Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 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_CROSS_DEVICE_PROMO_H_ | |
| 6 #define CHROME_BROWSER_SIGNIN_CROSS_DEVICE_PROMO_H_ | |
| 7 | |
| 8 #include "base/observer_list.h" | |
| 9 #include "base/timer/timer.h" | |
| 10 #include "components/keyed_service/core/keyed_service.h" | |
| 11 #include "components/signin/core/browser/device_activity_fetcher.h" | |
| 12 #include "components/signin/core/browser/gaia_cookie_manager_service.h" | |
| 13 | |
| 14 class PrefService; | |
| 15 class SigninClient; | |
| 16 class SigninManager; | |
| 17 | |
| 18 // This defines whether the cross device signin promo should be displayed for | |
| 19 // this profile, and owns whether the user has opted out of the promo. The promo | |
| 20 // targets who sign into Chrome on other devices, who are not signed in locally | |
|
Roger Tawa OOO till Jul 10th
2015/05/15 21:23:22
target who -> targets those who ?
Mike Lerman
2015/05/19 14:47:35
Done.
| |
| 21 // but use only one account in the content area. | |
| 22 class CrossDevicePromo : public KeyedService, | |
| 23 public GaiaCookieManagerService::Observer, | |
| 24 public DeviceActivityFetcher::Observer { | |
| 25 public: | |
| 26 class Observer { | |
| 27 public: | |
| 28 // Called if the state changes. | |
| 29 virtual void OnPromoActivationChanged(bool active) = 0; | |
| 30 }; | |
| 31 | |
| 32 explicit CrossDevicePromo(SigninManager* signin_manager, | |
| 33 GaiaCookieManagerService* cookie_manager_service, | |
| 34 SigninClient* signin_client, | |
| 35 PrefService* pref_service); | |
| 36 ~CrossDevicePromo() override; | |
| 37 void Shutdown() override; | |
| 38 | |
| 39 void AddObserver(CrossDevicePromo::Observer* observer); | |
| 40 void RemoveObserver(CrossDevicePromo::Observer* observer); | |
| 41 | |
| 42 // Overriden from GaiaCookieManagerService::Observer | |
| 43 void OnGaiaAccountsInCookieUpdated( | |
| 44 const std::vector<std::pair<std::string, bool> >& accounts, | |
| 45 const GoogleServiceAuthError& error) override; | |
| 46 | |
| 47 // Overriden from DeviceActivityFetcher::Observer | |
| 48 void OnFetchDeviceActivitySuccess( | |
| 49 const std::vector<DeviceActivityFetcher::DeviceActivity>& devices) | |
| 50 override; | |
| 51 void OnFetchDeviceActivityFailure() override; | |
| 52 | |
| 53 // Profile should be shown the promo. | |
| 54 bool IsPromoActive(); | |
| 55 | |
| 56 // User elects to opt out of this promo. | |
| 57 void OptOut(); | |
| 58 | |
| 59 // Called whenever the Last Active Time changes. This is used to determine | |
| 60 // when a new browsing session occurs. | |
| 61 void MaybeBrowsingSessionStarted(const base::Time& previous_last_active); | |
| 62 | |
| 63 // Call this only in tests, please! | |
| 64 bool CheckPromoEligibilityForTesting() { | |
| 65 return CheckPromoEligibility(); | |
| 66 } | |
| 67 | |
| 68 private: | |
| 69 // Load configuration parameters from the Variations Seed. | |
| 70 void Init(); | |
| 71 | |
| 72 // Set whether the promo is active or inactive. | |
| 73 void MarkPromoActive(); | |
| 74 void MarkPromoInactive(); | |
| 75 | |
| 76 // Perform checks if the promo should be displayed to this profile. | |
| 77 bool CheckPromoEligibility(); | |
| 78 | |
| 79 // Perform checks if the promo should be displayed to this profile. This will | |
| 80 // not write any prefs or initiate any checks that are otherwise called in | |
| 81 // CheckPromoEligibility. Records no metrics. Used for DCHECKs. | |
| 82 bool VerifyPromoEligibleReadOnly(); | |
| 83 | |
| 84 // Track that there is exactly one account in the cookie jar for a period | |
| 85 // of time in order to activate the promo. | |
| 86 void RegisterForCookieChanges(); | |
| 87 void UnregisterForCookieChanges(); | |
| 88 | |
| 89 // Begin authenticating and then fetching the devices with the same account. | |
| 90 void GetDevicesActivityForAccountInCookie(); | |
| 91 | |
| 92 SigninManager* signin_manager_; | |
| 93 GaiaCookieManagerService* cookie_manager_service_; | |
| 94 PrefService* prefs_; | |
| 95 SigninClient* signin_client_; | |
| 96 | |
| 97 scoped_ptr<DeviceActivityFetcher> device_activity_fetcher_; | |
| 98 ObserverList<CrossDevicePromo::Observer> observer_list_; | |
| 99 | |
| 100 // Maximum time since activity seen on another device that activity is | |
| 101 // considered within a context switch. | |
| 102 base::TimeDelta context_switch_duration_; | |
| 103 | |
| 104 // Max time until the next Device Activity check. For the first test, this | |
| 105 // will be a uniformly random time between now and the max delay specified | |
| 106 // from Variations; otherwise we use the max delay as read from variations. | |
| 107 base::TimeDelta delay_until_next_list_devices_; | |
| 108 | |
| 109 // Minimum time a single account must be in the cookie jar to consider the | |
| 110 // machine as used by only one person. | |
| 111 base::TimeDelta single_account_duration_threshold_; | |
| 112 | |
| 113 // Time between noted browsing activity to determine when a new Browsing | |
| 114 // Session has started. | |
| 115 base::TimeDelta inactivity_between_browsing_sessions_; | |
| 116 | |
| 117 // Throttles some portion of RPCs so they never get executed, based on the | |
| 118 // variations configuration. | |
| 119 bool is_throttled_; | |
| 120 | |
| 121 // Metric to help us track how long a browsing session is. Useful for | |
| 122 // configurigng the promo. | |
| 123 base::Time start_last_browsing_session_; | |
| 124 | |
| 125 // Has the service been initialized. If false, the promo is inactive. | |
| 126 bool initialized_; | |
| 127 | |
| 128 // Used to delay the check of Device Activity. | |
| 129 base::OneShotTimer<CrossDevicePromo> device_activity_timer_; | |
| 130 | |
| 131 DISALLOW_COPY_AND_ASSIGN(CrossDevicePromo); | |
| 132 }; | |
| 133 | |
| 134 #endif // CHROME_BROWSER_SIGNIN_CROSS_DEVICE_PROMO_H_ | |
| OLD | NEW |