OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "ios/chrome/browser/history/web_history_service_factory.h" |
| 6 |
| 7 #include "base/memory/singleton.h" |
| 8 #include "base/prefs/pref_service.h" |
| 9 #include "components/history/core/browser/web_history_service.h" |
| 10 #include "components/keyed_service/ios/browser_state_dependency_manager.h" |
| 11 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
| 12 #include "components/signin/core/browser/signin_manager.h" |
| 13 #include "components/sync_driver/sync_service.h" |
| 14 #include "ios/public/provider/chrome/browser/browser_state/chrome_browser_state.
h" |
| 15 #include "ios/public/provider/chrome/browser/keyed_service_provider.h" |
| 16 #include "net/url_request/url_request_context_getter.h" |
| 17 |
| 18 namespace ios { |
| 19 namespace { |
| 20 |
| 21 // Returns true if the user is signed-in and full history sync is enabled, |
| 22 // false otherwise. |
| 23 bool IsHistorySyncEnabled(ios::ChromeBrowserState* browser_state) { |
| 24 sync_driver::SyncService* sync_service = |
| 25 GetKeyedServiceProvider()->GetSyncServiceForBrowserState(browser_state); |
| 26 return sync_service && sync_service->IsSyncActive() && |
| 27 sync_service->GetActiveDataTypes().Has( |
| 28 syncer::HISTORY_DELETE_DIRECTIVES); |
| 29 } |
| 30 |
| 31 } // namespace |
| 32 |
| 33 // static |
| 34 history::WebHistoryService* WebHistoryServiceFactory::GetForBrowserState( |
| 35 ios::ChromeBrowserState* browser_state) { |
| 36 // Ensure that the service is not instantiated or used if the user is not |
| 37 // signed into sync, or if web history is not enabled. |
| 38 if (!IsHistorySyncEnabled(browser_state)) |
| 39 return nullptr; |
| 40 |
| 41 return static_cast<history::WebHistoryService*>( |
| 42 GetInstance()->GetServiceForBrowserState(browser_state, true)); |
| 43 } |
| 44 |
| 45 // static |
| 46 WebHistoryServiceFactory* WebHistoryServiceFactory::GetInstance() { |
| 47 return Singleton<WebHistoryServiceFactory>::get(); |
| 48 } |
| 49 |
| 50 WebHistoryServiceFactory::WebHistoryServiceFactory() |
| 51 : BrowserStateKeyedServiceFactory( |
| 52 "WebHistoryService", |
| 53 BrowserStateDependencyManager::GetInstance()) { |
| 54 ios::KeyedServiceProvider* provider = ios::GetKeyedServiceProvider(); |
| 55 DependsOn(provider->GetSyncServiceFactory()); |
| 56 DependsOn(provider->GetProfileOAuth2TokenServiceFactory()); |
| 57 DependsOn(provider->GetSigninManagerFactory()); |
| 58 } |
| 59 |
| 60 WebHistoryServiceFactory::~WebHistoryServiceFactory() { |
| 61 } |
| 62 |
| 63 scoped_ptr<KeyedService> WebHistoryServiceFactory::BuildServiceInstanceFor( |
| 64 web::BrowserState* context) const { |
| 65 ios::ChromeBrowserState* browser_state = |
| 66 ios::ChromeBrowserState::FromBrowserState(context); |
| 67 ios::KeyedServiceProvider* provider = ios::GetKeyedServiceProvider(); |
| 68 return make_scoped_ptr(new history::WebHistoryService( |
| 69 provider->GetProfileOAuth2TokenServiceForBrowserState(browser_state), |
| 70 provider->GetSigninManagerForBrowserState(browser_state), |
| 71 browser_state->GetRequestContext())); |
| 72 } |
| 73 |
| 74 } // namespace ios |
OLD | NEW |