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

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: Add a flow for when the first listDevices request is scheduled in the future. Tests around the sche… 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 namespace net {
19 class CanonicalCookie;
20 }
21
22 class CrossDevicePromo : public KeyedService,
23 public GaiaCookieManagerService::Observer,
24 public DeviceActivityFetcher::Observer {
25 public:
26 class Observer {
27 public:
28 // Only 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 // Profile should be shown the promo.
43 bool IsPromoActive();
44
45 // Perform checks if the promo should be displayed to this profile.
46 bool CheckPromoEligibility();
47
48 // User elects to opt out of this promo.
49 void OptOut();
50
51 // Called whenever the Last Active Time changes. This is used to determine
52 // when a new browsing session occurs.
53 void UpdateLastActiveTime(const base::Time& previous_last_active);
54
55 private:
56 // Load configuration parameters from the Finch experiment.
57 void Init();
58
59 // Set whether the promo is active or inactive.
60 void MarkPromoActive();
61 void MarkPromoInactive();
62
63 // Overriden from GaiaCookieManagerService::Observer
64 void OnGaiaAccountsInCookieUpdated(
65 const std::vector<std::pair<std::string, bool> >& accounts,
66 const GoogleServiceAuthError& error) override;
67
68 // Overriden from DeviceActivityFetcher::Observer
69 void OnFetchDeviceActivitySuccess(
70 const std::vector<DeviceActivityFetcher::DeviceActivity>& devices)
71 override;
72 void OnFetchDeviceActivityFailure() override;
73
74 // Track that there is exactly one account in the cookie jar for a period
75 // of time in order to activate the promo.
76 void RegisterForCookieChanges();
77 void UnregisterForCookieChanges();
78
79 // Begin authenticating and then fetching the devices with the same account.
80 void GetSyncDevicesForAccountInCookie();
81
82 SigninManager* signin_manager_;
83 GaiaCookieManagerService* cookie_manager_service_;
84 PrefService* prefs_;
85 SigninClient* signin_client_;
86
87 scoped_ptr<DeviceActivityFetcher> device_activity_fetcher_;
88 ObserverList<CrossDevicePromo::Observer> observer_list_;
89
90 // Maximum time since activity seen on another device that activity is
91 // considered within a context switch.
92 base::TimeDelta context_switch_duration_;
93
94 // max time until the next Sync Device check. For the first test, this will be
95 // a uniformly random time between now and the max delay specified from Finch;
96 // otherwise we use the max delay as read from Finch.
97 base::TimeDelta delay_until_next_list_devices_;
98
99 // Minimum time a single account must be in the cookie jar to
100 // consider the machine as used by only one person.
101 base::TimeDelta single_account_in_profile_;
102
103 // Time between noted browsing activity to determine when a new Browsing
104 // Session has started.
105 base::TimeDelta inactivity_between_browsing_sessions_;
106
107 // Metric to help us track how long a browsing session is. Useful for
108 // configurigng the promo.
109 base::Time start_last_browsing_session_;
110
111 // Has the service been initialized. If false, the promo is inactive.
112 bool initialized_;
113
114 // Some parts of the flow we want to ignore towards our metrics so we don't
115 // double count.
116 bool track_metrics_;
117
118 // Used to delay the check of Device Activity.
119 base::OneShotTimer<CrossDevicePromo> device_activity_timer_;
120
121 DISALLOW_COPY_AND_ASSIGN(CrossDevicePromo);
122 };
123
124 #endif // CHROME_BROWSER_SIGNIN_CROSS_DEVICE_PROMO_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698