summaryrefslogtreecommitdiffstats
path: root/ios/chrome/browser/history
diff options
context:
space:
mode:
authorsdefresne <sdefresne@chromium.org>2015-07-07 10:39:12 -0700
committerCommit bot <commit-bot@chromium.org>2015-07-07 17:39:49 +0000
commitcacc7b509a6ab9111b15ff5abc16bdd0de27d15b (patch)
tree889a3b4e6de39d9dd33457660b8ed46bd6f7b81f /ios/chrome/browser/history
parentab0fee448a6f539c122b2725588c44a4d91bea7f (diff)
downloadchromium_src-cacc7b509a6ab9111b15ff5abc16bdd0de27d15b.zip
chromium_src-cacc7b509a6ab9111b15ff5abc16bdd0de27d15b.tar.gz
chromium_src-cacc7b509a6ab9111b15ff5abc16bdd0de27d15b.tar.bz2
Implements WebHistoryServiceFactory on iOS
Cleanup iOS BrowserStateKeyedService factories to follow style guide and to fix typos in the factory description comments. BUG=429756 Review URL: https://codereview.chromium.org/1222013005 Cr-Commit-Position: refs/heads/master@{#337633}
Diffstat (limited to 'ios/chrome/browser/history')
-rw-r--r--ios/chrome/browser/history/history_service_factory.cc1
-rw-r--r--ios/chrome/browser/history/history_service_factory.h2
-rw-r--r--ios/chrome/browser/history/web_history_service_factory.cc74
-rw-r--r--ios/chrome/browser/history/web_history_service_factory.h46
4 files changed, 122 insertions, 1 deletions
diff --git a/ios/chrome/browser/history/history_service_factory.cc b/ios/chrome/browser/history/history_service_factory.cc
index 98e3dff..b919a1d 100644
--- a/ios/chrome/browser/history/history_service_factory.cc
+++ b/ios/chrome/browser/history/history_service_factory.cc
@@ -50,6 +50,7 @@ history::HistoryService* HistoryServiceFactory::GetForBrowserStateIfExists(
GetInstance()->GetServiceForBrowserState(browser_state, true));
}
+// static
HistoryServiceFactory* HistoryServiceFactory::GetInstance() {
return Singleton<HistoryServiceFactory>::get();
}
diff --git a/ios/chrome/browser/history/history_service_factory.h b/ios/chrome/browser/history/history_service_factory.h
index 6449603..c3b1a59 100644
--- a/ios/chrome/browser/history/history_service_factory.h
+++ b/ios/chrome/browser/history/history_service_factory.h
@@ -21,7 +21,7 @@ namespace ios {
class ChromeBrowserState;
-// Singleton that owns all HistoryService and associates them with
+// Singleton that owns all HistoryServices and associates them with
// ios::ChromeBrowserState.
class HistoryServiceFactory : public BrowserStateKeyedServiceFactory {
public:
diff --git a/ios/chrome/browser/history/web_history_service_factory.cc b/ios/chrome/browser/history/web_history_service_factory.cc
new file mode 100644
index 0000000..7efc452d
--- /dev/null
+++ b/ios/chrome/browser/history/web_history_service_factory.cc
@@ -0,0 +1,74 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ios/chrome/browser/history/web_history_service_factory.h"
+
+#include "base/memory/singleton.h"
+#include "base/prefs/pref_service.h"
+#include "components/history/core/browser/web_history_service.h"
+#include "components/keyed_service/ios/browser_state_dependency_manager.h"
+#include "components/signin/core/browser/profile_oauth2_token_service.h"
+#include "components/signin/core/browser/signin_manager.h"
+#include "components/sync_driver/sync_service.h"
+#include "ios/public/provider/chrome/browser/browser_state/chrome_browser_state.h"
+#include "ios/public/provider/chrome/browser/keyed_service_provider.h"
+#include "net/url_request/url_request_context_getter.h"
+
+namespace ios {
+namespace {
+
+// Returns true if the user is signed-in and full history sync is enabled,
+// false otherwise.
+bool IsHistorySyncEnabled(ios::ChromeBrowserState* browser_state) {
+ sync_driver::SyncService* sync_service =
+ GetKeyedServiceProvider()->GetSyncServiceForBrowserState(browser_state);
+ return sync_service && sync_service->IsSyncActive() &&
+ sync_service->GetActiveDataTypes().Has(
+ syncer::HISTORY_DELETE_DIRECTIVES);
+}
+
+} // namespace
+
+// static
+history::WebHistoryService* WebHistoryServiceFactory::GetForBrowserState(
+ ios::ChromeBrowserState* browser_state) {
+ // Ensure that the service is not instantiated or used if the user is not
+ // signed into sync, or if web history is not enabled.
+ if (!IsHistorySyncEnabled(browser_state))
+ return nullptr;
+
+ return static_cast<history::WebHistoryService*>(
+ GetInstance()->GetServiceForBrowserState(browser_state, true));
+}
+
+// static
+WebHistoryServiceFactory* WebHistoryServiceFactory::GetInstance() {
+ return Singleton<WebHistoryServiceFactory>::get();
+}
+
+WebHistoryServiceFactory::WebHistoryServiceFactory()
+ : BrowserStateKeyedServiceFactory(
+ "WebHistoryService",
+ BrowserStateDependencyManager::GetInstance()) {
+ ios::KeyedServiceProvider* provider = ios::GetKeyedServiceProvider();
+ DependsOn(provider->GetSyncServiceFactory());
+ DependsOn(provider->GetProfileOAuth2TokenServiceFactory());
+ DependsOn(provider->GetSigninManagerFactory());
+}
+
+WebHistoryServiceFactory::~WebHistoryServiceFactory() {
+}
+
+scoped_ptr<KeyedService> WebHistoryServiceFactory::BuildServiceInstanceFor(
+ web::BrowserState* context) const {
+ ios::ChromeBrowserState* browser_state =
+ ios::ChromeBrowserState::FromBrowserState(context);
+ ios::KeyedServiceProvider* provider = ios::GetKeyedServiceProvider();
+ return make_scoped_ptr(new history::WebHistoryService(
+ provider->GetProfileOAuth2TokenServiceForBrowserState(browser_state),
+ provider->GetSigninManagerForBrowserState(browser_state),
+ browser_state->GetRequestContext()));
+}
+
+} // namespace ios
diff --git a/ios/chrome/browser/history/web_history_service_factory.h b/ios/chrome/browser/history/web_history_service_factory.h
new file mode 100644
index 0000000..49f5f63
--- /dev/null
+++ b/ios/chrome/browser/history/web_history_service_factory.h
@@ -0,0 +1,46 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef IOS_CHROME_BROWSER_HISTORY_WEB_HISTORY_SERVICE_FACTORY_H_
+#define IOS_CHROME_BROWSER_HISTORY_WEB_HISTORY_SERVICE_FACTORY_H_
+
+#include "base/macros.h"
+#include "base/memory/scoped_ptr.h"
+#include "components/keyed_service/ios/browser_state_keyed_service_factory.h"
+
+template <typename T>
+struct DefaultSingletonTraits;
+
+namespace history {
+class WebHistoryService;
+}
+
+namespace ios {
+
+class ChromeBrowserState;
+
+// Singleton that owns all WebHistoryServices and associates them with
+// ios::ChromeBrowserState.
+class WebHistoryServiceFactory : public BrowserStateKeyedServiceFactory {
+ public:
+ static history::WebHistoryService* GetForBrowserState(
+ ios::ChromeBrowserState* browser_state);
+ static WebHistoryServiceFactory* GetInstance();
+
+ private:
+ friend struct DefaultSingletonTraits<WebHistoryServiceFactory>;
+
+ WebHistoryServiceFactory();
+ ~WebHistoryServiceFactory() override;
+
+ // BrowserStateKeyedServiceFactory implementation.
+ scoped_ptr<KeyedService> BuildServiceInstanceFor(
+ web::BrowserState* context) const override;
+
+ DISALLOW_COPY_AND_ASSIGN(WebHistoryServiceFactory);
+};
+
+} // namespace ios
+
+#endif // IOS_CHROME_BROWSER_HISTORY_WEB_HISTORY_SERVICE_FACTORY_H_