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

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

Issue 11415094: Split UserCloudPolicyManager implementation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix DeviceCloudPolicyManagerChromeOSTest.EnrolledDevice failure. Created 8 years 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
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_policy_manager.h" 5 #include "chrome/browser/policy/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 "chrome/browser/policy/cloud_policy_refresh_scheduler.h" 10 #include "chrome/browser/policy/cloud_policy_refresh_scheduler.h"
11 #include "chrome/browser/policy/cloud_policy_service.h" 11 #include "chrome/browser/policy/cloud_policy_service.h"
12 #include "chrome/browser/policy/policy_bundle.h" 12 #include "chrome/browser/policy/policy_bundle.h"
13 #include "chrome/browser/policy/policy_map.h" 13 #include "chrome/browser/policy/policy_map.h"
14 14
15 namespace policy { 15 namespace policy {
16 16
17 CloudPolicyManager::CloudPolicyManager(scoped_ptr<CloudPolicyStore> store) 17 CloudPolicyManager::CloudPolicyManager(CloudPolicyStore* store)
18 : store_(store.Pass()), 18 : store_(store),
19 waiting_for_policy_refresh_(false) { 19 waiting_for_policy_refresh_(false) {
20 store_->AddObserver(this); 20 store_->AddObserver(this);
21 21
22 // If the underlying store is already initialized, publish the loaded 22 // If the underlying store is already initialized, publish the loaded
23 // policy. Otherwise, request a load now. 23 // policy. Otherwise, request a load now.
24 if (store_->is_initialized()) 24 if (store_->is_initialized())
25 CheckAndPublishPolicy(); 25 CheckAndPublishPolicy();
26 else 26 else
27 store_->Load(); 27 store_->Load();
28 } 28 }
29 29
30 CloudPolicyManager::~CloudPolicyManager() {} 30 CloudPolicyManager::~CloudPolicyManager() {
31 DCHECK(!store_) << "Shutdown() must be called before destruction!";
32 }
31 33
32 void CloudPolicyManager::Shutdown() { 34 void CloudPolicyManager::Shutdown() {
33 ShutdownService(); 35 ShutdownService();
34 store_->RemoveObserver(this); 36 if (store_)
37 store_->RemoveObserver(this);
35 ConfigurationPolicyProvider::Shutdown(); 38 ConfigurationPolicyProvider::Shutdown();
39 store_ = NULL;
36 } 40 }
37 41
38 bool CloudPolicyManager::IsInitializationComplete() const { 42 bool CloudPolicyManager::IsInitializationComplete() const {
39 return store_->is_initialized(); 43 return store_->is_initialized();
40 } 44 }
41 45
42 void CloudPolicyManager::RefreshPolicies() { 46 void CloudPolicyManager::RefreshPolicies() {
43 if (service_.get()) { 47 if (service_.get()) {
44 waiting_for_policy_refresh_ = true; 48 waiting_for_policy_refresh_ = true;
45 service_->RefreshPolicy( 49 service_->RefreshPolicy(
46 base::Bind(&CloudPolicyManager::OnRefreshComplete, 50 base::Bind(&CloudPolicyManager::OnRefreshComplete,
47 base::Unretained(this))); 51 base::Unretained(this)));
48 } else { 52 } else {
49 OnRefreshComplete(); 53 OnRefreshComplete();
50 } 54 }
51 } 55 }
52 56
53 void CloudPolicyManager::OnStoreLoaded(CloudPolicyStore* store) { 57 void CloudPolicyManager::OnStoreLoaded(CloudPolicyStore* store) {
54 DCHECK_EQ(store_.get(), store); 58 DCHECK_EQ(store_, store);
55 CheckAndPublishPolicy(); 59 CheckAndPublishPolicy();
56 } 60 }
57 61
58 void CloudPolicyManager::OnStoreError(CloudPolicyStore* store) { 62 void CloudPolicyManager::OnStoreError(CloudPolicyStore* store) {
59 DCHECK_EQ(store_.get(), store); 63 DCHECK_EQ(store_, store);
60 // No action required, the old policy is still valid. 64 // No action required, the old policy is still valid.
61 } 65 }
62 66
63 void CloudPolicyManager::InitializeService( 67 void CloudPolicyManager::InitializeService(
64 scoped_ptr<CloudPolicyClient> client) { 68 scoped_ptr<CloudPolicyClient> client) {
65 CHECK(!client_.get()); 69 CHECK(!client_.get());
66 CHECK(client.get()); 70 CHECK(client.get());
67 client_ = client.Pass(); 71 client_ = client.Pass();
68 service_.reset(new CloudPolicyService(client_.get(), store_.get())); 72 service_.reset(new CloudPolicyService(client_.get(), store_));
69 } 73 }
70 74
71 void CloudPolicyManager::ShutdownService() { 75 void CloudPolicyManager::ShutdownService() {
72 refresh_scheduler_.reset(); 76 refresh_scheduler_.reset();
73 service_.reset(); 77 service_.reset();
74 client_.reset(); 78 client_.reset();
75 } 79 }
76 80
77 void CloudPolicyManager::StartRefreshScheduler( 81 void CloudPolicyManager::StartRefreshScheduler(
78 PrefService* local_state, 82 PrefService* local_state,
79 const std::string& refresh_rate_pref) { 83 const std::string& refresh_rate_pref) {
80 if (!refresh_scheduler_.get()) { 84 if (!refresh_scheduler_.get()) {
81 refresh_scheduler_.reset( 85 refresh_scheduler_.reset(
82 new CloudPolicyRefreshScheduler( 86 new CloudPolicyRefreshScheduler(
83 client_.get(), store_.get(), local_state, refresh_rate_pref, 87 client_.get(), store_, local_state, refresh_rate_pref,
84 MessageLoop::current()->message_loop_proxy())); 88 MessageLoop::current()->message_loop_proxy()));
85 } 89 }
86 } 90 }
87 91
88 void CloudPolicyManager::CheckAndPublishPolicy() { 92 void CloudPolicyManager::CheckAndPublishPolicy() {
89 if (IsInitializationComplete() && !waiting_for_policy_refresh_) { 93 if (IsInitializationComplete() && !waiting_for_policy_refresh_) {
90 scoped_ptr<PolicyBundle> bundle(new PolicyBundle()); 94 scoped_ptr<PolicyBundle> bundle(new PolicyBundle());
91 bundle->Get(POLICY_DOMAIN_CHROME, std::string()).CopyFrom( 95 bundle->Get(POLICY_DOMAIN_CHROME, std::string()).CopyFrom(
92 store_->policy_map()); 96 store_->policy_map());
93 UpdatePolicy(bundle.Pass()); 97 UpdatePolicy(bundle.Pass());
94 } 98 }
95 } 99 }
96 100
97 void CloudPolicyManager::OnRefreshComplete() { 101 void CloudPolicyManager::OnRefreshComplete() {
98 waiting_for_policy_refresh_ = false; 102 waiting_for_policy_refresh_ = false;
99 CheckAndPublishPolicy(); 103 CheckAndPublishPolicy();
100 } 104 }
101 105
102 } // namespace policy 106 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/cloud_policy_manager.h ('k') | chrome/browser/policy/cloud_policy_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698