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

Side by Side Diff: chrome/browser/policy/cloud/cloud_policy_manager.cc

Issue 19733003: Implement cloud policy invalidations using the invalidation service framework. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 5 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 unified diff | Download patch
OLDNEW
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) {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 } 60 }
60 61
61 void CloudPolicyManager::OnStoreError(CloudPolicyStore* cloud_policy_store) { 62 void CloudPolicyManager::OnStoreError(CloudPolicyStore* cloud_policy_store) {
62 DCHECK_EQ(store(), cloud_policy_store); 63 DCHECK_EQ(store(), cloud_policy_store);
63 // Publish policy (even though it hasn't changed) in order to signal load 64 // Publish policy (even though it hasn't changed) in order to signal load
64 // complete on the ConfigurationPolicyProvider interface. Technically, this 65 // complete on the ConfigurationPolicyProvider interface. Technically, this
65 // is only required on the first load, but doesn't hurt in any case. 66 // is only required on the first load, but doesn't hurt in any case.
66 CheckAndPublishPolicy(); 67 CheckAndPublishPolicy();
67 } 68 }
68 69
70 void CloudPolicyManager::SetInvalidationInfo(
71 int64 version,
72 const std::string& payload) {
73 if (!core()->refresh_scheduler()) {
74 invalidation_replayer_.SetInvalidationInfo(version, payload);
75 return;
76 }
77 DCHECK(core()->client());
78 core()->client()->SetInvalidationInfo(version, payload);
79 }
80
81 void CloudPolicyManager::InvalidatePolicy() {
82 if (!core()->refresh_scheduler()) {
83 invalidation_replayer_.InvalidatePolicy();
84 return;
85 }
86 core()->refresh_scheduler()->RefreshSoon();
87 }
88
89 void CloudPolicyManager::OnInvalidatorStateChanged(bool invalidations_enabled) {
90 if (!core()->refresh_scheduler()) {
91 invalidation_replayer_.OnInvalidatorStateChanged(invalidations_enabled);
92 return;
93 }
94 // Enable this code once method is added to CloudPolicyRefreshScheduler.
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 invalidation_replayer_.Replay(this);
110 }
111
76 scoped_ptr<PolicyBundle> CloudPolicyManager::CreatePolicyBundle() { 112 scoped_ptr<PolicyBundle> CloudPolicyManager::CreatePolicyBundle() {
77 scoped_ptr<PolicyBundle> bundle(new PolicyBundle); 113 scoped_ptr<PolicyBundle> bundle(new PolicyBundle);
78 bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) 114 bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()))
79 .CopyFrom(store()->policy_map()); 115 .CopyFrom(store()->policy_map());
80 return bundle.Pass(); 116 return bundle.Pass();
81 } 117 }
82 118
83 void CloudPolicyManager::OnRefreshComplete(bool success) { 119 void CloudPolicyManager::OnRefreshComplete(bool success) {
84 waiting_for_policy_refresh_ = false; 120 waiting_for_policy_refresh_ = false;
85 CheckAndPublishPolicy(); 121 CheckAndPublishPolicy();
86 } 122 }
87 123
88 } // namespace policy 124 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698