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

Side by Side Diff: chrome/browser/policy/cloud_policy_provider.cc

Issue 11946017: Remove old cloud policy code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address nits. Created 7 years, 11 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/policy/cloud_policy_provider.h"
6
7 #include "base/memory/scoped_ptr.h"
8 #include "chrome/browser/policy/browser_policy_connector.h"
9 #include "chrome/browser/policy/policy_bundle.h"
10 #include "chrome/browser/policy/policy_map.h"
11
12 namespace policy {
13
14 CloudPolicyProvider::CloudPolicyProvider(BrowserPolicyConnector* connector)
15 : browser_policy_connector_(connector),
16 initialization_complete_(false) {
17 for (size_t i = 0; i < CACHE_SIZE; ++i)
18 caches_[i] = NULL;
19 }
20
21 CloudPolicyProvider::~CloudPolicyProvider() {}
22
23 void CloudPolicyProvider::SetUserPolicyCache(CloudPolicyCacheBase* cache) {
24 DCHECK(!caches_[CACHE_USER]);
25 caches_[CACHE_USER] = cache;
26 cache->AddObserver(this);
27 Merge();
28 }
29
30 #if defined(OS_CHROMEOS)
31 void CloudPolicyProvider::SetDevicePolicyCache(CloudPolicyCacheBase* cache) {
32 DCHECK(caches_[CACHE_DEVICE] == NULL);
33 caches_[CACHE_DEVICE] = cache;
34 cache->AddObserver(this);
35 Merge();
36 }
37 #endif
38
39 void CloudPolicyProvider::Shutdown() {
40 for (size_t i = 0; i < CACHE_SIZE; ++i) {
41 if (caches_[i]) {
42 caches_[i]->RemoveObserver(this);
43 caches_[i] = NULL;
44 }
45 }
46 ConfigurationPolicyProvider::Shutdown();
47 }
48
49 bool CloudPolicyProvider::IsInitializationComplete() const {
50 return initialization_complete_;
51 }
52
53 void CloudPolicyProvider::RefreshPolicies() {
54 for (size_t i = 0; i < CACHE_SIZE; ++i) {
55 if (caches_[i])
56 pending_updates_.insert(caches_[i]);
57 }
58 if (pending_updates_.empty())
59 Merge();
60 else
61 browser_policy_connector_->FetchCloudPolicy();
62 }
63
64 void CloudPolicyProvider::OnCacheUpdate(CloudPolicyCacheBase* cache) {
65 pending_updates_.erase(cache);
66 if (pending_updates_.empty())
67 Merge();
68 }
69
70 void CloudPolicyProvider::Merge() {
71 // Re-check whether all caches are ready.
72 if (!initialization_complete_) {
73 initialization_complete_ = true;
74 for (size_t i = 0; i < CACHE_SIZE; ++i) {
75 if (caches_[i] == NULL || !caches_[i]->IsReady()) {
76 initialization_complete_ = false;
77 break;
78 }
79 }
80 }
81
82 PolicyMap combined;
83 for (size_t i = 0; i < CACHE_SIZE; ++i) {
84 if (caches_[i] && caches_[i]->IsReady())
85 combined.MergeFrom(*caches_[i]->policy());
86 }
87
88 scoped_ptr<PolicyBundle> bundle(new PolicyBundle());
89 bundle->Get(POLICY_DOMAIN_CHROME, std::string()).Swap(&combined);
90 UpdatePolicy(bundle.Pass());
91 }
92
93 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/cloud_policy_provider.h ('k') | chrome/browser/policy/cloud_policy_provider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698