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

Side by Side Diff: chrome/browser/history/web_history_service_factory.cc

Issue 889553003: Revert of Componentize WebHistoryService (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Mon Feb 2 15:10:48 PST 2015 Created 5 years, 10 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
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"
7 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 9 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
8 #include "chrome/browser/signin/signin_manager_factory.h"
9 #include "chrome/browser/sync/profile_sync_service.h" 10 #include "chrome/browser/sync/profile_sync_service.h"
10 #include "chrome/browser/sync/profile_sync_service_factory.h" 11 #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"
16 13
17 namespace { 14 namespace {
18 // Returns true if the user is signed in and full history sync is enabled, 15 // Returns true if the user is signed in and full history sync is enabled,
19 // and false otherwise. 16 // and false otherwise.
20 bool IsHistorySyncEnabled(Profile* profile) { 17 bool IsHistorySyncEnabled(Profile* profile) {
21 ProfileSyncService* sync = 18 ProfileSyncService* sync =
22 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile); 19 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile);
23 return sync && 20 return sync &&
24 sync->SyncActive() && 21 sync->SyncActive() &&
25 sync->GetActiveDataTypes().Has(syncer::HISTORY_DELETE_DIRECTIVES); 22 sync->GetActiveDataTypes().Has(syncer::HISTORY_DELETE_DIRECTIVES);
26 } 23 }
27 24
28 } // namespace 25 } // namespace
29 26
30 // static 27 // static
31 WebHistoryServiceFactory* WebHistoryServiceFactory::GetInstance() { 28 WebHistoryServiceFactory* WebHistoryServiceFactory::GetInstance() {
32 return Singleton<WebHistoryServiceFactory>::get(); 29 return Singleton<WebHistoryServiceFactory>::get();
33 } 30 }
34 31
35 // static 32 // static
36 history::WebHistoryService* WebHistoryServiceFactory::GetForProfile( 33 history::WebHistoryService* WebHistoryServiceFactory::GetForProfile(
37 Profile* profile) { 34 Profile* profile) {
38 if (!IsHistorySyncEnabled(profile)) 35 if (IsHistorySyncEnabled(profile)) {
39 return nullptr; 36 return static_cast<history::WebHistoryService*>(
40 37 GetInstance()->GetServiceForBrowserContext(profile, true));
41 return static_cast<history::WebHistoryService*>( 38 }
42 GetInstance()->GetServiceForBrowserContext(profile, true)); 39 return NULL;
43 } 40 }
44 41
45 KeyedService* WebHistoryServiceFactory::BuildServiceInstanceFor( 42 KeyedService* WebHistoryServiceFactory::BuildServiceInstanceFor(
46 content::BrowserContext* context) const { 43 content::BrowserContext* context) const {
47 Profile* profile = static_cast<Profile*>(context); 44 Profile* profile = static_cast<Profile*>(context);
45
48 // Ensure that the service is not instantiated or used if the user is not 46 // Ensure that the service is not instantiated or used if the user is not
49 // signed into sync, or if web history is not enabled. 47 // signed into sync, or if web history is not enabled.
50 if (!IsHistorySyncEnabled(profile)) 48 return IsHistorySyncEnabled(profile) ?
51 return nullptr; 49 new history::WebHistoryService(profile) : NULL;
52
53 return new history::WebHistoryService(
54 ProfileOAuth2TokenServiceFactory::GetForProfile(profile),
55 SigninManagerFactory::GetForProfile(profile),
56 profile->GetRequestContext());
57 } 50 }
58 51
59 WebHistoryServiceFactory::WebHistoryServiceFactory() 52 WebHistoryServiceFactory::WebHistoryServiceFactory()
60 : BrowserContextKeyedServiceFactory( 53 : BrowserContextKeyedServiceFactory(
61 "WebHistoryServiceFactory", 54 "WebHistoryServiceFactory",
62 BrowserContextDependencyManager::GetInstance()) { 55 BrowserContextDependencyManager::GetInstance()) {
56 DependsOn(CookieSettings::Factory::GetInstance());
63 DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance()); 57 DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance());
64 DependsOn(SigninManagerFactory::GetInstance());
65 } 58 }
66 59
67 WebHistoryServiceFactory::~WebHistoryServiceFactory() { 60 WebHistoryServiceFactory::~WebHistoryServiceFactory() {
68 } 61 }
OLDNEW
« no previous file with comments | « chrome/browser/history/web_history_service.cc ('k') | chrome/browser/history/web_history_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698