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.
5 #include "chrome/browser/signin/cross_device_promo_factory.h"
7 #include "base/prefs/pref_service.h"
8 #include "chrome/browser/prefs/pref_service_syncable.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/signin/chrome_signin_client_factory.h"
11 #include "chrome/browser/signin/cross_device_promo.h"
12 #include "chrome/browser/signin/gaia_cookie_manager_service_factory.h"
13 #include "chrome/browser/signin/signin_manager_factory.h"
14 #include "chrome/common/pref_names.h"
15 #include "components/keyed_service/content/browser_context_dependency_manager.h"
16 #include "components/pref_registry/pref_registry_syncable.h"
17 #include "components/signin/core/browser/signin_manager.h"
18 #include "google_apis/gaia/gaia_constants.h"
20 CrossDevicePromoFactory::CrossDevicePromoFactory()
21 : BrowserContextKeyedServiceFactory(
23 BrowserContextDependencyManager::GetInstance()) {
24 DependsOn(ChromeSigninClientFactory::GetInstance());
25 DependsOn(GaiaCookieManagerServiceFactory::GetInstance());
26 DependsOn(SigninManagerFactory::GetInstance());
29 CrossDevicePromoFactory::~CrossDevicePromoFactory() {
33 CrossDevicePromo
* CrossDevicePromoFactory::GetForProfile(Profile
* profile
) {
34 return static_cast<CrossDevicePromo
*>(
35 GetInstance()->GetServiceForBrowserContext(profile
, true));
39 CrossDevicePromoFactory
* CrossDevicePromoFactory::GetInstance() {
40 return Singleton
<CrossDevicePromoFactory
>::get();
43 void CrossDevicePromoFactory::RegisterProfilePrefs(
44 user_prefs::PrefRegistrySyncable
* user_prefs
) {
45 user_prefs
->RegisterBooleanPref(prefs::kCrossDevicePromoOptedOut
, false);
46 user_prefs
->RegisterBooleanPref(prefs::kCrossDevicePromoShouldBeShown
, false);
47 user_prefs
->RegisterInt64Pref(
48 prefs::kCrossDevicePromoObservedSingleAccountCookie
,
49 base::Time().ToInternalValue());
50 user_prefs
->RegisterInt64Pref(
51 prefs::kCrossDevicePromoNextFetchListDevicesTime
,
52 base::Time().ToInternalValue());
53 user_prefs
->RegisterIntegerPref(prefs::kCrossDevicePromoNumDevices
, 0);
54 user_prefs
->RegisterInt64Pref(prefs::kCrossDevicePromoLastDeviceActiveTime
,
55 base::Time().ToInternalValue());
58 KeyedService
* CrossDevicePromoFactory::BuildServiceInstanceFor(
59 content::BrowserContext
* context
) const {
60 Profile
* profile
= Profile::FromBrowserContext(context
);
61 CrossDevicePromo
* service
= new CrossDevicePromo(
62 SigninManagerFactory::GetForProfile(profile
),
63 GaiaCookieManagerServiceFactory::GetForProfile(profile
),
64 ChromeSigninClientFactory::GetForProfile(profile
), profile
->GetPrefs());