diff options
author | rlp@chromium.org <rlp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-06 07:48:15 +0000 |
---|---|---|
committer | rlp@chromium.org <rlp@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-06 07:48:15 +0000 |
commit | 13169abc0aaffd173439844c9457c2e2eb96ccb2 (patch) | |
tree | 7747d2a9c8f8f5a1cc69de475ee91c7cd1625cd4 /chrome | |
parent | 1cbbad5bac0e5e5e097b417152ecedaa206e8371 (diff) | |
download | chromium_src-13169abc0aaffd173439844c9457c2e2eb96ccb2.zip chromium_src-13169abc0aaffd173439844c9457c2e2eb96ccb2.tar.gz chromium_src-13169abc0aaffd173439844c9457c2e2eb96ccb2.tar.bz2 |
Convert UserStyleSheetWatcher to a ProfileKeyedService.
BUG=121004
TEST=no new ones, passes existing
Review URL: http://codereview.chromium.org/9969037
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@131110 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/chrome_content_browser_client.cc | 7 | ||||
-rw-r--r-- | chrome/browser/profiles/off_the_record_profile_impl.cc | 4 | ||||
-rw-r--r-- | chrome/browser/profiles/off_the_record_profile_impl.h | 1 | ||||
-rw-r--r-- | chrome/browser/profiles/profile.h | 4 | ||||
-rw-r--r-- | chrome/browser/profiles/profile_dependency_manager.cc | 2 | ||||
-rw-r--r-- | chrome/browser/profiles/profile_impl.cc | 8 | ||||
-rw-r--r-- | chrome/browser/profiles/profile_impl.h | 2 | ||||
-rw-r--r-- | chrome/browser/user_style_sheet_watcher.cc | 9 | ||||
-rw-r--r-- | chrome/browser/user_style_sheet_watcher.h | 14 | ||||
-rw-r--r-- | chrome/browser/user_style_sheet_watcher_factory.cc | 46 | ||||
-rw-r--r-- | chrome/browser/user_style_sheet_watcher_factory.h | 39 | ||||
-rw-r--r-- | chrome/chrome_browser.gypi | 2 | ||||
-rw-r--r-- | chrome/test/base/testing_profile.cc | 4 | ||||
-rw-r--r-- | chrome/test/base/testing_profile.h | 1 |
14 files changed, 108 insertions, 35 deletions
diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/chrome_content_browser_client.cc index 4e5e7e4..d82f720 100644 --- a/chrome/browser/chrome_content_browser_client.cc +++ b/chrome/browser/chrome_content_browser_client.cc @@ -66,6 +66,7 @@ #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h" #include "chrome/browser/user_style_sheet_watcher.h" +#include "chrome/browser/user_style_sheet_watcher_factory.h" #include "chrome/common/child_process_logging.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_switches.h" @@ -1434,10 +1435,12 @@ void ChromeContentBrowserClient::OverrideWebkitPrefs( web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled; // The user stylesheet watcher may not exist in a testing profile. - if (profile->GetUserStyleSheetWatcher()) { + UserStyleSheetWatcher* user_style_sheet_watcher = + UserStyleSheetWatcherFactory::GetForProfile(profile); + if (user_style_sheet_watcher) { web_prefs->user_style_sheet_enabled = true; web_prefs->user_style_sheet_location = - profile->GetUserStyleSheetWatcher()->user_style_sheet(); + user_style_sheet_watcher->user_style_sheet(); } else { web_prefs->user_style_sheet_enabled = false; } diff --git a/chrome/browser/profiles/off_the_record_profile_impl.cc b/chrome/browser/profiles/off_the_record_profile_impl.cc index c22c132..ad58ba2 100644 --- a/chrome/browser/profiles/off_the_record_profile_impl.cc +++ b/chrome/browser/profiles/off_the_record_profile_impl.cc @@ -342,10 +342,6 @@ content::SpeechRecognitionPreferences* return profile_->GetSpeechRecognitionPreferences(); } -UserStyleSheetWatcher* OffTheRecordProfileImpl::GetUserStyleSheetWatcher() { - return profile_->GetUserStyleSheetWatcher(); -} - bool OffTheRecordProfileImpl::DidLastSessionExitCleanly() { return profile_->DidLastSessionExitCleanly(); } diff --git a/chrome/browser/profiles/off_the_record_profile_impl.h b/chrome/browser/profiles/off_the_record_profile_impl.h index 0427b15..cc58a70 100644 --- a/chrome/browser/profiles/off_the_record_profile_impl.h +++ b/chrome/browser/profiles/off_the_record_profile_impl.h @@ -63,7 +63,6 @@ class OffTheRecordProfileImpl : public Profile, const std::string& app_id) OVERRIDE; virtual net::SSLConfigService* GetSSLConfigService() OVERRIDE; virtual HostContentSettingsMap* GetHostContentSettingsMap() OVERRIDE; - virtual UserStyleSheetWatcher* GetUserStyleSheetWatcher() OVERRIDE; virtual BookmarkModel* GetBookmarkModel() OVERRIDE; virtual ProtocolHandlerRegistry* GetProtocolHandlerRegistry() OVERRIDE; virtual bool IsSameProfile(Profile* profile) OVERRIDE; diff --git a/chrome/browser/profiles/profile.h b/chrome/browser/profiles/profile.h index 446b508..eca7fba 100644 --- a/chrome/browser/profiles/profile.h +++ b/chrome/browser/profiles/profile.h @@ -37,7 +37,6 @@ class PromoCounter; class ProtocolHandlerRegistry; class TestingProfile; class UserScriptMaster; -class UserStyleSheetWatcher; class VisitedLinkMaster; class WebDataService; @@ -319,9 +318,6 @@ class Profile : public content::BrowserContext { // Returns the Hostname <-> Content settings map for this profile. virtual HostContentSettingsMap* GetHostContentSettingsMap() = 0; - // Returns the user style sheet watcher. - virtual UserStyleSheetWatcher* GetUserStyleSheetWatcher() = 0; - // Returns the BookmarkModel, creating if not yet created. virtual BookmarkModel* GetBookmarkModel() = 0; diff --git a/chrome/browser/profiles/profile_dependency_manager.cc b/chrome/browser/profiles/profile_dependency_manager.cc index 3565e0c..f225e6a 100644 --- a/chrome/browser/profiles/profile_dependency_manager.cc +++ b/chrome/browser/profiles/profile_dependency_manager.cc @@ -37,6 +37,7 @@ #include "chrome/browser/ui/find_bar/find_bar_state_factory.h" #include "chrome/browser/ui/global_error_service_factory.h" #include "chrome/browser/ui/webui/ntp/ntp_resource_cache_factory.h" +#include "chrome/browser/user_style_sheet_watcher_factory.h" #ifndef NDEBUG #include "base/command_line.h" @@ -202,6 +203,7 @@ void ProfileDependencyManager::AssertFactoriesBuilt() { #if defined(ENABLE_THEMES) ThemeServiceFactory::GetInstance(); #endif + UserStyleSheetWatcherFactory::GetInstance(); #if defined(ENABLE_WEB_INTENTS) WebIntentsRegistryFactory::GetInstance(); #endif diff --git a/chrome/browser/profiles/profile_impl.cc b/chrome/browser/profiles/profile_impl.cc index 1f6179d..b8958dd 100644 --- a/chrome/browser/profiles/profile_impl.cc +++ b/chrome/browser/profiles/profile_impl.cc @@ -761,14 +761,6 @@ content::SpeechRecognitionPreferences* #endif } -UserStyleSheetWatcher* ProfileImpl::GetUserStyleSheetWatcher() { - if (!user_style_sheet_watcher_.get()) { - user_style_sheet_watcher_ = new UserStyleSheetWatcher(this, GetPath()); - user_style_sheet_watcher_->Init(); - } - return user_style_sheet_watcher_.get(); -} - GAIAInfoUpdateService* ProfileImpl::GetGAIAInfoUpdateService() { if (!gaia_info_update_service_.get() && GAIAInfoUpdateService::ShouldUseGAIAProfileInfo(this)) { diff --git a/chrome/browser/profiles/profile_impl.h b/chrome/browser/profiles/profile_impl.h index 9f76bc1..252dc61 100644 --- a/chrome/browser/profiles/profile_impl.h +++ b/chrome/browser/profiles/profile_impl.h @@ -97,7 +97,6 @@ class ProfileImpl : public Profile, const std::string& app_id) OVERRIDE; virtual net::SSLConfigService* GetSSLConfigService() OVERRIDE; virtual HostContentSettingsMap* GetHostContentSettingsMap() OVERRIDE; - virtual UserStyleSheetWatcher* GetUserStyleSheetWatcher() OVERRIDE; virtual BookmarkModel* GetBookmarkModel() OVERRIDE; virtual ProtocolHandlerRegistry* GetProtocolHandlerRegistry() OVERRIDE; virtual bool IsSameProfile(Profile* profile) OVERRIDE; @@ -211,7 +210,6 @@ class ProfileImpl : public Profile, geolocation_permission_context_; scoped_refptr<content::SpeechRecognitionPreferences> speech_recognition_preferences_; - scoped_refptr<UserStyleSheetWatcher> user_style_sheet_watcher_; scoped_ptr<GAIAInfoUpdateService> gaia_info_update_service_; scoped_refptr<HistoryService> history_service_; scoped_ptr<FaviconService> favicon_service_; diff --git a/chrome/browser/user_style_sheet_watcher.cc b/chrome/browser/user_style_sheet_watcher.cc index 09093e6..4f909c1 100644 --- a/chrome/browser/user_style_sheet_watcher.cc +++ b/chrome/browser/user_style_sheet_watcher.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. @@ -133,7 +133,8 @@ void UserStyleSheetLoader::SetStyleSheet(const GURL& url) { UserStyleSheetWatcher::UserStyleSheetWatcher(Profile* profile, const FilePath& profile_path) - : profile_(profile), + : RefcountedProfileKeyedService(content::BrowserThread::UI), + profile_(profile), profile_path_(profile_path), loader_(new UserStyleSheetLoader) { // Listen for when the first render view host is created. If we load @@ -182,3 +183,7 @@ void UserStyleSheetWatcher::Observe(int type, registrar_.RemoveAll(); } } + +void UserStyleSheetWatcher::ShutdownOnUIThread() { + registrar_.RemoveAll(); +} diff --git a/chrome/browser/user_style_sheet_watcher.h b/chrome/browser/user_style_sheet_watcher.h index b167963..228e3e2 100644 --- a/chrome/browser/user_style_sheet_watcher.h +++ b/chrome/browser/user_style_sheet_watcher.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. @@ -11,6 +11,7 @@ #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "base/message_loop_helpers.h" +#include "chrome/browser/profiles/refcounted_profile_keyed_service.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_registrar.h" @@ -22,10 +23,8 @@ class UserStyleSheetLoader; // Watches the user style sheet file and triggers reloads on the file thread // whenever the file changes. class UserStyleSheetWatcher - : public base::RefCountedThreadSafe< - UserStyleSheetWatcher, - content::BrowserThread::DeleteOnUIThread>, - public content::NotificationObserver { + : public content::NotificationObserver, + public RefcountedProfileKeyedService { public: UserStyleSheetWatcher(Profile* profile, const FilePath& profile_path); @@ -38,9 +37,10 @@ class UserStyleSheetWatcher const content::NotificationSource& source, const content::NotificationDetails& details) OVERRIDE; + // RefCountedProfileKeyedBase method override. + virtual void ShutdownOnUIThread() OVERRIDE; + private: - friend struct content::BrowserThread::DeleteOnThread< - content::BrowserThread::UI>; friend class base::DeleteHelper<UserStyleSheetWatcher>; virtual ~UserStyleSheetWatcher(); diff --git a/chrome/browser/user_style_sheet_watcher_factory.cc b/chrome/browser/user_style_sheet_watcher_factory.cc new file mode 100644 index 0000000..e096bff --- /dev/null +++ b/chrome/browser/user_style_sheet_watcher_factory.cc @@ -0,0 +1,46 @@ +// 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. + +#include "chrome/browser/user_style_sheet_watcher_factory.h" + +#include "chrome/browser/profiles/profile.h" +#include "chrome/browser/profiles/profile_dependency_manager.h" +#include "chrome/browser/user_style_sheet_watcher.h" + +// static +scoped_refptr<UserStyleSheetWatcher> +UserStyleSheetWatcherFactory::GetForProfile( + Profile* profile) { + return static_cast<UserStyleSheetWatcher*>( + GetInstance()->GetServiceForProfile(profile, true).get()); +} + +// static +UserStyleSheetWatcherFactory* UserStyleSheetWatcherFactory::GetInstance() { + return Singleton<UserStyleSheetWatcherFactory>::get(); +} + +UserStyleSheetWatcherFactory::UserStyleSheetWatcherFactory() + : RefcountedProfileKeyedServiceFactory( + "UserStyleSheetWatcher", ProfileDependencyManager::GetInstance()) { +} + +UserStyleSheetWatcherFactory::~UserStyleSheetWatcherFactory() { +} + +scoped_refptr<RefcountedProfileKeyedService> +UserStyleSheetWatcherFactory::BuildServiceInstanceFor(Profile* profile) const { + scoped_refptr<UserStyleSheetWatcher> user_style_sheet_watcher( + new UserStyleSheetWatcher(profile, profile->GetPath())); + user_style_sheet_watcher->Init(); + return user_style_sheet_watcher; +} + +bool UserStyleSheetWatcherFactory::ServiceRedirectedInIncognito() { + return true; +} + +bool UserStyleSheetWatcherFactory::ServiceIsNULLWhileTesting() { + return true; +} diff --git a/chrome/browser/user_style_sheet_watcher_factory.h b/chrome/browser/user_style_sheet_watcher_factory.h new file mode 100644 index 0000000..30bcd22 --- /dev/null +++ b/chrome/browser/user_style_sheet_watcher_factory.h @@ -0,0 +1,39 @@ +// 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. + +#ifndef CHROME_BROWSER_USER_STYLE_SHEET_WATCHER_FACTORY_H_ +#define CHROME_BROWSER_USER_STYLE_SHEET_WATCHER_FACTORY_H_ +#pragma once + +#include "base/memory/singleton.h" +#include "chrome/browser/profiles/refcounted_profile_keyed_service_factory.h" + +class Profile; +class UserStyleSheetWatcher; + +// Singleton that owns all UserStyleSheetWatcher and associates them with +// Profiles. +class UserStyleSheetWatcherFactory + : public RefcountedProfileKeyedServiceFactory { + public: + static scoped_refptr<UserStyleSheetWatcher> GetForProfile(Profile* profile); + + static UserStyleSheetWatcherFactory* GetInstance(); + + private: + friend struct DefaultSingletonTraits<UserStyleSheetWatcherFactory>; + + UserStyleSheetWatcherFactory(); + virtual ~UserStyleSheetWatcherFactory(); + + // ProfileKeyedServiceFactory: + virtual scoped_refptr<RefcountedProfileKeyedService> BuildServiceInstanceFor( + Profile* profile) const OVERRIDE; + virtual bool ServiceRedirectedInIncognito() OVERRIDE; + virtual bool ServiceIsNULLWhileTesting() OVERRIDE; + + DISALLOW_COPY_AND_ASSIGN(UserStyleSheetWatcherFactory); +}; + +#endif // CHROME_BROWSER_USER_STYLE_SHEET_WATCHER_FACTORY_H_ diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 284b1cf..802ca3d 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -3942,6 +3942,8 @@ 'browser/upgrade_detector_impl.h', 'browser/user_style_sheet_watcher.cc', 'browser/user_style_sheet_watcher.h', + 'browser/user_style_sheet_watcher_factory.cc', + 'browser/user_style_sheet_watcher_factory.h', 'browser/visitedlink/visitedlink_event_listener.cc', 'browser/visitedlink/visitedlink_event_listener.h', 'browser/visitedlink/visitedlink_master.cc', diff --git a/chrome/test/base/testing_profile.cc b/chrome/test/base/testing_profile.cc index 385b0fe..99b3d6f 100644 --- a/chrome/test/base/testing_profile.cc +++ b/chrome/test/base/testing_profile.cc @@ -591,10 +591,6 @@ net::SSLConfigService* TestingProfile::GetSSLConfigService() { return NULL; } -UserStyleSheetWatcher* TestingProfile::GetUserStyleSheetWatcher() { - return NULL; -} - net::URLRequestContextGetter* TestingProfile::GetRequestContextForIsolatedApp( const std::string& app_id) { // We don't test isolated app storage here yet, so returning the same dummy diff --git a/chrome/test/base/testing_profile.h b/chrome/test/base/testing_profile.h index 1214218..f9ff29e 100644 --- a/chrome/test/base/testing_profile.h +++ b/chrome/test/base/testing_profile.h @@ -203,7 +203,6 @@ class TestingProfile : public Profile { virtual net::URLRequestContextGetter* GetRequestContextForIsolatedApp( const std::string& app_id) OVERRIDE; virtual net::SSLConfigService* GetSSLConfigService() OVERRIDE; - virtual UserStyleSheetWatcher* GetUserStyleSheetWatcher() OVERRIDE; virtual HostContentSettingsMap* GetHostContentSettingsMap() OVERRIDE; virtual std::wstring GetName(); virtual void SetName(const std::wstring& name) {} |