1 // Copyright (c) 2012 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/google/google_url_tracker_factory.h"
7 #include "base/prefs/pref_service.h"
8 #include "chrome/browser/google/chrome_google_url_tracker_client.h"
9 #include "chrome/browser/profiles/incognito_helpers.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "components/google/core/browser/google_pref_names.h"
12 #include "components/google/core/browser/google_url_tracker.h"
13 #include "components/keyed_service/content/browser_context_dependency_manager.h"
14 #include "components/pref_registry/pref_registry_syncable.h"
18 const char kLastPromptedGoogleURL
[] = "browser.last_prompted_google_url";
24 GoogleURLTracker
* GoogleURLTrackerFactory::GetForProfile(Profile
* profile
) {
25 return static_cast<GoogleURLTracker
*>(
26 GetInstance()->GetServiceForBrowserContext(profile
, true));
30 GoogleURLTrackerFactory
* GoogleURLTrackerFactory::GetInstance() {
31 return Singleton
<GoogleURLTrackerFactory
>::get();
34 GoogleURLTrackerFactory::GoogleURLTrackerFactory()
35 : BrowserContextKeyedServiceFactory(
37 BrowserContextDependencyManager::GetInstance()) {
40 GoogleURLTrackerFactory::~GoogleURLTrackerFactory() {
43 KeyedService
* GoogleURLTrackerFactory::BuildServiceInstanceFor(
44 content::BrowserContext
* context
) const {
45 // Delete this now-unused pref.
46 // At some point in the future, this code can be removed entirely.
47 static_cast<Profile
*>(context
)->GetOriginalProfile()->GetPrefs()->ClearPref(
48 kLastPromptedGoogleURL
);
50 scoped_ptr
<GoogleURLTrackerClient
> client(
51 new ChromeGoogleURLTrackerClient(Profile::FromBrowserContext(context
)));
52 return new GoogleURLTracker(client
.Pass(), GoogleURLTracker::NORMAL_MODE
);
55 void GoogleURLTrackerFactory::RegisterProfilePrefs(
56 user_prefs::PrefRegistrySyncable
* user_prefs
) {
57 user_prefs
->RegisterStringPref(
58 prefs::kLastKnownGoogleURL
,
59 GoogleURLTracker::kDefaultGoogleHomepage
,
60 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
61 user_prefs
->RegisterStringPref(
62 kLastPromptedGoogleURL
,
64 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
67 content::BrowserContext
* GoogleURLTrackerFactory::GetBrowserContextToUse(
68 content::BrowserContext
* context
) const {
69 return chrome::GetBrowserContextRedirectedInIncognito(context
);
72 bool GoogleURLTrackerFactory::ServiceIsCreatedWithBrowserContext() const {
76 bool GoogleURLTrackerFactory::ServiceIsNULLWhileTesting() const {