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

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

Issue 23592017: Fix policy invalidator lifecycle bugs for Android. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 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 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"
12 #include "chrome/browser/policy/cloud/cloud_policy_service.h" 11 #include "chrome/browser/policy/cloud/cloud_policy_service.h"
13 #include "chrome/browser/policy/policy_bundle.h" 12 #include "chrome/browser/policy/policy_bundle.h"
14 #include "chrome/browser/policy/policy_map.h" 13 #include "chrome/browser/policy/policy_map.h"
15 14
16 namespace policy { 15 namespace policy {
17 16
18 CloudPolicyManager::CloudPolicyManager(const PolicyNamespaceKey& policy_ns_key, 17 CloudPolicyManager::CloudPolicyManager(const PolicyNamespaceKey& policy_ns_key,
19 CloudPolicyStore* cloud_policy_store) 18 CloudPolicyStore* cloud_policy_store)
20 : core_(policy_ns_key, cloud_policy_store), 19 : core_(policy_ns_key, cloud_policy_store),
21 waiting_for_policy_refresh_(false) { 20 waiting_for_policy_refresh_(false) {
22 store()->AddObserver(this); 21 store()->AddObserver(this);
23 22
24 // If the underlying store is already initialized, publish the loaded 23 // If the underlying store is already initialized, publish the loaded
25 // policy. Otherwise, request a load now. 24 // policy. Otherwise, request a load now.
26 if (store()->is_initialized()) 25 if (store()->is_initialized())
27 CheckAndPublishPolicy(); 26 CheckAndPublishPolicy();
28 else 27 else
29 store()->Load(); 28 store()->Load();
30 } 29 }
31 30
32 CloudPolicyManager::~CloudPolicyManager() {} 31 CloudPolicyManager::~CloudPolicyManager() {}
33 32
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
47 void CloudPolicyManager::Shutdown() { 33 void CloudPolicyManager::Shutdown() {
48 core_.Disconnect(); 34 core_.Disconnect();
49 store()->RemoveObserver(this); 35 store()->RemoveObserver(this);
50 ConfigurationPolicyProvider::Shutdown(); 36 ConfigurationPolicyProvider::Shutdown();
51 } 37 }
52 38
53 bool CloudPolicyManager::IsInitializationComplete(PolicyDomain domain) const { 39 bool CloudPolicyManager::IsInitializationComplete(PolicyDomain domain) const {
54 if (domain == POLICY_DOMAIN_CHROME) 40 if (domain == POLICY_DOMAIN_CHROME)
55 return store()->is_initialized(); 41 return store()->is_initialized();
56 return true; 42 return true;
(...skipping 16 matching lines...) Expand all
73 } 59 }
74 60
75 void CloudPolicyManager::OnStoreError(CloudPolicyStore* cloud_policy_store) { 61 void CloudPolicyManager::OnStoreError(CloudPolicyStore* cloud_policy_store) {
76 DCHECK_EQ(store(), cloud_policy_store); 62 DCHECK_EQ(store(), cloud_policy_store);
77 // Publish policy (even though it hasn't changed) in order to signal load 63 // Publish policy (even though it hasn't changed) in order to signal load
78 // complete on the ConfigurationPolicyProvider interface. Technically, this 64 // complete on the ConfigurationPolicyProvider interface. Technically, this
79 // is only required on the first load, but doesn't hurt in any case. 65 // is only required on the first load, but doesn't hurt in any case.
80 CheckAndPublishPolicy(); 66 CheckAndPublishPolicy();
81 } 67 }
82 68
83 void CloudPolicyManager::SetInvalidationInfo(
84 int64 version,
85 const std::string& payload) {
86 DCHECK(core()->client());
87 core()->client()->SetInvalidationInfo(version, payload);
88 }
89
90 void CloudPolicyManager::InvalidatePolicy() {
91 DCHECK(core()->refresh_scheduler());
92 core()->refresh_scheduler()->RefreshSoon();
93 }
94
95 void CloudPolicyManager::OnInvalidatorStateChanged(bool invalidations_enabled) {
96 DCHECK(core()->refresh_scheduler());
97 core()->refresh_scheduler()->SetInvalidationServiceAvailability(
98 invalidations_enabled);
99 }
100
101 void CloudPolicyManager::CheckAndPublishPolicy() { 69 void CloudPolicyManager::CheckAndPublishPolicy() {
102 if (IsInitializationComplete(POLICY_DOMAIN_CHROME) && 70 if (IsInitializationComplete(POLICY_DOMAIN_CHROME) &&
103 !waiting_for_policy_refresh_) { 71 !waiting_for_policy_refresh_) {
104 UpdatePolicy(CreatePolicyBundle()); 72 UpdatePolicy(CreatePolicyBundle());
105 } 73 }
106 } 74 }
107 75
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
116 scoped_ptr<PolicyBundle> CloudPolicyManager::CreatePolicyBundle() { 76 scoped_ptr<PolicyBundle> CloudPolicyManager::CreatePolicyBundle() {
117 scoped_ptr<PolicyBundle> bundle(new PolicyBundle); 77 scoped_ptr<PolicyBundle> bundle(new PolicyBundle);
118 bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) 78 bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()))
119 .CopyFrom(store()->policy_map()); 79 .CopyFrom(store()->policy_map());
120 return bundle.Pass(); 80 return bundle.Pass();
121 } 81 }
122 82
123 void CloudPolicyManager::OnRefreshComplete(bool success) { 83 void CloudPolicyManager::OnRefreshComplete(bool success) {
124 waiting_for_policy_refresh_ = false; 84 waiting_for_policy_refresh_ = false;
125 CheckAndPublishPolicy(); 85 CheckAndPublishPolicy();
126 } 86 }
127 87
128 } // namespace policy 88 } // 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