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

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

Issue 10919131: Break out base functionality of UserCloudPolicyManager. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 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 "chrome/browser/policy/cloud_policy_refresh_scheduler.h"
11 #include "chrome/browser/policy/cloud_policy_service.h"
12 #include "chrome/browser/policy/device_management_service.h"
Joao da Silva 2012/09/07 12:44:13 nit: not used
Mattias Nissler (ping if slow) 2012/09/07 13:12:59 Done.
13 #include "chrome/browser/policy/policy_bundle.h"
14 #include "chrome/browser/policy/policy_map.h"
15
16 namespace policy {
17
18 CloudPolicyManager::CloudPolicyManager(scoped_ptr<CloudPolicyStore> store)
19 : store_(store.Pass()),
20 waiting_for_policy_refresh_(false) {
21 store_->Load();
22 store_->AddObserver(this);
Joao da Silva 2012/09/07 12:44:13 Swap the order of these 2, since this assumes Load
Mattias Nissler (ping if slow) 2012/09/07 13:12:59 Done.
23 }
24
25 CloudPolicyManager::~CloudPolicyManager() {
26 ShutdownService();
27 store_->RemoveObserver(this);
28 }
29
30 bool CloudPolicyManager::IsInitializationComplete() const {
31 return store_->is_initialized();
32 }
33
34 void CloudPolicyManager::RefreshPolicies() {
35 if (service_.get()) {
36 waiting_for_policy_refresh_ = true;
37 service_->RefreshPolicy(
38 base::Bind(&CloudPolicyManager::OnRefreshComplete,
39 base::Unretained(this)));
40 } else {
41 OnRefreshComplete();
42 }
43 }
44
45 void CloudPolicyManager::OnStoreLoaded(CloudPolicyStore* store) {
46 DCHECK_EQ(store_.get(), store);
47 CheckAndPublishPolicy();
48 }
49
50 void CloudPolicyManager::OnStoreError(CloudPolicyStore* store) {
51 DCHECK_EQ(store_.get(), store);
52 // No action required, the old policy is still valid.
53 }
54
55 void CloudPolicyManager::InitializeService(
56 scoped_ptr<CloudPolicyClient> client) {
57 CHECK(!client_.get());
58 CHECK(client.get());
59 client_ = client.Pass();
60 service_.reset(new CloudPolicyService(client_.get(), store_.get()));
61 }
62
63 void CloudPolicyManager::ShutdownService() {
64 refresh_scheduler_.reset();
65 service_.reset();
66 client_.reset();
67 }
68
69 void CloudPolicyManager::StartRefreshScheduler(
70 PrefService* local_state,
71 const std::string& refresh_rate_pref) {
72 if (!refresh_scheduler_.get()) {
73 refresh_scheduler_.reset(
74 new CloudPolicyRefreshScheduler(
75 client_.get(), store_.get(), local_state, refresh_rate_pref,
76 MessageLoop::current()->message_loop_proxy()));
77 }
78 }
79
80 void CloudPolicyManager::CheckAndPublishPolicy() {
81 if (IsInitializationComplete() && !waiting_for_policy_refresh_) {
82 scoped_ptr<PolicyBundle> bundle(new PolicyBundle());
83 bundle->Get(POLICY_DOMAIN_CHROME, std::string()).CopyFrom(
84 store_->policy_map());
85 UpdatePolicy(bundle.Pass());
86 }
87 }
88
89 void CloudPolicyManager::OnRefreshComplete() {
90 waiting_for_policy_refresh_ = false;
91 CheckAndPublishPolicy();
92 }
93
94 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698