summaryrefslogtreecommitdiffstats
path: root/ios
diff options
context:
space:
mode:
authorsdefresne <sdefresne@chromium.org>2015-06-17 09:03:52 -0700
committerCommit bot <commit-bot@chromium.org>2015-06-17 16:04:27 +0000
commitea32e77ba52ef0ea2b5147d83079226943795ffd (patch)
tree47c39c5e669bcf55dc84ba995b8220b2910109ee /ios
parente88424d952e5239d0b4467973415ab94de3ca23d (diff)
downloadchromium_src-ea32e77ba52ef0ea2b5147d83079226943795ffd.zip
chromium_src-ea32e77ba52ef0ea2b5147d83079226943795ffd.tar.gz
chromium_src-ea32e77ba52ef0ea2b5147d83079226943795ffd.tar.bz2
[iOS] KeyedServiceProvider improvements
Change KeyedServiceProvider into a pure abstract interface and implement the missing methods in TestKeyedServiceProvider. Create a new MissingServiceKeyedServiceFactory whose instance is returned by TestKeyedServiceProvider for services that are not implemented in //ios so that KeyedService factories dependencies can be resolved. This is done so that more KeyedService factories are instantiated during unit tests. Update browser_state_keyed_service_factories.mm with the list of all the KeyedService factories that are implemented in //ios. BUG=478763 Review URL: https://codereview.chromium.org/1186543003 Cr-Commit-Position: refs/heads/master@{#334843}
Diffstat (limited to 'ios')
-rw-r--r--ios/chrome/browser/browser_state/browser_state_keyed_service_factories.mm6
-rw-r--r--ios/public/provider/chrome/browser/keyed_service_provider.cc72
-rw-r--r--ios/public/provider/chrome/browser/keyed_service_provider.h30
-rw-r--r--ios/public/test/DEPS7
-rw-r--r--ios/public/test/test_keyed_service_provider.cc112
-rw-r--r--ios/public/test/test_keyed_service_provider.h20
6 files changed, 156 insertions, 91 deletions
diff --git a/ios/chrome/browser/browser_state/browser_state_keyed_service_factories.mm b/ios/chrome/browser/browser_state/browser_state_keyed_service_factories.mm
index 0e26898..41dca16 100644
--- a/ios/chrome/browser/browser_state/browser_state_keyed_service_factories.mm
+++ b/ios/chrome/browser/browser_state/browser_state_keyed_service_factories.mm
@@ -5,6 +5,8 @@
#include "ios/chrome/browser/browser_state/browser_state_keyed_service_factories.h"
#include "ios/chrome/browser/dom_distiller/dom_distiller_service_factory.h"
+#include "ios/chrome/browser/enhanced_bookmarks/bookmark_server_cluster_service_factory.h"
+#include "ios/chrome/browser/enhanced_bookmarks/enhanced_bookmark_model_factory.h"
#include "ios/chrome/browser/suggestions/suggestions_service_factory.h"
#include "ios/chrome/browser/translate/translate_accept_languages_factory.h"
#include "ios/public/provider/chrome/browser/keyed_service_provider.h"
@@ -19,9 +21,11 @@
// TODO(erg): This needs to be something else. I don't think putting every
// FooServiceFactory here will scale or is desirable long term.
void EnsureBrowserStateKeyedServiceFactoriesBuilt() {
- TranslateAcceptLanguagesFactory::GetInstance();
dom_distiller::DomDistillerServiceFactory::GetInstance();
+ enhanced_bookmarks::BookmarkServerClusterServiceFactory::GetInstance();
+ enhanced_bookmarks::EnhancedBookmarkModelFactory::GetInstance();
suggestions::SuggestionsServiceFactory::GetInstance();
+ TranslateAcceptLanguagesFactory::GetInstance();
if (ios::GetKeyedServiceProvider())
ios::GetKeyedServiceProvider()->AssertKeyedFactoriesBuilt();
diff --git a/ios/public/provider/chrome/browser/keyed_service_provider.cc b/ios/public/provider/chrome/browser/keyed_service_provider.cc
index 4ca9c17..5140a0d 100644
--- a/ios/public/provider/chrome/browser/keyed_service_provider.cc
+++ b/ios/public/provider/chrome/browser/keyed_service_provider.cc
@@ -28,76 +28,4 @@ KeyedServiceProvider::KeyedServiceProvider() {
KeyedServiceProvider::~KeyedServiceProvider() {
}
-void KeyedServiceProvider::AssertKeyedFactoriesBuilt() {
-}
-
-KeyedServiceBaseFactory* KeyedServiceProvider::GetBookmarkModelFactory() {
- return nullptr;
-}
-
-bookmarks::BookmarkModel* KeyedServiceProvider::GetBookmarkModelForBrowserState(
- ios::ChromeBrowserState* browser_state) {
- return nullptr;
-}
-
-KeyedServiceBaseFactory*
-KeyedServiceProvider::GetProfileOAuth2TokenServiceIOSFactory() {
- return nullptr;
-}
-
-ProfileOAuth2TokenServiceIOS*
-KeyedServiceProvider::GetProfileOAuth2TokenServiceIOSForBrowserState(
- ChromeBrowserState* browser_state) {
- return nullptr;
-}
-
-KeyedServiceBaseFactory* KeyedServiceProvider::GetSigninManagerFactory() {
- return nullptr;
-}
-
-SigninManager* KeyedServiceProvider::GetSigninManagerForBrowserState(
- ChromeBrowserState* browser_state) {
- return nullptr;
-}
-
-KeyedServiceBaseFactory* KeyedServiceProvider::GetAutofillWebDataFactory() {
- return nullptr;
-}
-
-scoped_refptr<autofill::AutofillWebDataService>
-KeyedServiceProvider::GetAutofillWebDataForBrowserState(
- ChromeBrowserState* browser_state,
- ServiceAccessType access_type) {
- return nullptr;
-}
-
-KeyedServiceBaseFactory* KeyedServiceProvider::GetPersonalDataManagerFactory() {
- return nullptr;
-}
-
-autofill::PersonalDataManager*
-KeyedServiceProvider::GetPersonalDataManagerForBrowserState(
- ChromeBrowserState* browser_state) {
- return nullptr;
-}
-
-KeyedServiceBaseFactory* KeyedServiceProvider::GetSyncServiceFactory() {
- return nullptr;
-}
-
-sync_driver::SyncService* KeyedServiceProvider::GetSyncServiceForBrowserState(
- ChromeBrowserState* browser_state) {
- return nullptr;
-}
-
-KeyedServiceBaseFactory* KeyedServiceProvider::GetHistoryServiceFactory() {
- return nullptr;
-}
-
-history::HistoryService* KeyedServiceProvider::GetHistoryServiceForBrowserState(
- ChromeBrowserState* browser_state,
- ServiceAccessType access_type) {
- return nullptr;
-}
-
} // namespace ios
diff --git a/ios/public/provider/chrome/browser/keyed_service_provider.h b/ios/public/provider/chrome/browser/keyed_service_provider.h
index 9296cf4..c5c7862 100644
--- a/ios/public/provider/chrome/browser/keyed_service_provider.h
+++ b/ios/public/provider/chrome/browser/keyed_service_provider.h
@@ -50,62 +50,62 @@ class KeyedServiceProvider {
// Ensures that all KeyedService factories are instantiated. Must be called
// before any BrowserState instance is created so that dependencies are
// correct.
- virtual void AssertKeyedFactoriesBuilt();
+ virtual void AssertKeyedFactoriesBuilt() = 0;
// Returns the bookmarks::BookmarkModel factory for dependencies.
- virtual KeyedServiceBaseFactory* GetBookmarkModelFactory();
+ virtual KeyedServiceBaseFactory* GetBookmarkModelFactory() = 0;
// Returns an instance of bookmarks::BookmarkModel tied to |browser_state|.
virtual bookmarks::BookmarkModel* GetBookmarkModelForBrowserState(
- ios::ChromeBrowserState* browser_state);
+ ChromeBrowserState* browser_state) = 0;
// Returns the ProfileOAuth2TokenServiceIOS factory for dependencies.
- virtual KeyedServiceBaseFactory* GetProfileOAuth2TokenServiceIOSFactory();
+ virtual KeyedServiceBaseFactory* GetProfileOAuth2TokenServiceIOSFactory() = 0;
// Returns an instance of ProfileOAuth2TokenServiceIOS tied to
// |browser_state|.
virtual ProfileOAuth2TokenServiceIOS*
GetProfileOAuth2TokenServiceIOSForBrowserState(
- ChromeBrowserState* browser_state);
+ ChromeBrowserState* browser_state) = 0;
// Returns the SigninManager factory for dependencies.
- virtual KeyedServiceBaseFactory* GetSigninManagerFactory();
+ virtual KeyedServiceBaseFactory* GetSigninManagerFactory() = 0;
// Returns an instance of SigninManager tied to |browser_state|.
virtual SigninManager* GetSigninManagerForBrowserState(
- ChromeBrowserState* browser_state);
+ ChromeBrowserState* browser_state) = 0;
// Returns the autofill::AutofillWebDataService factory for dependencies.
- virtual KeyedServiceBaseFactory* GetAutofillWebDataFactory();
+ virtual KeyedServiceBaseFactory* GetAutofillWebDataFactory() = 0;
// Returns an instance of autofill::AutofillWebDataService tied to
// |browser_state|.
virtual scoped_refptr<autofill::AutofillWebDataService>
GetAutofillWebDataForBrowserState(ChromeBrowserState* browser_state,
- ServiceAccessType access_type);
+ ServiceAccessType access_type) = 0;
// Returns the autofill::PersonalDataManager factory for dependencies.
- virtual KeyedServiceBaseFactory* GetPersonalDataManagerFactory();
+ virtual KeyedServiceBaseFactory* GetPersonalDataManagerFactory() = 0;
// Returns an instance of autofill::PersonalDataManager tied to
// |browser_state|.
virtual autofill::PersonalDataManager* GetPersonalDataManagerForBrowserState(
- ChromeBrowserState* browser_state);
+ ChromeBrowserState* browser_state) = 0;
// Returns the sync_driver::SyncService factory for dependencies.
- virtual KeyedServiceBaseFactory* GetSyncServiceFactory();
+ virtual KeyedServiceBaseFactory* GetSyncServiceFactory() = 0;
// Returns an instance of sync_driver::SyncService tied to |browser_state|.
virtual sync_driver::SyncService* GetSyncServiceForBrowserState(
- ChromeBrowserState* browser_state);
+ ChromeBrowserState* browser_state) = 0;
// Returns the history::HistoryService factory for dependencies.
- virtual KeyedServiceBaseFactory* GetHistoryServiceFactory();
+ virtual KeyedServiceBaseFactory* GetHistoryServiceFactory() = 0;
// Returns an instance of history::HistoryService tied to |browser_state|.
virtual history::HistoryService* GetHistoryServiceForBrowserState(
ChromeBrowserState* browser_state,
- ServiceAccessType access_type);
+ ServiceAccessType access_type) = 0;
private:
DISALLOW_COPY_AND_ASSIGN(KeyedServiceProvider);
diff --git a/ios/public/test/DEPS b/ios/public/test/DEPS
index 3672da2..3c6ee3d 100644
--- a/ios/public/test/DEPS
+++ b/ios/public/test/DEPS
@@ -1,5 +1,6 @@
include_rules = [
- '+components/keyed_service/core',
- '+components/keyed_service/ios',
- '+components/sync_driver',
+ "+components/autofill/core/browser",
+ "+components/keyed_service/core",
+ "+components/keyed_service/ios",
+ "+components/sync_driver",
]
diff --git a/ios/public/test/test_keyed_service_provider.cc b/ios/public/test/test_keyed_service_provider.cc
index b4e88a3..99b555f 100644
--- a/ios/public/test/test_keyed_service_provider.cc
+++ b/ios/public/test/test_keyed_service_provider.cc
@@ -4,11 +4,59 @@
#include "ios/public/test/test_keyed_service_provider.h"
+#include "base/logging.h"
+#include "base/macros.h"
+#include "base/memory/singleton.h"
+#include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
+#include "components/keyed_service/ios/browser_state_dependency_manager.h"
+#include "components/keyed_service/ios/browser_state_keyed_service_factory.h"
#include "components/sync_driver/fake_sync_service.h"
#include "ios/public/provider/chrome/browser/browser_state/chrome_browser_state.h"
#include "ios/public/test/fake_sync_service_factory.h"
namespace ios {
+namespace {
+
+class MissingServiceKeyedServiceFactory
+ : public BrowserStateKeyedServiceFactory {
+ public:
+ static MissingServiceKeyedServiceFactory* GetInstance();
+
+ private:
+ friend struct DefaultSingletonTraits<MissingServiceKeyedServiceFactory>;
+
+ MissingServiceKeyedServiceFactory();
+ ~MissingServiceKeyedServiceFactory() override;
+
+ // BrowserStateKeyedServiceFactory implementation.
+ KeyedService* BuildServiceInstanceFor(
+ web::BrowserState* context) const override;
+
+ DISALLOW_COPY_AND_ASSIGN(MissingServiceKeyedServiceFactory);
+};
+
+// static
+MissingServiceKeyedServiceFactory*
+MissingServiceKeyedServiceFactory::GetInstance() {
+ return Singleton<MissingServiceKeyedServiceFactory>::get();
+}
+
+MissingServiceKeyedServiceFactory::MissingServiceKeyedServiceFactory()
+ : BrowserStateKeyedServiceFactory(
+ "MissingService",
+ BrowserStateDependencyManager::GetInstance()) {
+}
+
+MissingServiceKeyedServiceFactory::~MissingServiceKeyedServiceFactory() {
+}
+
+KeyedService* MissingServiceKeyedServiceFactory::BuildServiceInstanceFor(
+ web::BrowserState* context) const {
+ NOTREACHED();
+ return nullptr;
+}
+
+} // namespace
TestKeyedServiceProvider::TestKeyedServiceProvider() {
}
@@ -18,6 +66,59 @@ TestKeyedServiceProvider::~TestKeyedServiceProvider() {
void TestKeyedServiceProvider::AssertKeyedFactoriesBuilt() {
FakeSyncServiceFactory::GetInstance();
+ MissingServiceKeyedServiceFactory::GetInstance();
+}
+
+KeyedServiceBaseFactory* TestKeyedServiceProvider::GetBookmarkModelFactory() {
+ return MissingServiceKeyedServiceFactory::GetInstance();
+}
+
+bookmarks::BookmarkModel*
+TestKeyedServiceProvider::GetBookmarkModelForBrowserState(
+ ChromeBrowserState* browser_state) {
+ return nullptr;
+}
+
+KeyedServiceBaseFactory*
+TestKeyedServiceProvider::GetProfileOAuth2TokenServiceIOSFactory() {
+ return MissingServiceKeyedServiceFactory::GetInstance();
+}
+
+ProfileOAuth2TokenServiceIOS*
+TestKeyedServiceProvider::GetProfileOAuth2TokenServiceIOSForBrowserState(
+ ChromeBrowserState* browser_state) {
+ return nullptr;
+}
+
+KeyedServiceBaseFactory* TestKeyedServiceProvider::GetSigninManagerFactory() {
+ return MissingServiceKeyedServiceFactory::GetInstance();
+}
+
+SigninManager* TestKeyedServiceProvider::GetSigninManagerForBrowserState(
+ ChromeBrowserState* browser_state) {
+ return nullptr;
+}
+
+KeyedServiceBaseFactory* TestKeyedServiceProvider::GetAutofillWebDataFactory() {
+ return MissingServiceKeyedServiceFactory::GetInstance();
+}
+
+scoped_refptr<autofill::AutofillWebDataService>
+TestKeyedServiceProvider::GetAutofillWebDataForBrowserState(
+ ChromeBrowserState* browser_state,
+ ServiceAccessType access_type) {
+ return scoped_refptr<autofill::AutofillWebDataService>(nullptr);
+}
+
+KeyedServiceBaseFactory*
+TestKeyedServiceProvider::GetPersonalDataManagerFactory() {
+ return MissingServiceKeyedServiceFactory::GetInstance();
+}
+
+autofill::PersonalDataManager*
+TestKeyedServiceProvider::GetPersonalDataManagerForBrowserState(
+ ChromeBrowserState* browser_state) {
+ return nullptr;
}
KeyedServiceBaseFactory* TestKeyedServiceProvider::GetSyncServiceFactory() {
@@ -30,4 +131,15 @@ TestKeyedServiceProvider::GetSyncServiceForBrowserState(
return FakeSyncServiceFactory::GetForBrowserState(browser_state);
}
+KeyedServiceBaseFactory* TestKeyedServiceProvider::GetHistoryServiceFactory() {
+ return MissingServiceKeyedServiceFactory::GetInstance();
+}
+
+history::HistoryService*
+TestKeyedServiceProvider::GetHistoryServiceForBrowserState(
+ ChromeBrowserState* browser_state,
+ ServiceAccessType access_type) {
+ return nullptr;
+}
+
} // namespace ios
diff --git a/ios/public/test/test_keyed_service_provider.h b/ios/public/test/test_keyed_service_provider.h
index 3d33dbc..a3af1ab 100644
--- a/ios/public/test/test_keyed_service_provider.h
+++ b/ios/public/test/test_keyed_service_provider.h
@@ -17,9 +17,29 @@ class TestKeyedServiceProvider : public KeyedServiceProvider {
// KeyedServiceProvider implementation:
void AssertKeyedFactoriesBuilt() override;
+ KeyedServiceBaseFactory* GetBookmarkModelFactory() override;
+ bookmarks::BookmarkModel* GetBookmarkModelForBrowserState(
+ ChromeBrowserState* browser_state) override;
+ KeyedServiceBaseFactory* GetProfileOAuth2TokenServiceIOSFactory() override;
+ ProfileOAuth2TokenServiceIOS* GetProfileOAuth2TokenServiceIOSForBrowserState(
+ ChromeBrowserState* browser_state) override;
+ KeyedServiceBaseFactory* GetSigninManagerFactory() override;
+ SigninManager* GetSigninManagerForBrowserState(
+ ChromeBrowserState* browser_state) override;
+ KeyedServiceBaseFactory* GetAutofillWebDataFactory() override;
+ scoped_refptr<autofill::AutofillWebDataService>
+ GetAutofillWebDataForBrowserState(ChromeBrowserState* browser_state,
+ ServiceAccessType access_type) override;
+ KeyedServiceBaseFactory* GetPersonalDataManagerFactory() override;
+ autofill::PersonalDataManager* GetPersonalDataManagerForBrowserState(
+ ChromeBrowserState* browser_state) override;
KeyedServiceBaseFactory* GetSyncServiceFactory() override;
sync_driver::SyncService* GetSyncServiceForBrowserState(
ChromeBrowserState* browser_state) override;
+ KeyedServiceBaseFactory* GetHistoryServiceFactory() override;
+ history::HistoryService* GetHistoryServiceForBrowserState(
+ ChromeBrowserState* browser_state,
+ ServiceAccessType access_type) override;
private:
DISALLOW_COPY_AND_ASSIGN(TestKeyedServiceProvider);