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

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

Issue 11415094: Split UserCloudPolicyManager implementation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Bring back ProxyPolicyProvider, fix local_state policy provider, fix Joao's fine CloudPolicyTest. 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/user_cloud_policy_manager.h" 5 #include "chrome/browser/policy/user_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 "chrome/browser/policy/cloud_policy_service.h" 9 #include "chrome/browser/policy/cloud_policy_service.h"
10 #include "chrome/browser/policy/policy_types.h" 10 #include "chrome/browser/policy/policy_types.h"
11 #include "chrome/browser/policy/user_cloud_policy_store.h"
11 #include "chrome/common/pref_names.h" 12 #include "chrome/common/pref_names.h"
12 13
13 namespace policy { 14 namespace policy {
14 15
15 UserCloudPolicyManager::UserCloudPolicyManager( 16 UserCloudPolicyManager::UserCloudPolicyManager(
16 scoped_ptr<CloudPolicyStore> store, 17 scoped_ptr<UserCloudPolicyStore> store)
17 bool wait_for_policy_fetch) 18 : CloudPolicyManager(store.get()),
18 : CloudPolicyManager(store.Pass()), 19 store_(store.Pass()) {}
19 wait_for_policy_fetch_(wait_for_policy_fetch) {}
20 20
21 UserCloudPolicyManager::~UserCloudPolicyManager() {} 21 UserCloudPolicyManager::~UserCloudPolicyManager() {}
22 22
23 // static
24 scoped_ptr<UserCloudPolicyManager> UserCloudPolicyManager::Create(
25 Profile* profile,
26 PolicyInit policy_init) {
27 scoped_ptr<CloudPolicyStore> store =
28 CloudPolicyStore::CreateUserPolicyStore(
29 profile, policy_init == POLICY_INIT_IMMEDIATELY);
30 return make_scoped_ptr(new UserCloudPolicyManager(
31 store.Pass(), policy_init == POLICY_INIT_REFRESH_FROM_SERVER));
32 }
33
34 void UserCloudPolicyManager::Initialize( 23 void UserCloudPolicyManager::Initialize(
35 PrefService* local_state, 24 PrefService* local_state,
36 DeviceManagementService* device_management_service, 25 DeviceManagementService* device_management_service) {
37 UserAffiliation user_affiliation) { 26 InitializeService(
38 DCHECK(device_management_service); 27 make_scoped_ptr(new CloudPolicyClient(std::string(), std::string(),
39 DCHECK(local_state); 28 USER_AFFILIATION_NONE,
40 local_state_ = local_state; 29 POLICY_SCOPE_USER, NULL,
41 scoped_ptr<CloudPolicyClient> client( 30 device_management_service)));
42 new CloudPolicyClient(std::string(), std::string(), user_affiliation, 31 StartRefreshScheduler(local_state, prefs::kUserPolicyRefreshRate);
43 POLICY_SCOPE_USER, NULL,
44 device_management_service));
45 InitializeService(client.Pass());
46 cloud_policy_client()->AddObserver(this);
47
48 if (wait_for_policy_fetch_) {
49 // If we are supposed to wait for a policy fetch, we trigger an explicit
50 // policy refresh at startup that allows us to unblock initialization once
51 // done. The refresh scheduler only gets started once that refresh
52 // completes. Note that we might have to wait for registration to happen,
53 // see OnRegistrationStateChanged() below.
54 if (cloud_policy_client()->is_registered()) {
55 cloud_policy_service()->RefreshPolicy(
56 base::Bind(&UserCloudPolicyManager::OnInitialPolicyFetchComplete,
57 base::Unretained(this)));
58 }
59 } else {
60 CancelWaitForPolicyFetch();
61 }
62 } 32 }
63 33
64 void UserCloudPolicyManager::ShutdownAndRemovePolicy() { 34 void UserCloudPolicyManager::ShutdownAndRemovePolicy() {
65 if (cloud_policy_client())
66 cloud_policy_client()->RemoveObserver(this);
67 ShutdownService(); 35 ShutdownService();
68 local_state_ = NULL; 36 store_->Clear();
69 cloud_policy_store()->Clear();
70 }
71
72 void UserCloudPolicyManager::CancelWaitForPolicyFetch() {
73 wait_for_policy_fetch_ = false;
74 CheckAndPublishPolicy();
75
76 // Now that |wait_for_policy_fetch_| is guaranteed to be false, the scheduler
77 // can be started.
78 if (cloud_policy_service() && local_state_)
79 StartRefreshScheduler(local_state_, prefs::kUserPolicyRefreshRate);
80 } 37 }
81 38
82 bool UserCloudPolicyManager::IsClientRegistered() const { 39 bool UserCloudPolicyManager::IsClientRegistered() const {
83 return cloud_policy_client() && cloud_policy_client()->is_registered(); 40 return cloud_policy_client() && cloud_policy_client()->is_registered();
84 } 41 }
85 42
86 void UserCloudPolicyManager::RegisterClient(const std::string& access_token) { 43 void UserCloudPolicyManager::RegisterClient(const std::string& access_token) {
87 DCHECK(cloud_policy_client()) << "Callers must invoke Initialize() first"; 44 DCHECK(cloud_policy_client()) << "Callers must invoke Initialize() first";
88 if (!cloud_policy_client()->is_registered()) { 45 if (!cloud_policy_client()->is_registered()) {
89 DVLOG(1) << "Registering client with access token: " << access_token; 46 DVLOG(1) << "Registering client with access token: " << access_token;
90 cloud_policy_client()->Register(access_token); 47 cloud_policy_client()->Register(access_token);
91 } 48 }
92 } 49 }
93 50
94 void UserCloudPolicyManager::Shutdown() {
95 if (cloud_policy_client())
96 cloud_policy_client()->RemoveObserver(this);
97 CloudPolicyManager::Shutdown();
98 }
99
100 bool UserCloudPolicyManager::IsInitializationComplete() const {
101 return CloudPolicyManager::IsInitializationComplete() &&
102 !wait_for_policy_fetch_;
103 }
104
105 void UserCloudPolicyManager::OnPolicyFetched(CloudPolicyClient* client) {
106 // No action required. If we're blocked on a policy fetch, we'll learn about
107 // completion of it through OnInitialPolicyFetchComplete().
108 }
109
110 void UserCloudPolicyManager::OnRegistrationStateChanged(
111 CloudPolicyClient* client) {
112 DCHECK_EQ(cloud_policy_client(), client);
113 if (wait_for_policy_fetch_) {
114 // If we're blocked on the policy fetch, now is a good time to issue it.
115 if (cloud_policy_client()->is_registered()) {
116 cloud_policy_service()->RefreshPolicy(
117 base::Bind(&UserCloudPolicyManager::OnInitialPolicyFetchComplete,
118 base::Unretained(this)));
119 } else {
120 // If the client has switched to not registered, we bail out as this
121 // indicates the cloud policy setup flow has been aborted.
122 CancelWaitForPolicyFetch();
123 }
124 }
125 }
126
127 void UserCloudPolicyManager::OnClientError(CloudPolicyClient* client) {
128 DCHECK_EQ(cloud_policy_client(), client);
129 CancelWaitForPolicyFetch();
130 }
131
132 void UserCloudPolicyManager::OnInitialPolicyFetchComplete() {
133 CancelWaitForPolicyFetch();
134 }
135
136 } // namespace policy 51 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698