Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/policy/cloud/cloud_policy_manager.h" | 5 #include "chrome/browser/policy/cloud/cloud_policy_manager.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| 11 #include "chrome/browser/policy/cloud/cloud_policy_refresh_scheduler.h" | |
| 11 #include "chrome/browser/policy/cloud/cloud_policy_service.h" | 12 #include "chrome/browser/policy/cloud/cloud_policy_service.h" |
| 12 #include "chrome/browser/policy/policy_bundle.h" | 13 #include "chrome/browser/policy/policy_bundle.h" |
| 13 #include "chrome/browser/policy/policy_map.h" | 14 #include "chrome/browser/policy/policy_map.h" |
| 14 | 15 |
| 15 namespace policy { | 16 namespace policy { |
| 16 | 17 |
| 17 CloudPolicyManager::CloudPolicyManager(const PolicyNamespaceKey& policy_ns_key, | 18 CloudPolicyManager::CloudPolicyManager(const PolicyNamespaceKey& policy_ns_key, |
| 18 CloudPolicyStore* cloud_policy_store) | 19 CloudPolicyStore* cloud_policy_store) |
| 19 : core_(policy_ns_key, cloud_policy_store), | 20 : core_(policy_ns_key, cloud_policy_store), |
| 20 waiting_for_policy_refresh_(false) { | 21 waiting_for_policy_refresh_(false) { |
| 21 store()->AddObserver(this); | 22 store()->AddObserver(this); |
| 22 | 23 |
| 23 // If the underlying store is already initialized, publish the loaded | 24 // If the underlying store is already initialized, publish the loaded |
| 24 // policy. Otherwise, request a load now. | 25 // policy. Otherwise, request a load now. |
| 25 if (store()->is_initialized()) | 26 if (store()->is_initialized()) |
| 26 CheckAndPublishPolicy(); | 27 CheckAndPublishPolicy(); |
| 27 else | 28 else |
| 28 store()->Load(); | 29 store()->Load(); |
| 29 } | 30 } |
| 30 | 31 |
| 31 CloudPolicyManager::~CloudPolicyManager() {} | 32 CloudPolicyManager::~CloudPolicyManager() {} |
| 32 | 33 |
| 34 void CloudPolicyManager::EnableInvalidations( | |
| 35 const base::Closure& initialize_invalidator) { | |
|
Joao da Silva
2013/07/29 19:44:32
DCHECK(!initialize_invalidator.is_null());
DCHECK(
Steve Condie
2013/07/29 20:44:51
Done.
| |
| 36 // If the refresh scheduler is already running, initialize the invalidator | |
| 37 // right away. Otherwise, store the closure so it can be invoked when the | |
| 38 // refresh scheduler starts. | |
| 39 if (core()->refresh_scheduler()) | |
| 40 initialize_invalidator.Run(); | |
| 41 else | |
| 42 initialize_invalidator_ = initialize_invalidator; | |
| 43 } | |
| 44 | |
| 33 void CloudPolicyManager::Shutdown() { | 45 void CloudPolicyManager::Shutdown() { |
| 34 core_.Disconnect(); | 46 core_.Disconnect(); |
| 35 store()->RemoveObserver(this); | 47 store()->RemoveObserver(this); |
| 36 ConfigurationPolicyProvider::Shutdown(); | 48 ConfigurationPolicyProvider::Shutdown(); |
| 37 } | 49 } |
| 38 | 50 |
| 39 bool CloudPolicyManager::IsInitializationComplete(PolicyDomain domain) const { | 51 bool CloudPolicyManager::IsInitializationComplete(PolicyDomain domain) const { |
| 40 if (domain == POLICY_DOMAIN_CHROME) | 52 if (domain == POLICY_DOMAIN_CHROME) |
| 41 return store()->is_initialized(); | 53 return store()->is_initialized(); |
| 42 return true; | 54 return true; |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 59 } | 71 } |
| 60 | 72 |
| 61 void CloudPolicyManager::OnStoreError(CloudPolicyStore* cloud_policy_store) { | 73 void CloudPolicyManager::OnStoreError(CloudPolicyStore* cloud_policy_store) { |
| 62 DCHECK_EQ(store(), cloud_policy_store); | 74 DCHECK_EQ(store(), cloud_policy_store); |
| 63 // Publish policy (even though it hasn't changed) in order to signal load | 75 // Publish policy (even though it hasn't changed) in order to signal load |
| 64 // complete on the ConfigurationPolicyProvider interface. Technically, this | 76 // complete on the ConfigurationPolicyProvider interface. Technically, this |
| 65 // is only required on the first load, but doesn't hurt in any case. | 77 // is only required on the first load, but doesn't hurt in any case. |
| 66 CheckAndPublishPolicy(); | 78 CheckAndPublishPolicy(); |
| 67 } | 79 } |
| 68 | 80 |
| 81 void CloudPolicyManager::SetInvalidationInfo( | |
| 82 int64 version, | |
| 83 const std::string& payload) { | |
| 84 DCHECK(core()->client()); | |
| 85 core()->client()->SetInvalidationInfo(version, payload); | |
| 86 } | |
| 87 | |
| 88 void CloudPolicyManager::InvalidatePolicy() { | |
| 89 DCHECK(core()->refresh_scheduler()); | |
| 90 core()->refresh_scheduler()->RefreshSoon(); | |
| 91 } | |
| 92 | |
| 93 void CloudPolicyManager::OnInvalidatorStateChanged(bool invalidations_enabled) { | |
| 94 DCHECK(core()->refresh_scheduler()); | |
| 95 core()->refresh_scheduler()->SetInvalidationServiceAvailability( | |
| 96 invalidations_enabled); | |
| 97 } | |
| 98 | |
| 69 void CloudPolicyManager::CheckAndPublishPolicy() { | 99 void CloudPolicyManager::CheckAndPublishPolicy() { |
| 70 if (IsInitializationComplete(POLICY_DOMAIN_CHROME) && | 100 if (IsInitializationComplete(POLICY_DOMAIN_CHROME) && |
| 71 !waiting_for_policy_refresh_) { | 101 !waiting_for_policy_refresh_) { |
| 72 UpdatePolicy(CreatePolicyBundle()); | 102 UpdatePolicy(CreatePolicyBundle()); |
| 73 } | 103 } |
| 74 } | 104 } |
| 75 | 105 |
| 106 void CloudPolicyManager::StartRefreshScheduler() { | |
| 107 DCHECK(!core()->refresh_scheduler()); | |
| 108 core()->StartRefreshScheduler(); | |
| 109 // Initialize the invalidator if EnableInvalidations has been called. | |
| 110 if (!initialize_invalidator_.is_null()) | |
| 111 initialize_invalidator_.Run(); | |
| 112 } | |
| 113 | |
| 76 scoped_ptr<PolicyBundle> CloudPolicyManager::CreatePolicyBundle() { | 114 scoped_ptr<PolicyBundle> CloudPolicyManager::CreatePolicyBundle() { |
| 77 scoped_ptr<PolicyBundle> bundle(new PolicyBundle); | 115 scoped_ptr<PolicyBundle> bundle(new PolicyBundle); |
| 78 bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) | 116 bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) |
| 79 .CopyFrom(store()->policy_map()); | 117 .CopyFrom(store()->policy_map()); |
| 80 return bundle.Pass(); | 118 return bundle.Pass(); |
| 81 } | 119 } |
| 82 | 120 |
| 83 void CloudPolicyManager::OnRefreshComplete(bool success) { | 121 void CloudPolicyManager::OnRefreshComplete(bool success) { |
| 84 waiting_for_policy_refresh_ = false; | 122 waiting_for_policy_refresh_ = false; |
| 85 CheckAndPublishPolicy(); | 123 CheckAndPublishPolicy(); |
| 86 } | 124 } |
| 87 | 125 |
| 88 } // namespace policy | 126 } // namespace policy |
| OLD | NEW |