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

Unified Diff: chrome/browser/policy/user_cloud_policy_manager.cc

Issue 10919131: Break out base functionality of UserCloudPolicyManager. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 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/policy/user_cloud_policy_manager.cc
diff --git a/chrome/browser/policy/user_cloud_policy_manager.cc b/chrome/browser/policy/user_cloud_policy_manager.cc
index 3572ad4657694c3cacb795b23509632bb2ced1d0..3b8866af2bc9da3bbb136534851e08bd5655e384 100644
--- a/chrome/browser/policy/user_cloud_policy_manager.cc
+++ b/chrome/browser/policy/user_cloud_policy_manager.cc
@@ -44,16 +44,12 @@ const FilePath::CharType kPolicyCacheFile[] = FILE_PATH_LITERAL("Policy");
UserCloudPolicyManager::UserCloudPolicyManager(
scoped_ptr<CloudPolicyStore> store,
bool wait_for_policy_fetch)
- : wait_for_policy_fetch_(wait_for_policy_fetch),
- wait_for_policy_refresh_(false),
- store_(store.Pass()) {
- store_->Load();
- store_->AddObserver(this);
-}
+ : CloudPolicyManager(store.Pass()),
+ wait_for_policy_fetch_(wait_for_policy_fetch) {}
UserCloudPolicyManager::~UserCloudPolicyManager() {
- Shutdown();
- store_->RemoveObserver(this);
+ if (cloud_policy_client())
+ cloud_policy_client()->RemoveObserver(this);
}
// static
@@ -66,18 +62,19 @@ scoped_ptr<UserCloudPolicyManager> UserCloudPolicyManager::Create(
new UserCloudPolicyManager(store.Pass(), wait_for_policy_fetch));
}
-void UserCloudPolicyManager::Initialize(PrefService* prefs,
- DeviceManagementService* service,
- UserAffiliation user_affiliation) {
- DCHECK(service);
- DCHECK(prefs);
- DCHECK(!service_.get());
- prefs_ = prefs;
+void UserCloudPolicyManager::Initialize(
+ PrefService* local_state,
+ DeviceManagementService* device_management_service,
+ UserAffiliation user_affiliation) {
+ DCHECK(device_management_service);
+ DCHECK(local_state);
+ local_state_ = local_state;
scoped_ptr<CloudPolicyClient> client(
new CloudPolicyClient(std::string(), std::string(), user_affiliation,
- POLICY_SCOPE_USER, NULL, service));
- service_.reset(new CloudPolicyService(client.Pass(), store_.get()));
- service_->client()->AddObserver(this);
+ POLICY_SCOPE_USER, NULL,
+ device_management_service));
+ InitializeService(client.Pass());
+ cloud_policy_client()->AddObserver(this);
if (wait_for_policy_fetch_) {
// If we are supposed to wait for a policy fetch, we trigger an explicit
@@ -85,8 +82,8 @@ void UserCloudPolicyManager::Initialize(PrefService* prefs,
// done. The refresh scheduler only gets started once that refresh
// completes. Note that we might have to wait for registration to happen,
// see OnRegistrationStateChanged() below.
- if (service_->client()->is_registered()) {
- service_->RefreshPolicy(
+ if (cloud_policy_client()->is_registered()) {
+ cloud_policy_service()->RefreshPolicy(
base::Bind(&UserCloudPolicyManager::OnInitialPolicyFetchComplete,
base::Unretained(this)));
}
@@ -96,8 +93,11 @@ void UserCloudPolicyManager::Initialize(PrefService* prefs,
}
void UserCloudPolicyManager::ShutdownAndRemovePolicy() {
- Shutdown();
- store_->Clear();
+ if (cloud_policy_client())
+ cloud_policy_client()->RemoveObserver(this);
+ ShutdownService();
+ local_state_ = NULL;
+ cloud_policy_store()->Clear();
}
void UserCloudPolicyManager::CancelWaitForPolicyFetch() {
@@ -106,42 +106,27 @@ void UserCloudPolicyManager::CancelWaitForPolicyFetch() {
// Now that |wait_for_policy_fetch_| is guaranteed to be false, the scheduler
// can be started.
- if (service_.get() && !refresh_scheduler_.get() && prefs_) {
- refresh_scheduler_.reset(
- new CloudPolicyRefreshScheduler(
- service_->client(), store_.get(), prefs_,
- prefs::kUserPolicyRefreshRate,
- MessageLoop::current()->message_loop_proxy()));
- }
+ if (cloud_policy_service() && local_state_)
+ StartRefreshScheduler(local_state_, prefs::kUserPolicyRefreshRate);
}
bool UserCloudPolicyManager::IsClientRegistered() const {
- if (!service_.get())
+ if (!cloud_policy_service())
return false;
- return service_->client()->is_registered();
+ return cloud_policy_client()->is_registered();
Joao da Silva 2012/09/07 12:44:13 The first line should test cloud_policy_client().
Mattias Nissler (ping if slow) 2012/09/07 13:12:59 Done.
}
void UserCloudPolicyManager::RegisterClient(const std::string& access_token) {
DCHECK(cloud_policy_service()) << "Callers must invoke Initialize() first";
Joao da Silva 2012/09/07 12:44:13 DCHECK(cloud_policy_client())
Mattias Nissler (ping if slow) 2012/09/07 13:12:59 Done.
- if (!cloud_policy_service()->client()->is_registered()) {
+ if (!cloud_policy_client()->is_registered()) {
DVLOG(1) << "Registering client with access token: " << access_token;
- cloud_policy_service()->client()->Register(access_token);
+ cloud_policy_client()->Register(access_token);
}
}
bool UserCloudPolicyManager::IsInitializationComplete() const {
- return store_->is_initialized() && !wait_for_policy_fetch_;
-}
-
-void UserCloudPolicyManager::RefreshPolicies() {
- if (service_.get()) {
- wait_for_policy_refresh_ = true;
- service_->RefreshPolicy(
- base::Bind(&UserCloudPolicyManager::OnRefreshComplete,
- base::Unretained(this)));
- } else {
- OnRefreshComplete();
- }
+ return CloudPolicyManager::IsInitializationComplete() &&
+ !wait_for_policy_fetch_;
}
void UserCloudPolicyManager::OnPolicyFetched(CloudPolicyClient* client) {
@@ -153,8 +138,8 @@ void UserCloudPolicyManager::OnRegistrationStateChanged(
CloudPolicyClient* client) {
Joao da Silva 2012/09/07 12:44:13 DCHECK_EQ(cloud_policy_client(), client) ?
Mattias Nissler (ping if slow) 2012/09/07 13:12:59 Done.
if (wait_for_policy_fetch_) {
// If we're blocked on the policy fetch, now is a good time to issue it.
- if (service_->client()->is_registered()) {
- service_->RefreshPolicy(
+ if (cloud_policy_client()->is_registered()) {
+ cloud_policy_service()->RefreshPolicy(
base::Bind(&UserCloudPolicyManager::OnInitialPolicyFetchComplete,
base::Unretained(this)));
} else {
@@ -169,38 +154,8 @@ void UserCloudPolicyManager::OnClientError(CloudPolicyClient* client) {
CancelWaitForPolicyFetch();
}
-void UserCloudPolicyManager::CheckAndPublishPolicy() {
- if (IsInitializationComplete() && !wait_for_policy_refresh_) {
- scoped_ptr<PolicyBundle> bundle(new PolicyBundle());
- bundle->Get(POLICY_DOMAIN_CHROME, std::string()).CopyFrom(
- store_->policy_map());
- UpdatePolicy(bundle.Pass());
- }
-}
-
-void UserCloudPolicyManager::OnStoreLoaded(CloudPolicyStore* store) {
- CheckAndPublishPolicy();
-}
-
-void UserCloudPolicyManager::OnStoreError(CloudPolicyStore* store) {
- // No action required, the old policy is still valid.
-}
-
void UserCloudPolicyManager::OnInitialPolicyFetchComplete() {
CancelWaitForPolicyFetch();
}
-void UserCloudPolicyManager::OnRefreshComplete() {
- wait_for_policy_refresh_ = false;
- CheckAndPublishPolicy();
-}
-
-void UserCloudPolicyManager::Shutdown() {
- refresh_scheduler_.reset();
- if (service_.get())
- service_->client()->RemoveObserver(this);
- service_.reset();
- prefs_ = NULL;
-}
-
} // namespace policy

Powered by Google App Engine
This is Rietveld 408576698