From 49b3c58578b73c0af19c180e9f3658534a9a1688 Mon Sep 17 00:00:00 2001 From: "erg@google.com" Date: Wed, 25 Jan 2012 00:49:16 +0000 Subject: 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 --- .../browser/profiles/profile_dependency_manager.cc | 6 ++---- chrome/browser/profiles/profile_impl.cc | 3 --- chrome/browser/tabs/pinned_tab_service_factory.cc | 21 +++++++++++++++------ chrome/browser/tabs/pinned_tab_service_factory.h | 15 +++++++++------ chrome/browser/tabs/pinned_tab_service_unittest.cc | 20 +++++++++++++++++--- 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 g_pinned_tab_service_factory = - LAZY_INSTANCE_INITIALIZER; +// static +PinnedTabService* PinnedTabServiceFactory::GetForProfile( + Profile* profile) { + return static_cast( + GetInstance()->GetServiceForProfile(profile, true)); } -// static -void PinnedTabServiceFactory::InitForProfile(Profile* profile) { - g_pinned_tab_service_factory.Get().GetServiceForProfile(profile, true); +PinnedTabServiceFactory* PinnedTabServiceFactory::GetInstance() { + return Singleton::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; + friend struct DefaultSingletonTraits; 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( + 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 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 -- cgit v1.1