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

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) {
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 // 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
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 // Enable this code once method is added to CloudPolicyRefreshScheduler.
rlarocque 2013/07/29 18:29:54 nit: Add a TODO with your name on it.
Steve Condie 2013/07/29 18:53:07 The code in question got checked in, so these line
96 // core()->refresh_scheduler()->SetInvalidationServiceAvailability(
97 // invalidations_enabled);
98 }
99
69 void CloudPolicyManager::CheckAndPublishPolicy() { 100 void CloudPolicyManager::CheckAndPublishPolicy() {
70 if (IsInitializationComplete(POLICY_DOMAIN_CHROME) && 101 if (IsInitializationComplete(POLICY_DOMAIN_CHROME) &&
71 !waiting_for_policy_refresh_) { 102 !waiting_for_policy_refresh_) {
72 UpdatePolicy(CreatePolicyBundle()); 103 UpdatePolicy(CreatePolicyBundle());
73 } 104 }
74 } 105 }
75 106
107 void CloudPolicyManager::StartRefreshScheduler() {
108 DCHECK(!core()->refresh_scheduler());
109 core()->StartRefreshScheduler();
110 // Initialize the invalidator if EnableInvalidations has been called.
111 if (!initialize_invalidator_.is_null())
112 initialize_invalidator_.Run();
113 }
114
76 scoped_ptr<PolicyBundle> CloudPolicyManager::CreatePolicyBundle() { 115 scoped_ptr<PolicyBundle> CloudPolicyManager::CreatePolicyBundle() {
77 scoped_ptr<PolicyBundle> bundle(new PolicyBundle); 116 scoped_ptr<PolicyBundle> bundle(new PolicyBundle);
78 bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) 117 bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()))
79 .CopyFrom(store()->policy_map()); 118 .CopyFrom(store()->policy_map());
80 return bundle.Pass(); 119 return bundle.Pass();
81 } 120 }
82 121
83 void CloudPolicyManager::OnRefreshComplete(bool success) { 122 void CloudPolicyManager::OnRefreshComplete(bool success) {
84 waiting_for_policy_refresh_ = false; 123 waiting_for_policy_refresh_ = false;
85 CheckAndPublishPolicy(); 124 CheckAndPublishPolicy();
86 } 125 }
87 126
88 } // namespace policy 127 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/cloud/cloud_policy_manager.h ('k') | chrome/browser/policy/cloud/cloud_policy_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698