Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2816)

Unified Diff: chrome/browser/chromeos/policy/device_local_account_policy_service.cc

Issue 342233005: Move ownership of the ComponentCloudPolicyService to the broker. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix clang build Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/policy/device_local_account_policy_service.cc
diff --git a/chrome/browser/chromeos/policy/device_local_account_policy_service.cc b/chrome/browser/chromeos/policy/device_local_account_policy_service.cc
index 9d853b80cb6748b7ca261bec78a0107b5a2efe24..2f703e32bd1ee0c70f5abbe3aa56535f64197490 100644
--- a/chrome/browser/chromeos/policy/device_local_account_policy_service.cc
+++ b/chrome/browser/chromeos/policy/device_local_account_policy_service.cc
@@ -7,6 +7,8 @@
#include <vector>
#include "base/bind.h"
+#include "base/callback.h"
bartfab (slow) 2014/06/20 09:44:23 Nit: Move this to the header file.
Joao da Silva 2014/06/20 15:36:07 Done.
+#include "base/command_line.h"
#include "base/file_util.h"
#include "base/files/file_enumerator.h"
#include "base/logging.h"
@@ -21,16 +23,20 @@
#include "chrome/browser/chromeos/policy/device_local_account_external_data_service.h"
#include "chrome/browser/chromeos/policy/device_local_account_policy_store.h"
#include "chrome/browser/chromeos/settings/device_settings_service.h"
+#include "chrome/browser/policy/schema_registry_service.h"
#include "chrome/common/chrome_content_client.h"
#include "chromeos/chromeos_paths.h"
#include "chromeos/dbus/session_manager_client.h"
#include "chromeos/settings/cros_settings_names.h"
#include "chromeos/settings/cros_settings_provider.h"
+#include "components/policy/core/browser/browser_policy_connector.h"
#include "components/policy/core/common/cloud/cloud_policy_client.h"
#include "components/policy/core/common/cloud/cloud_policy_constants.h"
#include "components/policy/core/common/cloud/cloud_policy_refresh_scheduler.h"
#include "components/policy/core/common/cloud/device_management_service.h"
+#include "components/policy/core/common/cloud/resource_cache.h"
#include "components/policy/core/common/cloud/system_policy_request_context.h"
+#include "components/policy/core/common/policy_switches.h"
#include "content/public/browser/browser_thread.h"
#include "net/url_request/url_request_context_getter.h"
#include "policy/policy_constants.h"
@@ -116,6 +122,7 @@ DeviceLocalAccountPolicyBroker::DeviceLocalAccountPolicyBroker(
const base::FilePath& component_policy_cache_path,
scoped_ptr<DeviceLocalAccountPolicyStore> store,
scoped_refptr<DeviceLocalAccountExternalDataManager> external_data_manager,
+ const base::Closure& policy_update_callback,
const scoped_refptr<base::SequencedTaskRunner>& task_runner)
: account_id_(account.account_id),
user_id_(account.user_id),
@@ -125,23 +132,45 @@ DeviceLocalAccountPolicyBroker::DeviceLocalAccountPolicyBroker(
core_(PolicyNamespaceKey(dm_protocol::kChromePublicAccountPolicyType,
store_->account_id()),
store_.get(),
- task_runner) {
+ task_runner),
+ policy_update_callback_(policy_update_callback) {
base::FilePath cache_root_dir;
CHECK(PathService::Get(chromeos::DIR_DEVICE_LOCAL_ACCOUNT_EXTENSIONS,
&cache_root_dir));
extension_loader_ = new chromeos::DeviceLocalAccountExternalPolicyLoader(
store_.get(), cache_root_dir.Append(EncodeAccountId(account.account_id)));
+ store_->AddObserver(this);
+
+ BrowserPolicyConnector* connector =
+ g_browser_process->browser_policy_connector();
+ schema_registry_.reset(new SchemaRegistryService(
+ connector->GetChromeSchema(), connector->GetSchemaRegistry()));
}
DeviceLocalAccountPolicyBroker::~DeviceLocalAccountPolicyBroker() {
+ store_->RemoveObserver(this);
external_data_manager_->SetPolicyStore(NULL);
external_data_manager_->Disconnect();
+ component_policy_service_.reset();
+ if (schema_registry_)
+ schema_registry_->Shutdown();
}
void DeviceLocalAccountPolicyBroker::Initialize() {
store_->Load();
}
+void DeviceLocalAccountPolicyBroker::OnSchemaRegistryShutdown() {
+ // Make sure the |component_policy_service_| isn't observing the
+ // SchemaRegistryService anymore.
+ component_policy_service_.reset();
+}
+
+scoped_ptr<SchemaRegistryService>
+DeviceLocalAccountPolicyBroker::release_schema_registry() {
+ return schema_registry_.Pass();
+}
+
void DeviceLocalAccountPolicyBroker::ConnectIfPossible(
chromeos::DeviceSettingsService* device_settings_service,
DeviceManagementService* device_management_service,
@@ -159,6 +188,7 @@ void DeviceLocalAccountPolicyBroker::ConnectIfPossible(
external_data_manager_->Connect(request_context);
core_.StartRefreshScheduler();
UpdateRefreshDelay();
+ CreateComponentCloudPolicyService(request_context);
}
void DeviceLocalAccountPolicyBroker::UpdateRefreshDelay() {
@@ -180,9 +210,42 @@ std::string DeviceLocalAccountPolicyBroker::GetDisplayName() const {
return display_name;
}
-base::FilePath DeviceLocalAccountPolicyBroker::GetComponentPolicyCachePath()
- const {
- return component_policy_cache_path_;
+void DeviceLocalAccountPolicyBroker::OnStoreLoaded(CloudPolicyStore* store) {
+ UpdateRefreshDelay();
+ policy_update_callback_.Run();
+}
+
+void DeviceLocalAccountPolicyBroker::OnStoreError(CloudPolicyStore* store) {
+ policy_update_callback_.Run();
+}
+
+void DeviceLocalAccountPolicyBroker::OnComponentCloudPolicyUpdated() {
+ policy_update_callback_.Run();
+}
+
+void DeviceLocalAccountPolicyBroker::CreateComponentCloudPolicyService(
+ const scoped_refptr<net::URLRequestContextGetter>& request_context) {
+ if (CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kDisableComponentCloudPolicy)) {
+ // Disabled via the command line.
+ return;
+ }
+
+ scoped_ptr<ResourceCache> resource_cache(
+ new ResourceCache(component_policy_cache_path_,
+ content::BrowserThread::GetMessageLoopProxyForThread(
+ content::BrowserThread::FILE)));
+
+ component_policy_service_.reset(new ComponentCloudPolicyService(
+ this,
+ schema_registry_.get(),
+ core(),
+ resource_cache.Pass(),
+ request_context,
+ content::BrowserThread::GetMessageLoopProxyForThread(
+ content::BrowserThread::FILE),
+ content::BrowserThread::GetMessageLoopProxyForThread(
+ content::BrowserThread::IO)));
}
DeviceLocalAccountPolicyService::DeviceLocalAccountPolicyService(
@@ -260,11 +323,6 @@ bool DeviceLocalAccountPolicyService::IsPolicyAvailableForUser(
return broker && broker->core()->store()->is_managed();
}
-scoped_refptr<net::URLRequestContextGetter>
-DeviceLocalAccountPolicyService::request_context() const {
- return request_context_;
-}
-
void DeviceLocalAccountPolicyService::AddObserver(Observer* observer) {
observers_.AddObserver(observer);
}
@@ -273,23 +331,6 @@ void DeviceLocalAccountPolicyService::RemoveObserver(Observer* observer) {
observers_.RemoveObserver(observer);
}
-void DeviceLocalAccountPolicyService::OnStoreLoaded(CloudPolicyStore* store) {
- DeviceLocalAccountPolicyBroker* broker = GetBrokerForStore(store);
- DCHECK(broker);
- if (!broker)
- return;
- broker->UpdateRefreshDelay();
- FOR_EACH_OBSERVER(Observer, observers_, OnPolicyUpdated(broker->user_id()));
-}
-
-void DeviceLocalAccountPolicyService::OnStoreError(CloudPolicyStore* store) {
- DeviceLocalAccountPolicyBroker* broker = GetBrokerForStore(store);
- DCHECK(broker);
- if (!broker)
- return;
- FOR_EACH_OBSERVER(Observer, observers_, OnPolicyUpdated(broker->user_id()));
-}
-
bool DeviceLocalAccountPolicyService::IsExtensionCacheDirectoryBusy(
const std::string& account_id) {
return busy_extension_cache_directories_.find(account_id) !=
@@ -417,7 +458,6 @@ void DeviceLocalAccountPolicyService::UpdateAccountList() {
session_manager_client_,
device_settings_service_,
store_background_task_runner_));
- store->AddObserver(this);
scoped_refptr<DeviceLocalAccountExternalDataManager>
external_data_manager =
external_data_service_->GetExternalDataManager(it->account_id,
@@ -427,6 +467,9 @@ void DeviceLocalAccountPolicyService::UpdateAccountList() {
component_policy_cache_root_.Append(EncodeAccountId(it->account_id)),
store.Pass(),
external_data_manager,
+ base::Bind(&DeviceLocalAccountPolicyService::NotifyPolicyUpdated,
+ base::Unretained(this),
bartfab (slow) 2014/06/20 09:44:23 Nit: #include "base/bind_helpers.h"
Joao da Silva 2014/06/20 15:36:07 Done.
+ it->user_id),
base::MessageLoopProxy::current()));
}
@@ -498,7 +541,6 @@ void DeviceLocalAccountPolicyService::UpdateAccountList() {
void DeviceLocalAccountPolicyService::DeleteBrokers(PolicyBrokerMap* map) {
for (PolicyBrokerMap::iterator it = map->begin(); it != map->end(); ++it) {
- it->second->core()->store()->RemoveObserver(this);
scoped_refptr<chromeos::DeviceLocalAccountExternalPolicyLoader>
extension_loader = it->second->extension_loader();
if (extension_loader->IsCacheRunning()) {
@@ -509,7 +551,7 @@ void DeviceLocalAccountPolicyService::DeleteBrokers(PolicyBrokerMap* map) {
weak_factory_.GetWeakPtr(),
it->second->account_id()));
}
- FOR_EACH_OBSERVER(Observer, observers_, OnBrokerShutdown(it->second));
+
delete it->second;
}
map->clear();
@@ -526,4 +568,9 @@ DeviceLocalAccountPolicyBroker*
return NULL;
}
+void DeviceLocalAccountPolicyService::NotifyPolicyUpdated(
+ const std::string& user_id) {
+ FOR_EACH_OBSERVER(Observer, observers_, OnPolicyUpdated(user_id));
+}
+
} // namespace policy

Powered by Google App Engine
This is Rietveld 408576698