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

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

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

Powered by Google App Engine
This is Rietveld 408576698