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

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

Issue 23271009: Add UMA stats for initial user policy fetch on Chrome OS. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase. Created 7 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
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/chromeos/policy/user_cloud_policy_manager_chromeos.h" 5 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.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 "base/message_loop/message_loop_proxy.h" 10 #include "base/message_loop/message_loop_proxy.h"
11 #include "base/metrics/histogram.h"
12 #include "base/metrics/sparse_histogram.h"
11 #include "chrome/browser/browser_process.h" 13 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/chromeos/policy/policy_oauth2_token_fetcher.h" 14 #include "chrome/browser/chromeos/policy/policy_oauth2_token_fetcher.h"
13 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chrom eos.h" 15 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chrom eos.h"
14 #include "chrome/browser/chromeos/profiles/profile_helper.h" 16 #include "chrome/browser/chromeos/profiles/profile_helper.h"
15 #include "chrome/browser/policy/cloud/cloud_policy_refresh_scheduler.h" 17 #include "chrome/browser/policy/cloud/cloud_policy_refresh_scheduler.h"
16 #include "chrome/browser/policy/cloud/resource_cache.h" 18 #include "chrome/browser/policy/cloud/resource_cache.h"
17 #include "chrome/browser/policy/policy_bundle.h" 19 #include "chrome/browser/policy/policy_bundle.h"
18 #include "chrome/browser/policy/policy_domain_descriptor.h" 20 #include "chrome/browser/policy/policy_domain_descriptor.h"
19 #include "chrome/common/pref_names.h" 21 #include "chrome/common/pref_names.h"
20 #include "content/public/browser/browser_thread.h" 22 #include "content/public/browser/browser_thread.h"
21 #include "net/url_request/url_request_context_getter.h" 23 #include "net/url_request/url_request_context_getter.h"
22 24
23 namespace em = enterprise_management; 25 namespace em = enterprise_management;
24 26
25 namespace policy { 27 namespace policy {
26 28
29 namespace {
30
31 // UMA histogram names.
32 const char kUMADelayInitialization[] =
33 "Enterprise.UserPolicyChromeOS.DelayInitialization";
34 const char kUMAInitialFetchClientError[] =
35 "Enterprise.UserPolicyChromeOS.InitialFetch.ClientError";
36 const char kUMAInitialFetchDelayClientRegister[] =
37 "Enterprise.UserPolicyChromeOS.InitialFetch.DelayClientRegister";
38 const char kUMAInitialFetchDelayOAuth2Token[] =
39 "Enterprise.UserPolicyChromeOS.InitialFetch.DelayOAuth2Token";
40 const char kUMAInitialFetchDelayPolicyFetch[] =
41 "Enterprise.UserPolicyChromeOS.InitialFetch.DelayPolicyFetch";
42 const char kUMAInitialFetchDelayTotal[] =
43 "Enterprise.UserPolicyChromeOS.InitialFetch.DelayTotal";
44 const char kUMAInitialFetchOAuth2Error[] =
45 "Enterprise.UserPolicyChromeOS.InitialFetch.OAuth2Error";
46 const char kUMAInitialFetchOAuth2NetworkError[] =
47 "Enterprise.UserPolicyChromeOS.InitialFetch.OAuth2NetworkError";
48
49 } // namespace
50
27 UserCloudPolicyManagerChromeOS::UserCloudPolicyManagerChromeOS( 51 UserCloudPolicyManagerChromeOS::UserCloudPolicyManagerChromeOS(
28 scoped_ptr<CloudPolicyStore> store, 52 scoped_ptr<CloudPolicyStore> store,
29 scoped_ptr<ResourceCache> resource_cache, 53 scoped_ptr<ResourceCache> resource_cache,
30 bool wait_for_policy_fetch) 54 bool wait_for_policy_fetch)
31 : CloudPolicyManager( 55 : CloudPolicyManager(
32 PolicyNamespaceKey(dm_protocol::kChromeUserPolicyType, std::string()), 56 PolicyNamespaceKey(dm_protocol::kChromeUserPolicyType, std::string()),
33 store.get()), 57 store.get()),
34 store_(store.Pass()), 58 store_(store.Pass()),
35 wait_for_policy_fetch_(wait_for_policy_fetch) { 59 wait_for_policy_fetch_(wait_for_policy_fetch) {
60 time_init_started_ = base::Time::Now();
36 if (resource_cache) { 61 if (resource_cache) {
37 // TODO(joaodasilva): Move the backend from the FILE thread to the blocking 62 // TODO(joaodasilva): Move the backend from the FILE thread to the blocking
38 // pool. 63 // pool.
39 component_policy_service_.reset(new ComponentCloudPolicyService( 64 component_policy_service_.reset(new ComponentCloudPolicyService(
40 this, 65 this,
41 store_.get(), 66 store_.get(),
42 resource_cache.Pass(), 67 resource_cache.Pass(),
43 content::BrowserThread::GetMessageLoopProxyForThread( 68 content::BrowserThread::GetMessageLoopProxyForThread(
44 content::BrowserThread::FILE), 69 content::BrowserThread::FILE),
45 content::BrowserThread::GetMessageLoopProxyForThread( 70 content::BrowserThread::GetMessageLoopProxyForThread(
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 scoped_ptr<PolicyBundle> bundle = CloudPolicyManager::CreatePolicyBundle(); 148 scoped_ptr<PolicyBundle> bundle = CloudPolicyManager::CreatePolicyBundle();
124 if (component_policy_service_) 149 if (component_policy_service_)
125 bundle->MergeFrom(component_policy_service_->policy()); 150 bundle->MergeFrom(component_policy_service_->policy());
126 return bundle.Pass(); 151 return bundle.Pass();
127 } 152 }
128 153
129 void UserCloudPolicyManagerChromeOS::OnInitializationCompleted( 154 void UserCloudPolicyManagerChromeOS::OnInitializationCompleted(
130 CloudPolicyService* cloud_policy_service) { 155 CloudPolicyService* cloud_policy_service) {
131 DCHECK_EQ(service(), cloud_policy_service); 156 DCHECK_EQ(service(), cloud_policy_service);
132 cloud_policy_service->RemoveObserver(this); 157 cloud_policy_service->RemoveObserver(this);
158
159 time_init_completed_ = base::Time::Now();
160 UMA_HISTOGRAM_TIMES(kUMADelayInitialization,
161 time_init_completed_ - time_init_started_);
162
133 // If the CloudPolicyClient isn't registered at this stage then it needs an 163 // If the CloudPolicyClient isn't registered at this stage then it needs an
134 // OAuth token for the initial registration. 164 // OAuth token for the initial registration.
135 // 165 //
136 // If |wait_for_policy_fetch_| is true then Profile initialization is blocking 166 // If |wait_for_policy_fetch_| is true then Profile initialization is blocking
137 // on the initial policy fetch, so the token must be fetched immediately. 167 // on the initial policy fetch, so the token must be fetched immediately.
138 // In that case, the signin Profile is used to authenticate a Gaia request to 168 // In that case, the signin Profile is used to authenticate a Gaia request to
139 // fetch a refresh token, and then the policy token is fetched. 169 // fetch a refresh token, and then the policy token is fetched.
140 // 170 //
141 // If |wait_for_policy_fetch_| is false then the UserCloudPolicyTokenForwarder 171 // If |wait_for_policy_fetch_| is false then the UserCloudPolicyTokenForwarder
142 // service will eventually call OnAccessTokenAvailable() once an access token 172 // service will eventually call OnAccessTokenAvailable() once an access token
(...skipping 21 matching lines...) Expand all
164 194
165 void UserCloudPolicyManagerChromeOS::OnPolicyFetched( 195 void UserCloudPolicyManagerChromeOS::OnPolicyFetched(
166 CloudPolicyClient* client) { 196 CloudPolicyClient* client) {
167 // No action required. If we're blocked on a policy fetch, we'll learn about 197 // No action required. If we're blocked on a policy fetch, we'll learn about
168 // completion of it through OnInitialPolicyFetchComplete(). 198 // completion of it through OnInitialPolicyFetchComplete().
169 } 199 }
170 200
171 void UserCloudPolicyManagerChromeOS::OnRegistrationStateChanged( 201 void UserCloudPolicyManagerChromeOS::OnRegistrationStateChanged(
172 CloudPolicyClient* cloud_policy_client) { 202 CloudPolicyClient* cloud_policy_client) {
173 DCHECK_EQ(client(), cloud_policy_client); 203 DCHECK_EQ(client(), cloud_policy_client);
204
174 if (wait_for_policy_fetch_) { 205 if (wait_for_policy_fetch_) {
206 time_client_registered_ = base::Time::Now();
207 if (!time_token_available_.is_null()) {
208 UMA_HISTOGRAM_TIMES(kUMAInitialFetchDelayClientRegister,
209 time_client_registered_ - time_token_available_);
210 }
211
175 // If we're blocked on the policy fetch, now is a good time to issue it. 212 // If we're blocked on the policy fetch, now is a good time to issue it.
176 if (client()->is_registered()) { 213 if (client()->is_registered()) {
177 service()->RefreshPolicy( 214 service()->RefreshPolicy(
178 base::Bind( 215 base::Bind(
179 &UserCloudPolicyManagerChromeOS::OnInitialPolicyFetchComplete, 216 &UserCloudPolicyManagerChromeOS::OnInitialPolicyFetchComplete,
180 base::Unretained(this))); 217 base::Unretained(this)));
181 } else { 218 } else {
182 // If the client has switched to not registered, we bail out as this 219 // If the client has switched to not registered, we bail out as this
183 // indicates the cloud policy setup flow has been aborted. 220 // indicates the cloud policy setup flow has been aborted.
184 CancelWaitForPolicyFetch(); 221 CancelWaitForPolicyFetch();
185 } 222 }
186 } 223 }
187 } 224 }
188 225
189 void UserCloudPolicyManagerChromeOS::OnClientError( 226 void UserCloudPolicyManagerChromeOS::OnClientError(
190 CloudPolicyClient* cloud_policy_client) { 227 CloudPolicyClient* cloud_policy_client) {
191 DCHECK_EQ(client(), cloud_policy_client); 228 DCHECK_EQ(client(), cloud_policy_client);
192 CancelWaitForPolicyFetch(); 229 CancelWaitForPolicyFetch();
230
231 if (wait_for_policy_fetch_) {
232 UMA_HISTOGRAM_SPARSE_SLOWLY(kUMAInitialFetchClientError,
233 cloud_policy_client->status());
234 }
193 } 235 }
194 236
195 void UserCloudPolicyManagerChromeOS::OnComponentCloudPolicyRefreshNeeded() { 237 void UserCloudPolicyManagerChromeOS::OnComponentCloudPolicyRefreshNeeded() {
196 core()->RefreshSoon(); 238 core()->RefreshSoon();
197 } 239 }
198 240
199 void UserCloudPolicyManagerChromeOS::OnComponentCloudPolicyUpdated() { 241 void UserCloudPolicyManagerChromeOS::OnComponentCloudPolicyUpdated() {
200 CheckAndPublishPolicy(); 242 CheckAndPublishPolicy();
201 StartRefreshSchedulerIfReady(); 243 StartRefreshSchedulerIfReady();
202 } 244 }
(...skipping 15 matching lines...) Expand all
218 g_browser_process->system_request_context(), 260 g_browser_process->system_request_context(),
219 base::Bind(&UserCloudPolicyManagerChromeOS::OnOAuth2PolicyTokenFetched, 261 base::Bind(&UserCloudPolicyManagerChromeOS::OnOAuth2PolicyTokenFetched,
220 base::Unretained(this)))); 262 base::Unretained(this))));
221 token_fetcher_->Start(); 263 token_fetcher_->Start();
222 } 264 }
223 265
224 void UserCloudPolicyManagerChromeOS::OnOAuth2PolicyTokenFetched( 266 void UserCloudPolicyManagerChromeOS::OnOAuth2PolicyTokenFetched(
225 const std::string& policy_token, 267 const std::string& policy_token,
226 const GoogleServiceAuthError& error) { 268 const GoogleServiceAuthError& error) {
227 DCHECK(!client()->is_registered()); 269 DCHECK(!client()->is_registered());
270
271 time_token_available_ = base::Time::Now();
272 if (wait_for_policy_fetch_) {
273 UMA_HISTOGRAM_TIMES(kUMAInitialFetchDelayOAuth2Token,
274 time_token_available_ - time_init_completed_);
275 }
276
228 if (error.state() == GoogleServiceAuthError::NONE) { 277 if (error.state() == GoogleServiceAuthError::NONE) {
229 // Start client registration. Either OnRegistrationStateChanged() or 278 // Start client registration. Either OnRegistrationStateChanged() or
230 // OnClientError() will be called back. 279 // OnClientError() will be called back.
231 client()->Register(em::DeviceRegisterRequest::USER, 280 client()->Register(em::DeviceRegisterRequest::USER,
232 policy_token, std::string(), false, std::string()); 281 policy_token, std::string(), false, std::string());
233 } else { 282 } else {
234 // Failed to get a token, stop waiting and use an empty policy. 283 // Failed to get a token, stop waiting and use an empty policy.
235 CancelWaitForPolicyFetch(); 284 CancelWaitForPolicyFetch();
285
286 UMA_HISTOGRAM_ENUMERATION(kUMAInitialFetchOAuth2Error,
287 error.state(),
288 GoogleServiceAuthError::NUM_STATES);
289 if (error.state() == GoogleServiceAuthError::CONNECTION_FAILED) {
290 UMA_HISTOGRAM_SPARSE_SLOWLY(kUMAInitialFetchOAuth2NetworkError,
291 error.network_error());
292 }
236 } 293 }
237 294
238 token_fetcher_.reset(); 295 token_fetcher_.reset();
239 } 296 }
240 297
241 void UserCloudPolicyManagerChromeOS::OnInitialPolicyFetchComplete( 298 void UserCloudPolicyManagerChromeOS::OnInitialPolicyFetchComplete(
242 bool success) { 299 bool success) {
300
301 const base::Time now = base::Time::Now();
302 UMA_HISTOGRAM_TIMES(kUMAInitialFetchDelayPolicyFetch,
303 now - time_client_registered_);
304 UMA_HISTOGRAM_TIMES(kUMAInitialFetchDelayTotal, now - time_init_started_);
243 CancelWaitForPolicyFetch(); 305 CancelWaitForPolicyFetch();
244 } 306 }
245 307
246 void UserCloudPolicyManagerChromeOS::CancelWaitForPolicyFetch() { 308 void UserCloudPolicyManagerChromeOS::CancelWaitForPolicyFetch() {
247 wait_for_policy_fetch_ = false; 309 wait_for_policy_fetch_ = false;
248 CheckAndPublishPolicy(); 310 CheckAndPublishPolicy();
249 // Now that |wait_for_policy_fetch_| is guaranteed to be false, the scheduler 311 // Now that |wait_for_policy_fetch_| is guaranteed to be false, the scheduler
250 // can be started. 312 // can be started.
251 StartRefreshSchedulerIfReady(); 313 StartRefreshSchedulerIfReady();
252 } 314 }
(...skipping 14 matching lines...) Expand all
267 // start the scheduler. The |component_policy_service_| will call back into 329 // start the scheduler. The |component_policy_service_| will call back into
268 // OnComponentCloudPolicyUpdated() once it's ready. 330 // OnComponentCloudPolicyUpdated() once it's ready.
269 return; 331 return;
270 } 332 }
271 333
272 StartRefreshScheduler(); 334 StartRefreshScheduler();
273 core()->TrackRefreshDelayPref(local_state_, prefs::kUserPolicyRefreshRate); 335 core()->TrackRefreshDelayPref(local_state_, prefs::kUserPolicyRefreshRate);
274 } 336 }
275 337
276 } // namespace policy 338 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h ('k') | google_apis/gaia/google_service_auth_error.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698