OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/history/web_history_service_factory.h" | 5 #include "chrome/browser/history/web_history_service_factory.h" |
6 | 6 |
7 #include "chrome/browser/content_settings/cookie_settings.h" | |
8 #include "chrome/browser/history/web_history_service.h" | |
9 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 7 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 8 #include "chrome/browser/signin/signin_manager_factory.h" |
10 #include "chrome/browser/sync/profile_sync_service.h" | 9 #include "chrome/browser/sync/profile_sync_service.h" |
11 #include "chrome/browser/sync/profile_sync_service_factory.h" | 10 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 11 #include "components/history/core/browser/web_history_service.h" |
12 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 12 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
| 13 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
| 14 #include "components/signin/core/browser/signin_manager.h" |
| 15 #include "net/url_request/url_request_context_getter.h" |
13 | 16 |
14 namespace { | 17 namespace { |
15 // Returns true if the user is signed in and full history sync is enabled, | 18 // Returns true if the user is signed in and full history sync is enabled, |
16 // and false otherwise. | 19 // and false otherwise. |
17 bool IsHistorySyncEnabled(Profile* profile) { | 20 bool IsHistorySyncEnabled(Profile* profile) { |
18 ProfileSyncService* sync = | 21 ProfileSyncService* sync = |
19 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile); | 22 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile); |
20 return sync && | 23 return sync && |
21 sync->SyncActive() && | 24 sync->SyncActive() && |
22 sync->GetActiveDataTypes().Has(syncer::HISTORY_DELETE_DIRECTIVES); | 25 sync->GetActiveDataTypes().Has(syncer::HISTORY_DELETE_DIRECTIVES); |
23 } | 26 } |
24 | 27 |
25 } // namespace | 28 } // namespace |
26 | 29 |
27 // static | 30 // static |
28 WebHistoryServiceFactory* WebHistoryServiceFactory::GetInstance() { | 31 WebHistoryServiceFactory* WebHistoryServiceFactory::GetInstance() { |
29 return Singleton<WebHistoryServiceFactory>::get(); | 32 return Singleton<WebHistoryServiceFactory>::get(); |
30 } | 33 } |
31 | 34 |
32 // static | 35 // static |
33 history::WebHistoryService* WebHistoryServiceFactory::GetForProfile( | 36 history::WebHistoryService* WebHistoryServiceFactory::GetForProfile( |
34 Profile* profile) { | 37 Profile* profile) { |
35 if (IsHistorySyncEnabled(profile)) { | 38 if (!IsHistorySyncEnabled(profile)) |
36 return static_cast<history::WebHistoryService*>( | 39 return nullptr; |
37 GetInstance()->GetServiceForBrowserContext(profile, true)); | 40 |
38 } | 41 return static_cast<history::WebHistoryService*>( |
39 return NULL; | 42 GetInstance()->GetServiceForBrowserContext(profile, true)); |
40 } | 43 } |
41 | 44 |
42 KeyedService* WebHistoryServiceFactory::BuildServiceInstanceFor( | 45 KeyedService* WebHistoryServiceFactory::BuildServiceInstanceFor( |
43 content::BrowserContext* context) const { | 46 content::BrowserContext* context) const { |
44 Profile* profile = static_cast<Profile*>(context); | 47 Profile* profile = static_cast<Profile*>(context); |
45 | |
46 // Ensure that the service is not instantiated or used if the user is not | 48 // Ensure that the service is not instantiated or used if the user is not |
47 // signed into sync, or if web history is not enabled. | 49 // signed into sync, or if web history is not enabled. |
48 return IsHistorySyncEnabled(profile) ? | 50 if (!IsHistorySyncEnabled(profile)) |
49 new history::WebHistoryService(profile) : NULL; | 51 return nullptr; |
| 52 |
| 53 return new history::WebHistoryService( |
| 54 ProfileOAuth2TokenServiceFactory::GetForProfile(profile), |
| 55 SigninManagerFactory::GetForProfile(profile), |
| 56 profile->GetRequestContext()); |
50 } | 57 } |
51 | 58 |
52 WebHistoryServiceFactory::WebHistoryServiceFactory() | 59 WebHistoryServiceFactory::WebHistoryServiceFactory() |
53 : BrowserContextKeyedServiceFactory( | 60 : BrowserContextKeyedServiceFactory( |
54 "WebHistoryServiceFactory", | 61 "WebHistoryServiceFactory", |
55 BrowserContextDependencyManager::GetInstance()) { | 62 BrowserContextDependencyManager::GetInstance()) { |
56 DependsOn(CookieSettings::Factory::GetInstance()); | |
57 DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance()); | 63 DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance()); |
| 64 DependsOn(SigninManagerFactory::GetInstance()); |
58 } | 65 } |
59 | 66 |
60 WebHistoryServiceFactory::~WebHistoryServiceFactory() { | 67 WebHistoryServiceFactory::~WebHistoryServiceFactory() { |
61 } | 68 } |
OLD | NEW |