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

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" 11 #include "chrome/browser/policy/cloud/cloud_policy_refresh_scheduler.h"
12 #include "chrome/browser/policy/cloud/cloud_policy_service.h" 12 #include "chrome/browser/policy/cloud/cloud_policy_service.h"
13 #include "chrome/browser/policy/policy_bundle.h" 13 #include "chrome/browser/policy/policy_bundle.h"
14 #include "chrome/browser/policy/policy_map.h" 14 #include "chrome/browser/policy/policy_map.h"
15 15
16 namespace policy { 16 namespace policy {
17 17
18 CloudPolicyManager::CloudPolicyManager(const PolicyNamespaceKey& policy_ns_key, 18 CloudPolicyManager::CloudPolicyManager(const PolicyNamespaceKey& policy_ns_key,
19 CloudPolicyStore* cloud_policy_store) 19 CloudPolicyStore* cloud_policy_store)
20 : core_(policy_ns_key, cloud_policy_store), 20 : core_(policy_ns_key, cloud_policy_store),
21 waiting_for_policy_refresh_(false) { 21 waiting_for_policy_refresh_(false),
22 invalidator_started_(false) {
22 store()->AddObserver(this); 23 store()->AddObserver(this);
23 24
24 // If the underlying store is already initialized, publish the loaded 25 // If the underlying store is already initialized, publish the loaded
25 // policy. Otherwise, request a load now. 26 // policy. Otherwise, request a load now.
26 if (store()->is_initialized()) 27 if (store()->is_initialized())
27 CheckAndPublishPolicy(); 28 CheckAndPublishPolicy();
28 else 29 else
29 store()->Load(); 30 store()->Load();
30 } 31 }
31 32
32 CloudPolicyManager::~CloudPolicyManager() {} 33 CloudPolicyManager::~CloudPolicyManager() {}
33 34
34 void CloudPolicyManager::EnableInvalidations( 35 void CloudPolicyManager::SetInvalidator(
35 const base::Closure& initialize_invalidator) { 36 const base::WeakPtr<CloudPolicyInvalidator>& invalidator) {
36 DCHECK(!initialize_invalidator.is_null()); 37 DCHECK(invalidator);
37 DCHECK(initialize_invalidator_.is_null()); 38 invalidator_ = invalidator;
38 // If the refresh scheduler is already running, initialize the invalidator 39 // Start the invalidator if StartInvalidator was already called.
39 // right away. Otherwise, store the closure so it can be invoked when the 40 if (invalidator_started_)
40 // refresh scheduler starts. 41 invalidator_->Start();
41 if (core()->refresh_scheduler())
42 initialize_invalidator.Run();
43 else
44 initialize_invalidator_ = initialize_invalidator;
45 } 42 }
46 43
47 void CloudPolicyManager::Shutdown() { 44 void CloudPolicyManager::Shutdown() {
48 core_.Disconnect(); 45 core_.Disconnect();
49 store()->RemoveObserver(this); 46 store()->RemoveObserver(this);
50 ConfigurationPolicyProvider::Shutdown(); 47 ConfigurationPolicyProvider::Shutdown();
51 } 48 }
52 49
53 bool CloudPolicyManager::IsInitializationComplete(PolicyDomain domain) const { 50 bool CloudPolicyManager::IsInitializationComplete(PolicyDomain domain) const {
54 if (domain == POLICY_DOMAIN_CHROME) 51 if (domain == POLICY_DOMAIN_CHROME)
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 invalidations_enabled); 95 invalidations_enabled);
99 } 96 }
100 97
101 void CloudPolicyManager::CheckAndPublishPolicy() { 98 void CloudPolicyManager::CheckAndPublishPolicy() {
102 if (IsInitializationComplete(POLICY_DOMAIN_CHROME) && 99 if (IsInitializationComplete(POLICY_DOMAIN_CHROME) &&
103 !waiting_for_policy_refresh_) { 100 !waiting_for_policy_refresh_) {
104 UpdatePolicy(CreatePolicyBundle()); 101 UpdatePolicy(CreatePolicyBundle());
105 } 102 }
106 } 103 }
107 104
108 void CloudPolicyManager::StartRefreshScheduler() { 105 void CloudPolicyManager::StartInvalidator() {
109 DCHECK(!core()->refresh_scheduler()); 106 DCHECK(core()->refresh_scheduler());
110 core()->StartRefreshScheduler(); 107 invalidator_started_ = true;
111 // Initialize the invalidator if EnableInvalidations has been called. 108 CloudPolicyInvalidator* invalidator = invalidator_.get();
112 if (!initialize_invalidator_.is_null()) 109 if (invalidator)
113 initialize_invalidator_.Run(); 110 invalidator->Start();
111 }
112
113 void CloudPolicyManager::StopInvalidator() {
114 if (invalidator_started_) {
115 DCHECK(core()->refresh_scheduler());
116 invalidator_started_ = false;
117 CloudPolicyInvalidator* invalidator = invalidator_.get();
118 if (invalidator)
119 invalidator->Stop();
120 }
114 } 121 }
115 122
116 scoped_ptr<PolicyBundle> CloudPolicyManager::CreatePolicyBundle() { 123 scoped_ptr<PolicyBundle> CloudPolicyManager::CreatePolicyBundle() {
117 scoped_ptr<PolicyBundle> bundle(new PolicyBundle); 124 scoped_ptr<PolicyBundle> bundle(new PolicyBundle);
118 bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) 125 bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()))
119 .CopyFrom(store()->policy_map()); 126 .CopyFrom(store()->policy_map());
120 return bundle.Pass(); 127 return bundle.Pass();
121 } 128 }
122 129
123 void CloudPolicyManager::OnRefreshComplete(bool success) { 130 void CloudPolicyManager::OnRefreshComplete(bool success) {
124 waiting_for_policy_refresh_ = false; 131 waiting_for_policy_refresh_ = false;
125 CheckAndPublishPolicy(); 132 CheckAndPublishPolicy();
126 } 133 }
127 134
128 } // namespace policy 135 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698