diff options
Diffstat (limited to 'chrome/browser')
19 files changed, 283 insertions, 191 deletions
diff --git a/chrome/browser/browser_process.h b/chrome/browser/browser_process.h index b9510a8..409771a 100644 --- a/chrome/browser/browser_process.h +++ b/chrome/browser/browser_process.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 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. @@ -50,6 +50,10 @@ class PrintJobManager; class PrintPreviewTabController; } +namespace policy { +class ConfigurationPolicyProviderKeeper; +} + // NOT THREAD SAFE, call only from the main thread. // These functions shouldn't return NULL unless otherwise noted. class BrowserProcess { @@ -107,6 +111,9 @@ class BrowserProcess { virtual base::Thread* background_x11_thread() = 0; #endif + virtual policy::ConfigurationPolicyProviderKeeper* + configuration_policy_provider_keeper() = 0; + virtual IconManager* icon_manager() = 0; virtual ThumbnailGenerator* GetThumbnailGenerator() = 0; diff --git a/chrome/browser/browser_process_impl.cc b/chrome/browser/browser_process_impl.cc index 482f547..83fe028 100644 --- a/chrome/browser/browser_process_impl.cc +++ b/chrome/browser/browser_process_impl.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 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. @@ -40,6 +40,7 @@ #include "chrome/browser/plugin_data_remover.h" #include "chrome/browser/plugin_service.h" #include "chrome/browser/plugin_updater.h" +#include "chrome/browser/policy/configuration_policy_provider_keeper.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/printing/print_job_manager.h" #include "chrome/browser/printing/print_preview_tab_controller.h" @@ -100,6 +101,7 @@ BrowserProcessImpl::BrowserProcessImpl(const CommandLine& command_line) created_debugger_wrapper_(false), created_devtools_manager_(false), created_sidebar_manager_(false), + created_configuration_policy_provider_keeper_(false), created_notification_ui_manager_(false), created_safe_browsing_detection_service_(false), module_ref_count_(0), @@ -175,6 +177,10 @@ BrowserProcessImpl::~BrowserProcessImpl() { resource_dispatcher_host()->Shutdown(); } + // The policy providers managed by |configuration_policy_provider_keeper_| + // need to shut down while the file thread is still alive. + configuration_policy_provider_keeper_.reset(); + #if defined(USE_X11) // The IO thread must outlive the BACKGROUND_X11 thread. background_x11_thread_.reset(); @@ -414,6 +420,18 @@ NotificationUIManager* BrowserProcessImpl::notification_ui_manager() { return notification_ui_manager_.get(); } +policy::ConfigurationPolicyProviderKeeper* + BrowserProcessImpl::configuration_policy_provider_keeper() { + DCHECK(CalledOnValidThread()); + if (!created_configuration_policy_provider_keeper_) { + DCHECK(configuration_policy_provider_keeper_.get() == NULL); + created_configuration_policy_provider_keeper_ = true; + configuration_policy_provider_keeper_.reset( + new policy::ConfigurationPolicyProviderKeeper()); + } + return configuration_policy_provider_keeper_.get(); +} + IconManager* BrowserProcessImpl::icon_manager() { DCHECK(CalledOnValidThread()); if (!created_icon_manager_) diff --git a/chrome/browser/browser_process_impl.h b/chrome/browser/browser_process_impl.h index d5d3b51..8ec6f81 100644 --- a/chrome/browser/browser_process_impl.h +++ b/chrome/browser/browser_process_impl.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 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. @@ -61,6 +61,8 @@ class BrowserProcessImpl : public BrowserProcess, virtual SidebarManager* sidebar_manager(); virtual Clipboard* clipboard(); virtual NotificationUIManager* notification_ui_manager(); + virtual policy::ConfigurationPolicyProviderKeeper* + configuration_policy_provider_keeper(); virtual IconManager* icon_manager(); virtual ThumbnailGenerator* GetThumbnailGenerator(); virtual AutomationProviderList* InitAutomationProviderList(); @@ -179,6 +181,10 @@ class BrowserProcessImpl : public BrowserProcess, bool created_sidebar_manager_; scoped_refptr<SidebarManager> sidebar_manager_; + bool created_configuration_policy_provider_keeper_; + scoped_ptr<policy::ConfigurationPolicyProviderKeeper> + configuration_policy_provider_keeper_; + scoped_refptr<printing::PrintPreviewTabController> print_preview_tab_controller_; diff --git a/chrome/browser/policy/asynchronous_policy_loader.cc b/chrome/browser/policy/asynchronous_policy_loader.cc index 6ccae7a..f06ead7 100644 --- a/chrome/browser/policy/asynchronous_policy_loader.cc +++ b/chrome/browser/policy/asynchronous_policy_loader.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 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. @@ -38,6 +38,9 @@ void AsynchronousPolicyLoader::Stop() { if (!stopped_) { stopped_ = true; delegate_.reset(); + FOR_EACH_OBSERVER(ConfigurationPolicyProvider::Observer, + observer_list_, + OnProviderGoingAway()); BrowserThread::PostTask( BrowserThread::FILE, FROM_HERE, NewRunnableMethod(this, &AsynchronousPolicyLoader::StopOnFileThread)); diff --git a/chrome/browser/policy/asynchronous_policy_loader_unittest.cc b/chrome/browser/policy/asynchronous_policy_loader_unittest.cc index 3cc416c..44ab3c2 100644 --- a/chrome/browser/policy/asynchronous_policy_loader_unittest.cc +++ b/chrome/browser/policy/asynchronous_policy_loader_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 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. @@ -18,6 +18,7 @@ class MockConfigurationPolicyObserver : public ConfigurationPolicyProvider::Observer { public: MOCK_METHOD0(OnUpdatePolicy, void()); + void OnProviderGoingAway() {} }; class AsynchronousPolicyLoaderTest : public AsynchronousPolicyTestBase { @@ -120,8 +121,7 @@ TEST_F(AsynchronousPolicyLoaderTest, ProviderNotificationOnPolicyChange) { AsynchronousPolicyProvider provider(NULL, loader); // |registrar| must be declared last so that it is destroyed first. ConfigurationPolicyObserverRegistrar registrar; - registrar.Init(&provider); - registrar.AddObserver(&observer); + registrar.Init(&provider, &observer); loop_.RunAllPending(); loader->Reload(); loop_.RunAllPending(); diff --git a/chrome/browser/policy/configuration_policy_pref_store.cc b/chrome/browser/policy/configuration_policy_pref_store.cc index 1dc917a..a942bfc 100644 --- a/chrome/browser/policy/configuration_policy_pref_store.cc +++ b/chrome/browser/policy/configuration_policy_pref_store.cc @@ -1,9 +1,10 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 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/policy/configuration_policy_pref_store.h" +#include <map> #include <set> #include <string> #include <vector> @@ -11,29 +12,21 @@ #include "base/command_line.h" #include "base/lazy_instance.h" #include "base/logging.h" -#include "base/path_service.h" #include "base/stl_util-inl.h" #include "base/string16.h" #include "base/string_util.h" #include "base/utf_string_conversions.h" #include "base/values.h" +#include "chrome/browser/browser_process.h" #include "chrome/browser/policy/configuration_policy_provider.h" -#if defined(OS_WIN) -#include "chrome/browser/policy/configuration_policy_provider_win.h" -#elif defined(OS_MACOSX) -#include "chrome/browser/policy/configuration_policy_provider_mac.h" -#elif defined(OS_POSIX) -#include "chrome/browser/policy/config_dir_policy_provider.h" -#endif +#include "chrome/browser/policy/configuration_policy_provider_keeper.h" #include "chrome/browser/policy/device_management_policy_provider.h" -#include "chrome/browser/policy/dummy_configuration_policy_provider.h" #include "chrome/browser/policy/profile_policy_context.h" #include "chrome/browser/prefs/pref_value_map.h" #include "chrome/browser/prefs/proxy_prefs.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/search_engines/search_terms_data.h" #include "chrome/browser/search_engines/template_url.h" -#include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/notification_service.h" #include "chrome/common/policy_constants.h" @@ -620,94 +613,6 @@ bool ConfigurationPolicyPrefKeeper::HasProxyPolicy( iter->second && !iter->second->IsType(Value::TYPE_NULL); } -namespace { - -// Manages the lifecycle of the shared platform-specific policy providers for -// managed platform, device management and recommended policy. Instantiated as a -// Singleton. -class ConfigurationPolicyProviderKeeper { - public: - ConfigurationPolicyProviderKeeper() - : managed_platform_provider_(CreateManagedPlatformProvider()), - device_management_provider_(CreateDeviceManagementProvider()), - recommended_provider_(CreateRecommendedProvider()) {} - virtual ~ConfigurationPolicyProviderKeeper() {} - - ConfigurationPolicyProvider* managed_platform_provider() const { - return managed_platform_provider_.get(); - } - - ConfigurationPolicyProvider* device_management_provider() const { - return device_management_provider_.get(); - } - - ConfigurationPolicyProvider* recommended_provider() const { - return recommended_provider_.get(); - } - - private: - scoped_ptr<ConfigurationPolicyProvider> managed_platform_provider_; - scoped_ptr<ConfigurationPolicyProvider> device_management_provider_; - scoped_ptr<ConfigurationPolicyProvider> recommended_provider_; - - static ConfigurationPolicyProvider* CreateManagedPlatformProvider(); - static ConfigurationPolicyProvider* CreateDeviceManagementProvider(); - static ConfigurationPolicyProvider* CreateRecommendedProvider(); - - DISALLOW_COPY_AND_ASSIGN(ConfigurationPolicyProviderKeeper); -}; - -static base::LazyInstance<ConfigurationPolicyProviderKeeper> - g_configuration_policy_provider_keeper(base::LINKER_INITIALIZED); - -ConfigurationPolicyProvider* -ConfigurationPolicyProviderKeeper::CreateManagedPlatformProvider() { - const ConfigurationPolicyProvider::PolicyDefinitionList* policy_list = - ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(); -#if defined(OS_WIN) - return new ConfigurationPolicyProviderWin(policy_list); -#elif defined(OS_MACOSX) - return new ConfigurationPolicyProviderMac(policy_list); -#elif defined(OS_POSIX) - FilePath config_dir_path; - if (PathService::Get(chrome::DIR_POLICY_FILES, &config_dir_path)) { - return new ConfigDirPolicyProvider( - policy_list, - config_dir_path.Append(FILE_PATH_LITERAL("managed"))); - } else { - return new DummyConfigurationPolicyProvider(policy_list); - } -#else - return new DummyConfigurationPolicyProvider(policy_list); -#endif -} - -ConfigurationPolicyProvider* -ConfigurationPolicyProviderKeeper::CreateDeviceManagementProvider() { - return new DummyConfigurationPolicyProvider( - ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList()); -} - -ConfigurationPolicyProvider* -ConfigurationPolicyProviderKeeper::CreateRecommendedProvider() { - const ConfigurationPolicyProvider::PolicyDefinitionList* policy_list = - ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(); -#if defined(OS_POSIX) && !defined(OS_MACOSX) - FilePath config_dir_path; - if (PathService::Get(chrome::DIR_POLICY_FILES, &config_dir_path)) { - return new ConfigDirPolicyProvider( - policy_list, - config_dir_path.Append(FILE_PATH_LITERAL("recommended"))); - } else { - return new DummyConfigurationPolicyProvider(policy_list); - } -#else - return new DummyConfigurationPolicyProvider(policy_list); -#endif -} - -} // namespace - ConfigurationPolicyPrefStore::ConfigurationPolicyPrefStore( ConfigurationPolicyProvider* provider) : provider_(provider), @@ -715,8 +620,7 @@ ConfigurationPolicyPrefStore::ConfigurationPolicyPrefStore( // Read initial policy. policy_keeper_.reset(new ConfigurationPolicyPrefKeeper(provider)); - registrar_.Init(provider_); - registrar_.AddObserver(this); + registrar_.Init(provider_, this); } ConfigurationPolicyPrefStore::~ConfigurationPolicyPrefStore() { @@ -745,11 +649,16 @@ void ConfigurationPolicyPrefStore::OnUpdatePolicy() { Refresh(); } +void ConfigurationPolicyPrefStore::OnProviderGoingAway() { + provider_ = NULL; +} + // static ConfigurationPolicyPrefStore* ConfigurationPolicyPrefStore::CreateManagedPlatformPolicyPrefStore() { - return new ConfigurationPolicyPrefStore( - g_configuration_policy_provider_keeper.Get().managed_platform_provider()); + ConfigurationPolicyProviderKeeper* keeper = + g_browser_process->configuration_policy_provider_keeper(); + return new ConfigurationPolicyPrefStore(keeper->managed_platform_provider()); } // static @@ -757,7 +666,7 @@ ConfigurationPolicyPrefStore* ConfigurationPolicyPrefStore::CreateDeviceManagementPolicyPrefStore( Profile* profile) { ConfigurationPolicyProviderKeeper* keeper = - g_configuration_policy_provider_keeper.Pointer(); + g_browser_process->configuration_policy_provider_keeper(); ConfigurationPolicyProvider* provider = NULL; if (profile) provider = profile->GetPolicyContext()->GetDeviceManagementPolicyProvider(); @@ -769,8 +678,9 @@ ConfigurationPolicyPrefStore::CreateDeviceManagementPolicyPrefStore( // static ConfigurationPolicyPrefStore* ConfigurationPolicyPrefStore::CreateRecommendedPolicyPrefStore() { - return new ConfigurationPolicyPrefStore( - g_configuration_policy_provider_keeper.Get().recommended_provider()); + ConfigurationPolicyProviderKeeper* keeper = + g_browser_process->configuration_policy_provider_keeper(); + return new ConfigurationPolicyPrefStore(keeper->recommended_provider()); } /* static */ @@ -878,6 +788,9 @@ ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList() { } void ConfigurationPolicyPrefStore::Refresh() { + if (!provider_) + return; + // Construct a new keeper, determine what changed and swap the keeper in. scoped_ptr<ConfigurationPolicyPrefKeeper> new_keeper( new ConfigurationPolicyPrefKeeper(provider_)); diff --git a/chrome/browser/policy/configuration_policy_pref_store.h b/chrome/browser/policy/configuration_policy_pref_store.h index 526d884..93b2a4a 100644 --- a/chrome/browser/policy/configuration_policy_pref_store.h +++ b/chrome/browser/policy/configuration_policy_pref_store.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 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. @@ -42,6 +42,7 @@ class ConfigurationPolicyPrefStore // ConfigurationPolicyProvider::Observer methods: virtual void OnUpdatePolicy(); + virtual void OnProviderGoingAway(); // Creates a ConfigurationPolicyPrefStore that reads managed platform policy. static ConfigurationPolicyPrefStore* CreateManagedPlatformPolicyPrefStore(); diff --git a/chrome/browser/policy/configuration_policy_provider.cc b/chrome/browser/policy/configuration_policy_provider.cc index 2aee046..3b82134 100644 --- a/chrome/browser/policy/configuration_policy_provider.cc +++ b/chrome/browser/policy/configuration_policy_provider.cc @@ -1,46 +1,13 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 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/policy/configuration_policy_provider.h" -#include <algorithm> - #include "base/values.h" namespace policy { -ConfigurationPolicyObserverRegistrar::ConfigurationPolicyObserverRegistrar() {} - -ConfigurationPolicyObserverRegistrar::~ConfigurationPolicyObserverRegistrar() { - RemoveAll(); -} - -void ConfigurationPolicyObserverRegistrar::Init( - ConfigurationPolicyProvider* provider) { - provider_ = provider; -} - -void ConfigurationPolicyObserverRegistrar::AddObserver( - ConfigurationPolicyProvider::Observer* observer) { - observers_.push_back(observer); - provider_->AddObserver(observer); -} - -void ConfigurationPolicyObserverRegistrar::RemoveObserver( - ConfigurationPolicyProvider::Observer* observer) { - std::remove(observers_.begin(), observers_.end(), observer); - provider_->RemoveObserver(observer); -} - -void ConfigurationPolicyObserverRegistrar::RemoveAll() { - for (std::vector<ConfigurationPolicyProvider::Observer*>::iterator it = - observers_.begin(); it != observers_.end(); ++it) { - provider_->RemoveObserver(*it); - } - observers_.clear(); -} - // Class ConfigurationPolicyProvider. ConfigurationPolicyProvider::ConfigurationPolicyProvider( @@ -65,4 +32,31 @@ void ConfigurationPolicyProvider::DecodePolicyValueTree( // supports it. } +// Class ConfigurationPolicyObserverRegistrar. + +ConfigurationPolicyObserverRegistrar::ConfigurationPolicyObserverRegistrar() {} + +ConfigurationPolicyObserverRegistrar::~ConfigurationPolicyObserverRegistrar() { + if (provider_) + provider_->RemoveObserver(this); +} + +void ConfigurationPolicyObserverRegistrar::Init( + ConfigurationPolicyProvider* provider, + ConfigurationPolicyProvider::Observer* observer) { + provider_ = provider; + observer_ = observer; + provider_->AddObserver(this); +} + +void ConfigurationPolicyObserverRegistrar::OnUpdatePolicy() { + observer_->OnUpdatePolicy(); +} + +void ConfigurationPolicyObserverRegistrar::OnProviderGoingAway() { + observer_->OnProviderGoingAway(); + provider_->RemoveObserver(this); + provider_ = NULL; +} + } // namespace policy diff --git a/chrome/browser/policy/configuration_policy_provider.h b/chrome/browser/policy/configuration_policy_provider.h index 5639235..81c1813 100644 --- a/chrome/browser/policy/configuration_policy_provider.h +++ b/chrome/browser/policy/configuration_policy_provider.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 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,7 +7,6 @@ #pragma once #include <string> -#include <vector> #include "base/basictypes.h" #include "base/scoped_ptr.h" @@ -25,6 +24,7 @@ class ConfigurationPolicyProvider { public: virtual ~Observer() {} virtual void OnUpdatePolicy() = 0; + virtual void OnProviderGoingAway() = 0; }; // Used for static arrays of policy values that is used to initialize an @@ -83,17 +83,25 @@ class ConfigurationPolicyProvider { // Manages observers for a ConfigurationPolicyProvider. Is used to register // observers, and automatically removes them upon destruction. -class ConfigurationPolicyObserverRegistrar { +// Implementation detail: to avoid duplicate bookkeeping of registered +// observers, this registrar class acts as a proxy for notifications (since it +// needs to register itself anyway to get OnProviderGoingAway notifications). +class ConfigurationPolicyObserverRegistrar + : ConfigurationPolicyProvider::Observer { public: ConfigurationPolicyObserverRegistrar(); ~ConfigurationPolicyObserverRegistrar(); - void Init(ConfigurationPolicyProvider* provider); - void AddObserver(ConfigurationPolicyProvider::Observer* observer); - void RemoveObserver(ConfigurationPolicyProvider::Observer* observer); - void RemoveAll(); + void Init(ConfigurationPolicyProvider* provider, + ConfigurationPolicyProvider::Observer* observer); + + // ConfigurationPolicyProvider::Observer implementation: + virtual void OnUpdatePolicy(); + virtual void OnProviderGoingAway(); + private: ConfigurationPolicyProvider* provider_; - std::vector<ConfigurationPolicyProvider::Observer*> observers_; + ConfigurationPolicyProvider::Observer* observer_; + DISALLOW_COPY_AND_ASSIGN(ConfigurationPolicyObserverRegistrar); }; diff --git a/chrome/browser/policy/configuration_policy_provider_keeper.cc b/chrome/browser/policy/configuration_policy_provider_keeper.cc new file mode 100644 index 0000000..768bb93 --- /dev/null +++ b/chrome/browser/policy/configuration_policy_provider_keeper.cc @@ -0,0 +1,98 @@ +// Copyright (c) 2011 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/policy/configuration_policy_provider_keeper.h" + +#include "base/path_service.h" +#include "chrome/browser/policy/configuration_policy_pref_store.h" +#include "chrome/browser/policy/configuration_policy_provider.h" +#if defined(OS_WIN) +#include "chrome/browser/policy/configuration_policy_provider_win.h" +#elif defined(OS_MACOSX) +#include "chrome/browser/policy/configuration_policy_provider_mac.h" +#elif defined(OS_POSIX) +#include "chrome/browser/policy/config_dir_policy_provider.h" +#endif +#include "chrome/browser/policy/dummy_configuration_policy_provider.h" +#include "chrome/common/chrome_paths.h" + +namespace policy { + +ConfigurationPolicyProviderKeeper::ConfigurationPolicyProviderKeeper() + : managed_platform_provider_(CreateManagedPlatformProvider()), + device_management_provider_(CreateDeviceManagementProvider()), + recommended_provider_(CreateRecommendedProvider()) { +} + +ConfigurationPolicyProviderKeeper::ConfigurationPolicyProviderKeeper( + ConfigurationPolicyProvider* managed_platform_provider, + ConfigurationPolicyProvider* device_management_provider, + ConfigurationPolicyProvider* recommended_provider) + : managed_platform_provider_(managed_platform_provider), + device_management_provider_(device_management_provider), + recommended_provider_(recommended_provider) { +} + +ConfigurationPolicyProvider* + ConfigurationPolicyProviderKeeper::managed_platform_provider() const { + return managed_platform_provider_.get(); +} + +ConfigurationPolicyProvider* + ConfigurationPolicyProviderKeeper::device_management_provider() const { + return device_management_provider_.get(); +} + +ConfigurationPolicyProvider* + ConfigurationPolicyProviderKeeper::recommended_provider() const { + return recommended_provider_.get(); +} + +ConfigurationPolicyProvider* + ConfigurationPolicyProviderKeeper::CreateManagedPlatformProvider() { + const ConfigurationPolicyProvider::PolicyDefinitionList* policy_list = + ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(); +#if defined(OS_WIN) + return new ConfigurationPolicyProviderWin(policy_list); +#elif defined(OS_MACOSX) + return new ConfigurationPolicyProviderMac(policy_list); +#elif defined(OS_POSIX) + FilePath config_dir_path; + if (PathService::Get(chrome::DIR_POLICY_FILES, &config_dir_path)) { + return new ConfigDirPolicyProvider( + policy_list, + config_dir_path.Append(FILE_PATH_LITERAL("managed"))); + } else { + return new DummyConfigurationPolicyProvider(policy_list); + } +#else + return new DummyConfigurationPolicyProvider(policy_list); +#endif +} + +ConfigurationPolicyProvider* + ConfigurationPolicyProviderKeeper::CreateDeviceManagementProvider() { + return new DummyConfigurationPolicyProvider( + ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList()); +} + +ConfigurationPolicyProvider* + ConfigurationPolicyProviderKeeper::CreateRecommendedProvider() { + const ConfigurationPolicyProvider::PolicyDefinitionList* policy_list = + ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(); +#if defined(OS_POSIX) && !defined(OS_MACOSX) + FilePath config_dir_path; + if (PathService::Get(chrome::DIR_POLICY_FILES, &config_dir_path)) { + return new ConfigDirPolicyProvider( + policy_list, + config_dir_path.Append(FILE_PATH_LITERAL("recommended"))); + } else { + return new DummyConfigurationPolicyProvider(policy_list); + } +#else + return new DummyConfigurationPolicyProvider(policy_list); +#endif +} + +} // namespace diff --git a/chrome/browser/policy/configuration_policy_provider_keeper.h b/chrome/browser/policy/configuration_policy_provider_keeper.h new file mode 100644 index 0000000..6994de4 --- /dev/null +++ b/chrome/browser/policy/configuration_policy_provider_keeper.h @@ -0,0 +1,46 @@ +// Copyright (c) 2011 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_POLICY_CONFIGURATION_POLICY_PROVIDER_KEEPER_H_ +#define CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_PROVIDER_KEEPER_H_ +#pragma once + +#include "base/scoped_ptr.h" +#include "chrome/browser/policy/configuration_policy_provider.h" + +namespace policy { + +// Manages the lifecycle of the shared platform-specific policy providers for +// managed platform, device management and recommended policy. +class ConfigurationPolicyProviderKeeper { + public: + ConfigurationPolicyProviderKeeper(); + // Tests can pass in their own (dummy) providers using this c'tor. + ConfigurationPolicyProviderKeeper( + ConfigurationPolicyProvider* managed_platform_provider, + ConfigurationPolicyProvider* device_management_provider, + ConfigurationPolicyProvider* recommended_provider); + virtual ~ConfigurationPolicyProviderKeeper() {} + + ConfigurationPolicyProvider* managed_platform_provider() const; + + ConfigurationPolicyProvider* device_management_provider() const; + + ConfigurationPolicyProvider* recommended_provider() const; + + private: + scoped_ptr<ConfigurationPolicyProvider> managed_platform_provider_; + scoped_ptr<ConfigurationPolicyProvider> device_management_provider_; + scoped_ptr<ConfigurationPolicyProvider> recommended_provider_; + + static ConfigurationPolicyProvider* CreateManagedPlatformProvider(); + static ConfigurationPolicyProvider* CreateDeviceManagementProvider(); + static ConfigurationPolicyProvider* CreateRecommendedProvider(); + + DISALLOW_COPY_AND_ASSIGN(ConfigurationPolicyProviderKeeper); +}; + +} // namespace policy + +#endif // CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_PROVIDER_KEEPER_H_ diff --git a/chrome/browser/policy/device_management_policy_provider.cc b/chrome/browser/policy/device_management_policy_provider.cc index 1a1f0c2..8b9d9b4 100644 --- a/chrome/browser/policy/device_management_policy_provider.cc +++ b/chrome/browser/policy/device_management_policy_provider.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 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. @@ -108,7 +108,11 @@ DeviceManagementPolicyProvider::DeviceManagementPolicyProvider( unmanaged_device_refresh_rate_ms); } -DeviceManagementPolicyProvider::~DeviceManagementPolicyProvider() {} +DeviceManagementPolicyProvider::~DeviceManagementPolicyProvider() { + FOR_EACH_OBSERVER(ConfigurationPolicyProvider::Observer, + observer_list_, + OnProviderGoingAway()); +} bool DeviceManagementPolicyProvider::Provide( ConfigurationPolicyStoreInterface* policy_store) { @@ -183,12 +187,6 @@ void DeviceManagementPolicyProvider::OnNotManaged() { StopWaitingForInitialPolicies(); } -void DeviceManagementPolicyProvider::Shutdown() { - profile_ = NULL; - if (token_fetcher_) - token_fetcher_->Shutdown(); -} - void DeviceManagementPolicyProvider::AddObserver( ConfigurationPolicyProvider::Observer* observer) { observer_list_.AddObserver(observer); diff --git a/chrome/browser/policy/device_management_policy_provider.h b/chrome/browser/policy/device_management_policy_provider.h index 17edf82..fd18bc3 100644 --- a/chrome/browser/policy/device_management_policy_provider.h +++ b/chrome/browser/policy/device_management_policy_provider.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 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. @@ -54,10 +54,6 @@ class DeviceManagementPolicyProvider virtual void OnTokenError(); virtual void OnNotManaged(); - // Tells the provider that the passed in token service reference is about to - // become invalid. - void Shutdown(); - private: class InitializeAfterIOThreadExistsTask; class RefreshTask; diff --git a/chrome/browser/policy/device_management_policy_provider_unittest.cc b/chrome/browser/policy/device_management_policy_provider_unittest.cc index 4886f9d..eac2c5b 100644 --- a/chrome/browser/policy/device_management_policy_provider_unittest.cc +++ b/chrome/browser/policy/device_management_policy_provider_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 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. @@ -34,6 +34,7 @@ class MockConfigurationPolicyObserver : public ConfigurationPolicyProvider::Observer { public: MOCK_METHOD0(OnUpdatePolicy, void()); + void OnProviderGoingAway() {} }; class DeviceManagementPolicyProviderTest : public testing::Test { @@ -207,8 +208,7 @@ TEST_F(DeviceManagementPolicyProviderTest, SecondProvide) { TEST_F(DeviceManagementPolicyProviderTest, FetchTriggersRefresh) { MockConfigurationPolicyObserver observer; ConfigurationPolicyObserverRegistrar registrar; - registrar.Init(provider_.get()); - registrar.AddObserver(&observer); + registrar.Init(provider_.get(), &observer); EXPECT_CALL(observer, OnUpdatePolicy()).Times(1); SimulateSuccessfulInitialPolicyFetch(); } diff --git a/chrome/browser/policy/device_token_fetcher.cc b/chrome/browser/policy/device_token_fetcher.cc index 678c90f..2d514b6 100644 --- a/chrome/browser/policy/device_token_fetcher.cc +++ b/chrome/browser/policy/device_token_fetcher.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 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. @@ -212,11 +212,6 @@ void DeviceTokenFetcher::StartFetching() { } } -void DeviceTokenFetcher::Shutdown() { - profile_ = NULL; - backend_ = NULL; -} - void DeviceTokenFetcher::AttemptTokenLoadFromDisk() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); if (file_util::PathExists(token_path_)) { diff --git a/chrome/browser/policy/device_token_fetcher.h b/chrome/browser/policy/device_token_fetcher.h index f047e61..ae22f3d 100644 --- a/chrome/browser/policy/device_token_fetcher.h +++ b/chrome/browser/policy/device_token_fetcher.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 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. @@ -79,10 +79,6 @@ class DeviceTokenFetcher // will need the token in the future. Must be called on the UI thread. void StartFetching(); - // Instructs the fetcher to shut down, before the backend and token service - // references become stale. - void Shutdown(); - // Returns true if there is a pending token request to the device management // server. bool IsTokenPending(); diff --git a/chrome/browser/policy/dummy_configuration_policy_provider.cc b/chrome/browser/policy/dummy_configuration_policy_provider.cc index 9a8f491..973ee4c 100644 --- a/chrome/browser/policy/dummy_configuration_policy_provider.cc +++ b/chrome/browser/policy/dummy_configuration_policy_provider.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 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. @@ -12,6 +12,9 @@ DummyConfigurationPolicyProvider::DummyConfigurationPolicyProvider( } DummyConfigurationPolicyProvider::~DummyConfigurationPolicyProvider() { + FOR_EACH_OBSERVER(ConfigurationPolicyProvider::Observer, + observer_list_, + OnProviderGoingAway()); } bool DummyConfigurationPolicyProvider::Provide( @@ -19,4 +22,14 @@ bool DummyConfigurationPolicyProvider::Provide( return true; } +void DummyConfigurationPolicyProvider::AddObserver( + ConfigurationPolicyProvider::Observer* observer) { + observer_list_.AddObserver(observer); +} + +void DummyConfigurationPolicyProvider::RemoveObserver( + ConfigurationPolicyProvider::Observer* observer) { + observer_list_.RemoveObserver(observer); +} + } // namespace policy diff --git a/chrome/browser/policy/dummy_configuration_policy_provider.h b/chrome/browser/policy/dummy_configuration_policy_provider.h index 22ca152..119a74b 100644 --- a/chrome/browser/policy/dummy_configuration_policy_provider.h +++ b/chrome/browser/policy/dummy_configuration_policy_provider.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 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,6 +6,7 @@ #define CHROME_BROWSER_POLICY_DUMMY_CONFIGURATION_POLICY_PROVIDER_H_ #pragma once +#include "base/observer_list.h" #include "chrome/browser/policy/configuration_policy_provider.h" namespace policy { @@ -22,9 +23,10 @@ class DummyConfigurationPolicyProvider : public ConfigurationPolicyProvider { private: // ConfigurationPolicyProvider overrides: - virtual void AddObserver(ConfigurationPolicyProvider::Observer* observer) {} - virtual void RemoveObserver( - ConfigurationPolicyProvider::Observer* observer) {} + virtual void AddObserver(ConfigurationPolicyProvider::Observer* observer); + virtual void RemoveObserver(ConfigurationPolicyProvider::Observer* observer); + + ObserverList<ConfigurationPolicyProvider::Observer, true> observer_list_; DISALLOW_COPY_AND_ASSIGN(DummyConfigurationPolicyProvider); }; diff --git a/chrome/browser/policy/profile_policy_context.cc b/chrome/browser/policy/profile_policy_context.cc index c4b6e5b..c221529 100644 --- a/chrome/browser/policy/profile_policy_context.cc +++ b/chrome/browser/policy/profile_policy_context.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 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. @@ -39,8 +39,6 @@ void ProfilePolicyContext::Initialize() { void ProfilePolicyContext::Shutdown() { if (device_management_service_.get()) device_management_service_->Shutdown(); - if (device_management_policy_provider_.get()) - device_management_policy_provider_->Shutdown(); } DeviceManagementPolicyProvider* |