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

Unified 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: pre-review 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/signin/cross_device_promo.h
diff --git a/chrome/browser/signin/cross_device_promo.h b/chrome/browser/signin/cross_device_promo.h
new file mode 100644
index 0000000000000000000000000000000000000000..4f53eed5816a4d08350fb74a3615f8e05c5330a2
--- /dev/null
+++ b/chrome/browser/signin/cross_device_promo.h
@@ -0,0 +1,128 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_SIGNIN_CROSS_DEVICE_PROMO_H_
+#define CHROME_BROWSER_SIGNIN_CROSS_DEVICE_PROMO_H_
+
+#include "base/observer_list.h"
+#include "base/timer/timer.h"
+#include "components/keyed_service/core/keyed_service.h"
+#include "components/signin/core/browser/device_activity_fetcher.h"
+#include "components/signin/core/browser/gaia_cookie_manager_service.h"
+
+class PrefService;
+class SigninClient;
+class SigninManager;
+
+class CrossDevicePromo : public KeyedService,
+ public GaiaCookieManagerService::Observer,
+ public DeviceActivityFetcher::Observer {
+ public:
+ class Observer {
+ public:
+ // Called if the state changes.
+ virtual void OnPromoActivationChanged(bool active) = 0;
+ };
+
+ explicit CrossDevicePromo(SigninManager* signin_manager,
+ GaiaCookieManagerService* cookie_manager_service,
+ SigninClient* signin_client,
+ PrefService* pref_service);
+ ~CrossDevicePromo() override;
+ void Shutdown() override;
+
+ void AddObserver(CrossDevicePromo::Observer* observer);
+ void RemoveObserver(CrossDevicePromo::Observer* observer);
+
+ // Overriden from GaiaCookieManagerService::Observer
+ void OnGaiaAccountsInCookieUpdated(
+ const std::vector<std::pair<std::string, bool> >& accounts,
+ const GoogleServiceAuthError& error) override;
+
+ // Overriden from DeviceActivityFetcher::Observer
+ void OnFetchDeviceActivitySuccess(
+ const std::vector<DeviceActivityFetcher::DeviceActivity>& devices)
+ override;
+ void OnFetchDeviceActivityFailure() override;
+
+ // Profile should be shown the promo.
+ bool IsPromoActive();
+
+ // Perform checks if the promo should be displayed to this profile.
+ bool CheckPromoEligibility();
+
+ // User elects to opt out of this promo.
+ void OptOut();
+
+ // Called whenever the Last Active Time changes. This is used to determine
+ // when a new browsing session occurs.
+ void UpdateLastActiveTime(const base::Time& previous_last_active);
+
+ private:
+ // Load configuration parameters from the Variations Seed.
+ void Init();
+
+ // Set whether the promo is active or inactive.
+ void MarkPromoActive();
+ void MarkPromoInactive();
+
+ // Perform checks if the promo should be displayed to this profile. This will
+ // not write any prefs or initiate any checks that are otherwise called in
+ // CheckPromoEligibility. Records no metrics. Used for DCHECKs.
+ bool VerifyPromoEligibleReadOnly();
+
+ // Track that there is exactly one account in the cookie jar for a period
+ // of time in order to activate the promo.
+ void RegisterForCookieChanges();
+ void UnregisterForCookieChanges();
+
+ // Begin authenticating and then fetching the devices with the same account.
+ void GetDevicesActivityForAccountInCookie();
+
+ SigninManager* signin_manager_;
+ GaiaCookieManagerService* cookie_manager_service_;
+ PrefService* prefs_;
+ SigninClient* signin_client_;
+
+ scoped_ptr<DeviceActivityFetcher> device_activity_fetcher_;
+ ObserverList<CrossDevicePromo::Observer> observer_list_;
+
+ // Maximum time since activity seen on another device that activity is
+ // considered within a context switch.
+ base::TimeDelta context_switch_duration_;
+
+ // Max time until the next Device Activity check. For the first test, this
+ // will be a uniformly random time between now and the max delay specified
+ // from Variations; otherwise we use the max delay as read from variations.
+ base::TimeDelta delay_until_next_list_devices_;
+
+ // Minimum time a single account must be in the cookie jar to consider the
+ // machine as used by only one person.
+ base::TimeDelta single_account_in_profile_;
+
+ // Time between noted browsing activity to determine when a new Browsing
+ // Session has started.
+ base::TimeDelta inactivity_between_browsing_sessions_;
+
+ // Throttles some portion of RPCs so they never get executed. 100 = throttled.
+ uint64 rpc_throttle_;
+
+ // Metric to help us track how long a browsing session is. Useful for
+ // configurigng the promo.
+ base::Time start_last_browsing_session_;
+
+ // Has the service been initialized. If false, the promo is inactive.
+ bool initialized_;
+
+ // Some parts of the flow we want to ignore towards our metrics so we don't
+ // double count.
+ bool track_metrics_;
+
+ // Used to delay the check of Device Activity.
+ base::OneShotTimer<CrossDevicePromo> device_activity_timer_;
+
+ DISALLOW_COPY_AND_ASSIGN(CrossDevicePromo);
+};
+
+#endif // CHROME_BROWSER_SIGNIN_CROSS_DEVICE_PROMO_H_

Powered by Google App Engine
This is Rietveld 408576698