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

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

Issue 12189011: Split up chrome/browser/policy subdirectory (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase, add chrome/browser/chromeos/policy/OWNERS Created 7 years, 9 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_manager.h"
6
7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
9 #include "base/logging.h"
10 #include "base/prefs/pref_service.h"
11 #include "chrome/browser/policy/cloud_policy_service.h"
12 #include "chrome/browser/policy/policy_bundle.h"
13 #include "chrome/browser/policy/policy_map.h"
14
15 namespace policy {
16
17 CloudPolicyManager::CloudPolicyManager(const PolicyNamespaceKey& policy_ns_key,
18 CloudPolicyStore* cloud_policy_store)
19 : core_(policy_ns_key, cloud_policy_store),
20 waiting_for_policy_refresh_(false) {
21 store()->AddObserver(this);
22
23 // If the underlying store is already initialized, publish the loaded
24 // policy. Otherwise, request a load now.
25 if (store()->is_initialized())
26 CheckAndPublishPolicy();
27 else
28 store()->Load();
29 }
30
31 CloudPolicyManager::~CloudPolicyManager() {}
32
33 void CloudPolicyManager::Shutdown() {
34 core_.Disconnect();
35 store()->RemoveObserver(this);
36 ConfigurationPolicyProvider::Shutdown();
37 }
38
39 bool CloudPolicyManager::IsInitializationComplete(PolicyDomain domain) const {
40 if (domain == POLICY_DOMAIN_CHROME)
41 return store()->is_initialized();
42 return true;
43 }
44
45 void CloudPolicyManager::RefreshPolicies() {
46 if (service()) {
47 waiting_for_policy_refresh_ = true;
48 service()->RefreshPolicy(
49 base::Bind(&CloudPolicyManager::OnRefreshComplete,
50 base::Unretained(this)));
51 } else {
52 OnRefreshComplete(false);
53 }
54 }
55
56 void CloudPolicyManager::OnStoreLoaded(CloudPolicyStore* cloud_policy_store) {
57 DCHECK_EQ(store(), cloud_policy_store);
58 CheckAndPublishPolicy();
59 }
60
61 void CloudPolicyManager::OnStoreError(CloudPolicyStore* cloud_policy_store) {
62 DCHECK_EQ(store(), cloud_policy_store);
63 // Publish policy (even though it hasn't changed) in order to signal load
64 // complete on the ConfigurationPolicyProvider interface. Technically, this
65 // is only required on the first load, but doesn't hurt in any case.
66 CheckAndPublishPolicy();
67 }
68
69 void CloudPolicyManager::CheckAndPublishPolicy() {
70 if (IsInitializationComplete(POLICY_DOMAIN_CHROME) &&
71 !waiting_for_policy_refresh_) {
72 UpdatePolicy(CreatePolicyBundle());
73 }
74 }
75
76 scoped_ptr<PolicyBundle> CloudPolicyManager::CreatePolicyBundle() {
77 scoped_ptr<PolicyBundle> bundle(new PolicyBundle);
78 bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()))
79 .CopyFrom(store()->policy_map());
80 return bundle.Pass();
81 }
82
83 void CloudPolicyManager::OnRefreshComplete(bool success) {
84 waiting_for_policy_refresh_ = false;
85 CheckAndPublishPolicy();
86 }
87
88 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/cloud_policy_manager.h ('k') | chrome/browser/policy/cloud_policy_manager_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698