summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorerg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-25 00:49:16 +0000
committererg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-25 00:49:16 +0000
commit49b3c58578b73c0af19c180e9f3658534a9a1688 (patch)
tree1af60fae1a280ac54904e52cb6df12e8488a7e34
parent6e29d6f3d7f6fca666ec11626933de272dc299e8 (diff)
downloadchromium_src-49b3c58578b73c0af19c180e9f3658534a9a1688.zip
chromium_src-49b3c58578b73c0af19c180e9f3658534a9a1688.tar.gz
chromium_src-49b3c58578b73c0af19c180e9f3658534a9a1688.tar.bz2
Profiles: Make PinnedTabService use the same interface as every other service.
In r88185, PinnedTabServiceFactory was modified to use a unique way of declaring a ProfileKeyedServiceFactory that didn't use GetInstance(). Change this so it uses the standard testing methods and initialization routines. BUG=77155 Review URL: https://chromiumcodereview.appspot.com/9160005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@118959 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/profiles/profile_dependency_manager.cc6
-rw-r--r--chrome/browser/profiles/profile_impl.cc3
-rw-r--r--chrome/browser/tabs/pinned_tab_service_factory.cc21
-rw-r--r--chrome/browser/tabs/pinned_tab_service_factory.h15
-rw-r--r--chrome/browser/tabs/pinned_tab_service_unittest.cc20
5 files changed, 43 insertions, 22 deletions
diff --git a/chrome/browser/profiles/profile_dependency_manager.cc b/chrome/browser/profiles/profile_dependency_manager.cc
index 0d53c7b..833e4d9 100644
--- a/chrome/browser/profiles/profile_dependency_manager.cc
+++ b/chrome/browser/profiles/profile_dependency_manager.cc
@@ -28,6 +28,7 @@
#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/browser/speech/speech_input_extension_manager.h"
#include "chrome/browser/sync/profile_sync_service_factory.h"
+#include "chrome/browser/tabs/pinned_tab_service_factory.h"
#include "chrome/browser/themes/theme_service_factory.h"
#include "chrome/browser/ui/global_error_service_factory.h"
#include "chrome/browser/ui/webui/ntp/ntp_resource_cache_factory.h"
@@ -169,10 +170,7 @@ void ProfileDependencyManager::AssertFactoriesBuilt() {
NetworkActionPredictorFactory::GetInstance();
NTPResourceCacheFactory::GetInstance();
PersonalDataManagerFactory::GetInstance();
- // TODO(erg): PinnedTabService deviates from the pattern of every other
- // PKSF. It's broken and is registering itself twice.
- //
- // PinnedTabServiceFactory::GetInstance();
+ PinnedTabServiceFactory::GetInstance();
PluginPrefsFactory::GetInstance();
protector::ProtectorServiceFactory::GetInstance();
prerender::PrerenderManagerFactory::GetInstance();
diff --git a/chrome/browser/profiles/profile_impl.cc b/chrome/browser/profiles/profile_impl.cc
index 6bf51f9..7e8d475 100644
--- a/chrome/browser/profiles/profile_impl.cc
+++ b/chrome/browser/profiles/profile_impl.cc
@@ -75,7 +75,6 @@
#include "chrome/browser/speech/chrome_speech_input_preferences.h"
#include "chrome/browser/spellchecker/spellcheck_profile.h"
#include "chrome/browser/sync/profile_sync_service_factory.h"
-#include "chrome/browser/tabs/pinned_tab_service_factory.h"
#include "chrome/browser/transport_security_persister.h"
#include "chrome/browser/ui/browser_init.h"
#include "chrome/browser/ui/browser_list.h"
@@ -345,8 +344,6 @@ void ProfileImpl::DoFinalInit() {
ssl_config_service_manager_.reset(
SSLConfigServiceManager::CreateDefaultManager(local_state));
- PinnedTabServiceFactory::InitForProfile(this);
-
// Initialize the BackgroundModeManager - this has to be done here before
// InitExtensions() is called because it relies on receiving notifications
// when extensions are loaded. BackgroundModeManager is not needed under
diff --git a/chrome/browser/tabs/pinned_tab_service_factory.cc b/chrome/browser/tabs/pinned_tab_service_factory.cc
index e8e8daa..0ef5fa8 100644
--- a/chrome/browser/tabs/pinned_tab_service_factory.cc
+++ b/chrome/browser/tabs/pinned_tab_service_factory.cc
@@ -8,14 +8,15 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_dependency_manager.h"
-namespace {
-base::LazyInstance<PinnedTabServiceFactory> g_pinned_tab_service_factory =
- LAZY_INSTANCE_INITIALIZER;
+// static
+PinnedTabService* PinnedTabServiceFactory::GetForProfile(
+ Profile* profile) {
+ return static_cast<PinnedTabService*>(
+ GetInstance()->GetServiceForProfile(profile, true));
}
-// static
-void PinnedTabServiceFactory::InitForProfile(Profile* profile) {
- g_pinned_tab_service_factory.Get().GetServiceForProfile(profile, true);
+PinnedTabServiceFactory* PinnedTabServiceFactory::GetInstance() {
+ return Singleton<PinnedTabServiceFactory>::get();
}
PinnedTabServiceFactory::PinnedTabServiceFactory()
@@ -30,3 +31,11 @@ ProfileKeyedService* PinnedTabServiceFactory::BuildServiceInstanceFor(
Profile* profile) const {
return new PinnedTabService(profile);
}
+
+bool PinnedTabServiceFactory::ServiceIsCreatedWithProfile() {
+ return true;
+}
+
+bool PinnedTabServiceFactory::ServiceIsNULLWhileTesting() {
+ return true;
+}
diff --git a/chrome/browser/tabs/pinned_tab_service_factory.h b/chrome/browser/tabs/pinned_tab_service_factory.h
index 7c5a4f1..dab2302 100644
--- a/chrome/browser/tabs/pinned_tab_service_factory.h
+++ b/chrome/browser/tabs/pinned_tab_service_factory.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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.
@@ -6,7 +6,7 @@
#define CHROME_BROWSER_TABS_PINNED_TAB_SERVICE_FACTORY_H_
#include "base/compiler_specific.h"
-#include "base/lazy_instance.h"
+#include "base/memory/singleton.h"
#include "chrome/browser/profiles/profile_keyed_service_factory.h"
class PinnedTabService;
@@ -17,12 +17,13 @@ class Profile;
// associated PinnedTabService.
class PinnedTabServiceFactory : public ProfileKeyedServiceFactory {
public:
- // Creates and initializes a PinnedTabService to track pinning changes for
- // |profile|.
- static void InitForProfile(Profile* profile);
+ // Returns the PinnedTabService that tracks pinning changes for |profile|.
+ static PinnedTabService* GetForProfile(Profile* profile);
+
+ static PinnedTabServiceFactory* GetInstance();
private:
- friend struct base::DefaultLazyInstanceTraits<PinnedTabServiceFactory>;
+ friend struct DefaultSingletonTraits<PinnedTabServiceFactory>;
PinnedTabServiceFactory();
virtual ~PinnedTabServiceFactory();
@@ -30,6 +31,8 @@ class PinnedTabServiceFactory : public ProfileKeyedServiceFactory {
// ProfileKeyedServiceFactory:
virtual ProfileKeyedService* BuildServiceInstanceFor(
Profile* profile) const OVERRIDE;
+ virtual bool ServiceIsCreatedWithProfile() OVERRIDE;
+ virtual bool ServiceIsNULLWhileTesting() OVERRIDE;
};
#endif // CHROME_BROWSER_TABS_PINNED_TAB_SERVICE_FACTORY_H_
diff --git a/chrome/browser/tabs/pinned_tab_service_unittest.cc b/chrome/browser/tabs/pinned_tab_service_unittest.cc
index f1fcc37..6f00338 100644
--- a/chrome/browser/tabs/pinned_tab_service_unittest.cc
+++ b/chrome/browser/tabs/pinned_tab_service_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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.
@@ -7,6 +7,7 @@
#include "chrome/browser/tabs/pinned_tab_codec.h"
#include "chrome/browser/tabs/pinned_tab_service.h"
+#include "chrome/browser/tabs/pinned_tab_service_factory.h"
#include "chrome/browser/tabs/pinned_tab_test_utils.h"
#include "chrome/browser/tabs/tab_strip_model.h"
#include "chrome/browser/ui/browser.h"
@@ -14,6 +15,18 @@
#include "chrome/test/base/testing_profile.h"
#include "testing/gtest/include/gtest/gtest.h"
+namespace {
+
+ProfileKeyedService* BuildPinnedTabService(Profile* profile) {
+ return new PinnedTabService(profile);
+}
+
+PinnedTabService* BuildForProfile(Profile* profile) {
+ return static_cast<PinnedTabService*>(
+ PinnedTabServiceFactory::GetInstance()->SetTestingFactoryAndUse(
+ profile, BuildPinnedTabService));
+}
+
class PinnedTabServiceTest : public BrowserWithTestWindowTest {
public:
PinnedTabServiceTest() {}
@@ -21,12 +34,12 @@ class PinnedTabServiceTest : public BrowserWithTestWindowTest {
protected:
virtual TestingProfile* CreateProfile() OVERRIDE {
TestingProfile* profile = BrowserWithTestWindowTest::CreateProfile();
- pinned_tab_service_.reset(new PinnedTabService(profile));
+ pinned_tab_service_ = BuildForProfile(profile);
return profile;
}
private:
- scoped_ptr<PinnedTabService> pinned_tab_service_;
+ PinnedTabService* pinned_tab_service_;
DISALLOW_COPY_AND_ASSIGN(PinnedTabServiceTest);
};
@@ -61,3 +74,4 @@ TEST_F(PinnedTabServiceTest, Popup) {
EXPECT_EQ("http://www.google.com/::pinned:", result);
}
+} // namespace