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/command_line.h" | |
9 #include "base/logging.h" | 10 #include "base/logging.h" |
10 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
12 #include "chrome/browser/policy/cloud/cloud_policy_invalidator.h" | |
13 #include "chrome/browser/policy/cloud/cloud_policy_refresh_scheduler.h" | |
11 #include "chrome/browser/policy/cloud/cloud_policy_service.h" | 14 #include "chrome/browser/policy/cloud/cloud_policy_service.h" |
12 #include "chrome/browser/policy/policy_bundle.h" | 15 #include "chrome/browser/policy/policy_bundle.h" |
13 #include "chrome/browser/policy/policy_map.h" | 16 #include "chrome/browser/policy/policy_map.h" |
17 #include "chrome/common/chrome_switches.h" | |
14 | 18 |
15 namespace policy { | 19 namespace policy { |
16 | 20 |
17 CloudPolicyManager::CloudPolicyManager(const PolicyNamespaceKey& policy_ns_key, | 21 CloudPolicyManager::CloudPolicyManager(const PolicyNamespaceKey& policy_ns_key, |
18 CloudPolicyStore* cloud_policy_store) | 22 CloudPolicyStore* cloud_policy_store) |
19 : core_(policy_ns_key, cloud_policy_store), | 23 : core_(policy_ns_key, cloud_policy_store), |
20 waiting_for_policy_refresh_(false) { | 24 waiting_for_policy_refresh_(false) { |
21 store()->AddObserver(this); | 25 store()->AddObserver(this); |
22 | 26 |
23 // If the underlying store is already initialized, publish the loaded | 27 // If the underlying store is already initialized, publish the loaded |
24 // policy. Otherwise, request a load now. | 28 // policy. Otherwise, request a load now. |
25 if (store()->is_initialized()) | 29 if (store()->is_initialized()) |
26 CheckAndPublishPolicy(); | 30 CheckAndPublishPolicy(); |
27 else | 31 else |
28 store()->Load(); | 32 store()->Load(); |
29 } | 33 } |
30 | 34 |
31 CloudPolicyManager::~CloudPolicyManager() {} | 35 CloudPolicyManager::~CloudPolicyManager() {} |
32 | 36 |
33 void CloudPolicyManager::Shutdown() { | 37 void CloudPolicyManager::Shutdown() { |
38 invalidator_.reset(); | |
34 core_.Disconnect(); | 39 core_.Disconnect(); |
35 store()->RemoveObserver(this); | 40 store()->RemoveObserver(this); |
36 ConfigurationPolicyProvider::Shutdown(); | 41 ConfigurationPolicyProvider::Shutdown(); |
37 } | 42 } |
38 | 43 |
39 bool CloudPolicyManager::IsInitializationComplete(PolicyDomain domain) const { | 44 bool CloudPolicyManager::IsInitializationComplete(PolicyDomain domain) const { |
40 if (domain == POLICY_DOMAIN_CHROME) | 45 if (domain == POLICY_DOMAIN_CHROME) |
41 return store()->is_initialized(); | 46 return store()->is_initialized(); |
42 return true; | 47 return true; |
43 } | 48 } |
(...skipping 15 matching lines...) Expand all Loading... | |
59 } | 64 } |
60 | 65 |
61 void CloudPolicyManager::OnStoreError(CloudPolicyStore* cloud_policy_store) { | 66 void CloudPolicyManager::OnStoreError(CloudPolicyStore* cloud_policy_store) { |
62 DCHECK_EQ(store(), cloud_policy_store); | 67 DCHECK_EQ(store(), cloud_policy_store); |
63 // Publish policy (even though it hasn't changed) in order to signal load | 68 // Publish policy (even though it hasn't changed) in order to signal load |
64 // complete on the ConfigurationPolicyProvider interface. Technically, this | 69 // complete on the ConfigurationPolicyProvider interface. Technically, this |
65 // is only required on the first load, but doesn't hurt in any case. | 70 // is only required on the first load, but doesn't hurt in any case. |
66 CheckAndPublishPolicy(); | 71 CheckAndPublishPolicy(); |
67 } | 72 } |
68 | 73 |
74 void CloudPolicyManager::InvalidatePolicy() { | |
75 DCHECK(core()->refresh_scheduler()); | |
76 core()->refresh_scheduler()->RefreshSoon(); | |
77 } | |
78 | |
79 void CloudPolicyManager::OnInvalidatorStateChanged(bool invalidations_enabled) { | |
80 DCHECK(core()->refresh_scheduler()); | |
81 // Enable this code once method is added to CloudPolicyRefreshScheduler. | |
82 // core()->refresh_scheduler()->SetInvalidationServiceAvailability( | |
83 // invalidations_enabled); | |
84 } | |
85 | |
69 void CloudPolicyManager::CheckAndPublishPolicy() { | 86 void CloudPolicyManager::CheckAndPublishPolicy() { |
70 if (IsInitializationComplete(POLICY_DOMAIN_CHROME) && | 87 if (IsInitializationComplete(POLICY_DOMAIN_CHROME) && |
71 !waiting_for_policy_refresh_) { | 88 !waiting_for_policy_refresh_) { |
72 UpdatePolicy(CreatePolicyBundle()); | 89 UpdatePolicy(CreatePolicyBundle()); |
73 } | 90 } |
74 } | 91 } |
75 | 92 |
93 void CloudPolicyManager::CreateInvalidator( | |
94 invalidation::InvalidationService* service, | |
95 bool ignore_switch) { | |
96 DCHECK(core()->refresh_scheduler()); | |
97 #if defined(OS_ANDROID) // Allow invalidations on Android regardless of switch. | |
98 ignore_switch = true; | |
99 #endif | |
100 if (ignore_switch || CommandLine::ForCurrentProcess()->HasSwitch( | |
101 switches::kEnableCloudPolicyPush)) { | |
102 invalidator_.reset(new CloudPolicyInvalidator( | |
103 service, | |
104 client(), | |
105 store(), | |
106 base::MessageLoop::current()->message_loop_proxy(), | |
107 this /* invalidation_handler */)); | |
108 } | |
109 } | |
110 | |
111 void CloudPolicyManager::UnregisterInvalidator() { | |
112 if (invalidator_.get()) { | |
Joao da Silva
2013/07/24 15:34:07
.get() not needed to test scoped_ptrs
Steve Condie
2013/07/25 01:18:08
This function is now removed anyway.
| |
113 invalidator_->Unregister(); | |
114 invalidator_.reset(); | |
115 } | |
116 } | |
117 | |
76 scoped_ptr<PolicyBundle> CloudPolicyManager::CreatePolicyBundle() { | 118 scoped_ptr<PolicyBundle> CloudPolicyManager::CreatePolicyBundle() { |
77 scoped_ptr<PolicyBundle> bundle(new PolicyBundle); | 119 scoped_ptr<PolicyBundle> bundle(new PolicyBundle); |
78 bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) | 120 bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) |
79 .CopyFrom(store()->policy_map()); | 121 .CopyFrom(store()->policy_map()); |
80 return bundle.Pass(); | 122 return bundle.Pass(); |
81 } | 123 } |
82 | 124 |
83 void CloudPolicyManager::OnRefreshComplete(bool success) { | 125 void CloudPolicyManager::OnRefreshComplete(bool success) { |
84 waiting_for_policy_refresh_ = false; | 126 waiting_for_policy_refresh_ = false; |
85 CheckAndPublishPolicy(); | 127 CheckAndPublishPolicy(); |
86 } | 128 } |
87 | 129 |
88 } // namespace policy | 130 } // namespace policy |
OLD | NEW |