Home | History | Annotate | Download | only in signin
      1 // Copyright 2013 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef CHROME_BROWSER_SIGNIN_SIGNIN_PROMO_H_
      6 #define CHROME_BROWSER_SIGNIN_SIGNIN_PROMO_H_
      7 
      8 #include <string>
      9 
     10 #include "base/basictypes.h"
     11 
     12 class GURL;
     13 class Profile;
     14 
     15 namespace user_prefs {
     16 class PrefRegistrySyncable;
     17 }
     18 
     19 // Utility functions for sign in promos.
     20 namespace signin {
     21 
     22 const char kSignInPromoQueryKeyAutoClose[] = "auto_close";
     23 const char kSignInPromoQueryKeyContinue[] = "continue";
     24 const char kSignInPromoQueryKeySource[] = "source";
     25 const char kSignInPromoQueryKeyConstrained[] = "constrained";
     26 const char kSignInPromoQueryKeyShowAccountManagement[] =
     27     "showAccountManagement";
     28 
     29 enum Source {
     30   SOURCE_START_PAGE = 0, // This must be first.
     31   SOURCE_NTP_LINK,
     32   SOURCE_MENU,
     33   SOURCE_SETTINGS,
     34   SOURCE_EXTENSION_INSTALL_BUBBLE,
     35   SOURCE_APP_LAUNCHER,
     36   SOURCE_APPS_PAGE_LINK,
     37   SOURCE_BOOKMARK_BUBBLE,
     38   SOURCE_AVATAR_BUBBLE_SIGN_IN,
     39   SOURCE_AVATAR_BUBBLE_ADD_ACCOUNT,
     40   SOURCE_DEVICES_PAGE,
     41   SOURCE_REAUTH,
     42   SOURCE_UNKNOWN, // This must be last.
     43 };
     44 
     45 // Enum values used for Android signin promo actions.
     46 enum AndroidSigninPromoAction {
     47   // The promo was enabled.
     48   HISTOGRAM_ANDROID_SIGNIN_PROMO_ENABLED = 0,
     49 
     50   // The promo was shown.
     51   HISTOGRAM_ANDROID_SIGNIN_PROMO_SHOWN,
     52 
     53   // The promo was declined.
     54   HISTOGRAM_ANDROID_SIGNIN_PROMO_DECLINED,
     55 
     56   // The promo was accepted.
     57   HISTOGRAM_ANDROID_SIGNIN_PROMO_ACCEPTED,
     58 
     59   // The promo was accepted and user clicked the settings link.
     60   HISTOGRAM_ANDROID_SIGNIN_PROMO_ACCEPTED_WITH_ADVANCED,
     61 
     62   HISTOGRAM_ANDROID_SIGNIN_PROMO_MAX,
     63 };
     64 
     65 // Returns true if the sign in promo should be visible.
     66 // |profile| is the profile of the tab the promo would be shown on.
     67 bool ShouldShowPromo(Profile* profile);
     68 
     69 // Returns true if we should show the sign in promo at startup.
     70 bool ShouldShowPromoAtStartup(Profile* profile, bool is_new_profile);
     71 
     72 // Called when the sign in promo has been shown so that we can keep track
     73 // of the number of times we've displayed it.
     74 void DidShowPromoAtStartup(Profile* profile);
     75 
     76 // Registers the fact that the user has skipped the sign in promo.
     77 void SetUserSkippedPromo(Profile* profile);
     78 
     79 // Gets the sign in landing page URL.
     80 GURL GetLandingURL(const char* option, int value);
     81 
     82 // Returns the sign in promo URL wth the given arguments in the query.
     83 // |source| identifies from where the sign in promo is being called, and is
     84 // used to record sync promo UMA stats in the context of the source.
     85 // |auto_close| whether to close the sign in promo automatically when done.
     86 // |is_constrained} whether to load the URL in a constrained window, false
     87 // by default.
     88 GURL GetPromoURL(Source source, bool auto_close);
     89 GURL GetPromoURL(Source source, bool auto_close, bool is_constrained);
     90 
     91 // Returns a sign in promo URL specifically for reauthenticating |account_id|.
     92 GURL GetReauthURL(Profile* profile, const std::string& account_id);
     93 
     94 // Gets the next page URL from the query portion of the sign in promo URL.
     95 GURL GetNextPageURLForPromoURL(const GURL& url);
     96 
     97 // Gets the source from the query portion of the sign in promo URL.
     98 // The source identifies from where the sign in promo was opened.
     99 Source GetSourceForPromoURL(const GURL& url);
    100 
    101 // Returns true if the auto_close parameter in the given URL is set to true.
    102 bool IsAutoCloseEnabledInURL(const GURL& url);
    103 
    104 // Returns true if the showAccountManagement parameter in the given url is set
    105 // to true.
    106 bool ShouldShowAccountManagement(const GURL& url);
    107 
    108 // Returns true if the given URL is the standard continue URL used with the
    109 // sync promo when the web-based flow is enabled.  The query parameters
    110 // of the URL are ignored for this comparison.
    111 bool IsContinueUrlForWebBasedSigninFlow(const GURL& url);
    112 
    113 // Forces UseWebBasedSigninFlow() to return true when set; used in tests only.
    114 void ForceWebBasedSigninFlowForTesting(bool force);
    115 
    116 // Registers the preferences the Sign In Promo needs.
    117 void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
    118 
    119 }  // namespace signin
    120 
    121 #endif  // CHROME_BROWSER_SIGNIN_SIGNIN_PROMO_H_
    122