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) { | |
| 36 DCHECK(!initialize_invalidator.is_null()); | |
| 37 DCHECK(initialize_invalidator_.is_null()); | |
| 38 // If the refresh scheduler is already running, initialize the invalidator | |
| 39 // right away. Otherwise, store the closure so it can be invoked when the | |
| 40 // refresh scheduler starts. | |
| 41 if (core()->refresh_scheduler()) | |
| 42 initialize_invalidator.Run(); | |
| 43 else | |
| 44 initialize_invalidator_ = initialize_invalidator; | |
| 45 } | |
| 46 | |
| 33 void CloudPolicyManager::Shutdown() { | 47 void CloudPolicyManager::Shutdown() { |
| 34 core_.Disconnect(); | 48 core_.Disconnect(); |
| 35 store()->RemoveObserver(this); | 49 store()->RemoveObserver(this); |
| 36 ConfigurationPolicyProvider::Shutdown(); | 50 ConfigurationPolicyProvider::Shutdown(); |
| 37 } | 51 } |
| 38 | 52 |
| 39 bool CloudPolicyManager::IsInitializationComplete(PolicyDomain domain) const { | 53 bool CloudPolicyManager::IsInitializationComplete(PolicyDomain domain) const { |
| 40 if (domain == POLICY_DOMAIN_CHROME) | 54 if (domain == POLICY_DOMAIN_CHROME) |
| 41 return store()->is_initialized(); | 55 return store()->is_initialized(); |
| 42 return true; | 56 return true; |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 59 } | 73 } |
| 60 | 74 |
| 61 void CloudPolicyManager::OnStoreError(CloudPolicyStore* cloud_policy_store) { | 75 void CloudPolicyManager::OnStoreError(CloudPolicyStore* cloud_policy_store) { |
| 62 DCHECK_EQ(store(), cloud_policy_store); | 76 DCHECK_EQ(store(), cloud_policy_store); |
| 63 // Publish policy (even though it hasn't changed) in order to signal load | 77 // Publish policy (even though it hasn't changed) in order to signal load |
| 64 // complete on the ConfigurationPolicyProvider interface. Technically, this | 78 // complete on the ConfigurationPolicyProvider interface. Technically, this |
| 65 // is only required on the first load, but doesn't hurt in any case. | 79 // is only required on the first load, but doesn't hurt in any case. |
| 66 CheckAndPublishPolicy(); | 80 CheckAndPublishPolicy(); |
| 67 } | 81 } |
| 68 | 82 |
| 83 void CloudPolicyManager::SetInvalidationInfo( | |
| 84 int64 version, | |
| 85 const std::string& payload) { | |
| 86 DCHECK(core()->client()); | |
|
Mattias Nissler (ping if slow)
2013/08/28 14:20:40
This DCHECK is optimistic, in fact there are crash
| |
| 87 core()->client()->SetInvalidationInfo(version, payload); | |
| 88 } | |
| 89 | |
| 90 void CloudPolicyManager::InvalidatePolicy() { | |
| 91 DCHECK(core()->refresh_scheduler()); | |
|
Mattias Nissler (ping if slow)
2013/08/28 14:20:40
Same here.
| |
| 92 core()->refresh_scheduler()->RefreshSoon(); | |
| 93 } | |
| 94 | |
| 95 void CloudPolicyManager::OnInvalidatorStateChanged(bool invalidations_enabled) { | |
| 96 DCHECK(core()->refresh_scheduler()); | |
|
Mattias Nissler (ping if slow)
2013/08/28 14:20:40
and here.
| |
| 97 core()->refresh_scheduler()->SetInvalidationServiceAvailability( | |
| 98 invalidations_enabled); | |
| 99 } | |
| 100 | |
| 69 void CloudPolicyManager::CheckAndPublishPolicy() { | 101 void CloudPolicyManager::CheckAndPublishPolicy() { |
| 70 if (IsInitializationComplete(POLICY_DOMAIN_CHROME) && | 102 if (IsInitializationComplete(POLICY_DOMAIN_CHROME) && |
| 71 !waiting_for_policy_refresh_) { | 103 !waiting_for_policy_refresh_) { |
| 72 UpdatePolicy(CreatePolicyBundle()); | 104 UpdatePolicy(CreatePolicyBundle()); |
| 73 } | 105 } |
| 74 } | 106 } |
| 75 | 107 |
| 108 void CloudPolicyManager::StartRefreshScheduler() { | |
| 109 DCHECK(!core()->refresh_scheduler()); | |
| 110 core()->StartRefreshScheduler(); | |
| 111 // Initialize the invalidator if EnableInvalidations has been called. | |
| 112 if (!initialize_invalidator_.is_null()) | |
| 113 initialize_invalidator_.Run(); | |
| 114 } | |
| 115 | |
| 76 scoped_ptr<PolicyBundle> CloudPolicyManager::CreatePolicyBundle() { | 116 scoped_ptr<PolicyBundle> CloudPolicyManager::CreatePolicyBundle() { |
| 77 scoped_ptr<PolicyBundle> bundle(new PolicyBundle); | 117 scoped_ptr<PolicyBundle> bundle(new PolicyBundle); |
| 78 bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) | 118 bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) |
| 79 .CopyFrom(store()->policy_map()); | 119 .CopyFrom(store()->policy_map()); |
| 80 return bundle.Pass(); | 120 return bundle.Pass(); |
| 81 } | 121 } |
| 82 | 122 |
| 83 void CloudPolicyManager::OnRefreshComplete(bool success) { | 123 void CloudPolicyManager::OnRefreshComplete(bool success) { |
| 84 waiting_for_policy_refresh_ = false; | 124 waiting_for_policy_refresh_ = false; |
| 85 CheckAndPublishPolicy(); | 125 CheckAndPublishPolicy(); |
| 86 } | 126 } |
| 87 | 127 |
| 88 } // namespace policy | 128 } // namespace policy |
| OLD | NEW |