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/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_invalidator.h" | |
12 #include "chrome/browser/policy/cloud/cloud_policy_refresh_scheduler.h" | |
11 #include "chrome/browser/policy/cloud/cloud_policy_service.h" | 13 #include "chrome/browser/policy/cloud/cloud_policy_service.h" |
12 #include "chrome/browser/policy/policy_bundle.h" | 14 #include "chrome/browser/policy/policy_bundle.h" |
13 #include "chrome/browser/policy/policy_map.h" | 15 #include "chrome/browser/policy/policy_map.h" |
14 | 16 |
15 namespace policy { | 17 namespace policy { |
16 | 18 |
17 CloudPolicyManager::CloudPolicyManager(const PolicyNamespaceKey& policy_ns_key, | 19 CloudPolicyManager::CloudPolicyManager(const PolicyNamespaceKey& policy_ns_key, |
18 CloudPolicyStore* cloud_policy_store) | 20 CloudPolicyStore* cloud_policy_store) |
19 : core_(policy_ns_key, cloud_policy_store), | 21 : core_(policy_ns_key, cloud_policy_store), |
20 waiting_for_policy_refresh_(false) { | 22 waiting_for_policy_refresh_(false) { |
21 store()->AddObserver(this); | 23 store()->AddObserver(this); |
22 | 24 |
23 // If the underlying store is already initialized, publish the loaded | 25 // If the underlying store is already initialized, publish the loaded |
24 // policy. Otherwise, request a load now. | 26 // policy. Otherwise, request a load now. |
25 if (store()->is_initialized()) | 27 if (store()->is_initialized()) |
26 CheckAndPublishPolicy(); | 28 CheckAndPublishPolicy(); |
27 else | 29 else |
28 store()->Load(); | 30 store()->Load(); |
29 } | 31 } |
30 | 32 |
31 CloudPolicyManager::~CloudPolicyManager() {} | 33 CloudPolicyManager::~CloudPolicyManager() {} |
32 | 34 |
33 void CloudPolicyManager::Shutdown() { | 35 void CloudPolicyManager::Shutdown() { |
36 invalidator_.reset(); | |
34 core_.Disconnect(); | 37 core_.Disconnect(); |
35 store()->RemoveObserver(this); | 38 store()->RemoveObserver(this); |
36 ConfigurationPolicyProvider::Shutdown(); | 39 ConfigurationPolicyProvider::Shutdown(); |
37 } | 40 } |
38 | 41 |
39 bool CloudPolicyManager::IsInitializationComplete(PolicyDomain domain) const { | 42 bool CloudPolicyManager::IsInitializationComplete(PolicyDomain domain) const { |
40 if (domain == POLICY_DOMAIN_CHROME) | 43 if (domain == POLICY_DOMAIN_CHROME) |
41 return store()->is_initialized(); | 44 return store()->is_initialized(); |
42 return true; | 45 return true; |
43 } | 46 } |
(...skipping 22 matching lines...) Expand all Loading... | |
66 CheckAndPublishPolicy(); | 69 CheckAndPublishPolicy(); |
67 } | 70 } |
68 | 71 |
69 void CloudPolicyManager::CheckAndPublishPolicy() { | 72 void CloudPolicyManager::CheckAndPublishPolicy() { |
70 if (IsInitializationComplete(POLICY_DOMAIN_CHROME) && | 73 if (IsInitializationComplete(POLICY_DOMAIN_CHROME) && |
71 !waiting_for_policy_refresh_) { | 74 !waiting_for_policy_refresh_) { |
72 UpdatePolicy(CreatePolicyBundle()); | 75 UpdatePolicy(CreatePolicyBundle()); |
73 } | 76 } |
74 } | 77 } |
75 | 78 |
79 void CloudPolicyManager::CreateInvalidator( | |
80 invalidation::InvalidationService* service) { | |
Joao da Silva
2013/07/23 20:44:47
You can check the command line flag here.
Also, s
Steve Condie
2013/07/24 01:42:04
Done.
| |
81 invalidator_.reset(new CloudPolicyInvalidator( | |
82 service, | |
83 client(), | |
84 store(), | |
85 base::MessageLoop::current()->message_loop_proxy(), | |
86 base::Bind( | |
87 &CloudPolicyRefreshScheduler::RefreshForInvalidation, | |
Joao da Silva
2013/07/23 20:44:47
CloudPolicyRefreshScheduler::RefreshSoon
Actually
Steve Condie
2013/07/24 01:42:04
Changed this so that instead of passing in a singl
| |
88 base::Unretained(core()->refresh_scheduler())))); | |
89 } | |
90 | |
91 void CloudPolicyManager::UnregisterInvalidator() { | |
92 if (invalidator_.get()) { | |
93 invalidator_->Unregister(); | |
94 invalidator_.reset(); | |
95 } | |
96 } | |
97 | |
76 scoped_ptr<PolicyBundle> CloudPolicyManager::CreatePolicyBundle() { | 98 scoped_ptr<PolicyBundle> CloudPolicyManager::CreatePolicyBundle() { |
77 scoped_ptr<PolicyBundle> bundle(new PolicyBundle); | 99 scoped_ptr<PolicyBundle> bundle(new PolicyBundle); |
78 bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) | 100 bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) |
79 .CopyFrom(store()->policy_map()); | 101 .CopyFrom(store()->policy_map()); |
80 return bundle.Pass(); | 102 return bundle.Pass(); |
81 } | 103 } |
82 | 104 |
83 void CloudPolicyManager::OnRefreshComplete(bool success) { | 105 void CloudPolicyManager::OnRefreshComplete(bool success) { |
84 waiting_for_policy_refresh_ = false; | 106 waiting_for_policy_refresh_ = false; |
85 CheckAndPublishPolicy(); | 107 CheckAndPublishPolicy(); |
86 } | 108 } |
87 | 109 |
88 } // namespace policy | 110 } // namespace policy |
OLD | NEW |