Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(361)

Side by Side Diff: chrome/browser/signin/cross_device_promo.h

Issue 1087933002: Cross Device Promo - Main Eligibility Flow (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: git cl format Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 those who sign into Chrome on other devices, who are not signed in
21 // locally 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,
Alexei Svitkine (slow) 2015/05/19 17:10:37 Document ownership of params.
Mike Lerman 2015/05/19 18:17:34 Done
33 GaiaCookieManagerService* cookie_manager_service,
34 SigninClient* signin_client,
35 PrefService* pref_service);
36 ~CrossDevicePromo() override;
37 void Shutdown() override;
Alexei Svitkine (slow) 2015/05/19 17:10:37 Nit: Add a comment mentioning what this is overrid
Mike Lerman 2015/05/19 18:17:34 Ah, thanks. done.
38
39 void AddObserver(CrossDevicePromo::Observer* observer);
40 void RemoveObserver(CrossDevicePromo::Observer* observer);
41
42 // Overriden from GaiaCookieManagerService::Observer
Alexei Svitkine (slow) 2015/05/19 17:10:37 Nit: I think preferred style for these comments is
Mike Lerman 2015/05/19 18:17:34 Almost - but not quite, for two reasons. 1) It's a
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() { return CheckPromoEligibility(); }
65
66 private:
67 // Load configuration parameters from the Variations Seed.
68 void Init();
69
70 // Set whether the promo is active or inactive.
71 void MarkPromoActive();
72 void MarkPromoInactive();
73
74 // Perform checks if the promo should be displayed to this profile.
75 bool CheckPromoEligibility();
76
77 // Perform checks if the promo should be displayed to this profile. This will
78 // not write any prefs or initiate any checks that are otherwise called in
79 // CheckPromoEligibility. Records no metrics. Used for DCHECKs.
80 bool VerifyPromoEligibleReadOnly();
81
82 // Track that there is exactly one account in the cookie jar for a period
83 // of time in order to activate the promo.
84 void RegisterForCookieChanges();
85 void UnregisterForCookieChanges();
86
87 // Begin authenticating and then fetching the devices with the same account.
88 void GetDevicesActivityForAccountInCookie();
89
90 SigninManager* signin_manager_;
Alexei Svitkine (slow) 2015/05/19 17:10:37 Please document ownership of these.
Mike Lerman 2015/05/19 18:17:34 Done.
91 GaiaCookieManagerService* cookie_manager_service_;
92 PrefService* prefs_;
93 SigninClient* signin_client_;
94
95 scoped_ptr<DeviceActivityFetcher> device_activity_fetcher_;
96 ObserverList<CrossDevicePromo::Observer> observer_list_;
97
98 // Maximum time since activity seen on another device that activity is
99 // considered within a context switch.
100 base::TimeDelta context_switch_duration_;
101
102 // Max time until the next Device Activity check. For the first test, this
103 // will be a uniformly random time between now and the max delay specified
104 // from Variations; otherwise we use the max delay as read from variations.
105 base::TimeDelta delay_until_next_list_devices_;
106
107 // Minimum time a single account must be in the cookie jar to consider the
108 // machine as used by only one person.
109 base::TimeDelta single_account_duration_threshold_;
110
111 // Time between noted browsing activity to determine when a new Browsing
112 // Session has started.
113 base::TimeDelta inactivity_between_browsing_sessions_;
114
115 // Throttles some portion of RPCs so they never get executed, based on the
116 // variations configuration.
117 bool is_throttled_;
118
119 // Metric to help us track how long a browsing session is. Useful for
120 // configurigng the promo.
121 base::Time start_last_browsing_session_;
122
123 // Has the service been initialized. If false, the promo is inactive.
124 bool initialized_;
Alexei Svitkine (slow) 2015/05/19 17:10:37 Nit: Should probably be the first member.
Mike Lerman 2015/05/19 18:17:34 Done.
125
126 // Used to delay the check of Device Activity.
127 base::OneShotTimer<CrossDevicePromo> device_activity_timer_;
128
129 DISALLOW_COPY_AND_ASSIGN(CrossDevicePromo);
130 };
131
132 #endif // CHROME_BROWSER_SIGNIN_CROSS_DEVICE_PROMO_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698