Chromium Code Reviews| Index: chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.cc |
| diff --git a/chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.cc b/chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.cc |
| index e3452f9547f8936ef0e6a9c93578f681475bebd0..0616799268360aefff727f6cade582e0d0209925 100644 |
| --- a/chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.cc |
| +++ b/chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.cc |
| @@ -7,6 +7,8 @@ |
| #include "base/bind.h" |
| #include "base/bind_helpers.h" |
| #include "base/logging.h" |
| +#include "base/metrics/histogram.h" |
| +#include "base/metrics/sparse_histogram.h" |
| #include "chrome/browser/browser_process.h" |
| #include "chrome/browser/chromeos/policy/policy_oauth2_token_fetcher.h" |
| #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chromeos.h" |
| @@ -22,6 +24,28 @@ namespace em = enterprise_management; |
| namespace policy { |
| +namespace { |
| + |
| +// UMA histogram names. |
| +const char kUMADelayInitialization[] = |
| + "Enterprise.UserPolicyChromeOS.DelayInitialization"; |
| +const char kUMAInitialFetchClientError[] = |
| + "Enterprise.UserPolicyChromeOS.InitialFetch.ClientError"; |
| +const char kUMAInitialFetchDelayClientRegister[] = |
| + "Enterprise.UserPolicyChromeOS.InitialFetch.DelayClientRegister"; |
| +const char kUMAInitialFetchDelayOAuth2Token[] = |
| + "Enterprise.UserPolicyChromeOS.InitialFetch.DelayOAuth2Token"; |
| +const char kUMAInitialFetchDelayPolicyFetch[] = |
| + "Enterprise.UserPolicyChromeOS.InitialFetch.DelayPolicyFetch"; |
| +const char kUMAInitialFetchDelayTotal[] = |
| + "Enterprise.UserPolicyChromeOS.InitialFetch.DelayTotal"; |
| +const char kUMAInitialFetchOAuth2Error[] = |
| + "Enterprise.UserPolicyChromeOS.InitialFetch.OAuth2Error"; |
| +const char kUMAInitialFetchOAuth2NetworkError[] = |
| + "Enterprise.UserPolicyChromeOS.InitialFetch.OAuth2NetworkError"; |
| + |
| +} // namespace |
| + |
| UserCloudPolicyManagerChromeOS::UserCloudPolicyManagerChromeOS( |
| scoped_ptr<CloudPolicyStore> store, |
| scoped_ptr<ResourceCache> resource_cache, |
| @@ -31,6 +55,7 @@ UserCloudPolicyManagerChromeOS::UserCloudPolicyManagerChromeOS( |
| store.get()), |
| store_(store.Pass()), |
| wait_for_policy_fetch_(wait_for_policy_fetch) { |
| + time_init_started_ = base::Time::Now(); |
| if (resource_cache) { |
| component_policy_service_.reset(new ComponentCloudPolicyService( |
| this, store_.get(), resource_cache.Pass())); |
| @@ -120,6 +145,11 @@ void UserCloudPolicyManagerChromeOS::OnInitializationCompleted( |
| CloudPolicyService* cloud_policy_service) { |
| DCHECK_EQ(service(), cloud_policy_service); |
| cloud_policy_service->RemoveObserver(this); |
| + |
| + time_init_completed_ = base::Time::Now(); |
| + UMA_HISTOGRAM_TIMES(kUMADelayInitialization, |
| + time_init_completed_ - time_init_started_); |
| + |
| // If the CloudPolicyClient isn't registered at this stage then it needs an |
| // OAuth token for the initial registration. |
| // |
| @@ -161,7 +191,14 @@ void UserCloudPolicyManagerChromeOS::OnPolicyFetched( |
| void UserCloudPolicyManagerChromeOS::OnRegistrationStateChanged( |
| CloudPolicyClient* cloud_policy_client) { |
| DCHECK_EQ(client(), cloud_policy_client); |
| + |
| if (wait_for_policy_fetch_) { |
| + time_client_registered_ = base::Time::Now(); |
| + if (!time_token_available_.is_null()) { |
| + UMA_HISTOGRAM_TIMES(kUMAInitialFetchDelayClientRegister, |
| + time_client_registered_ - time_token_available_); |
| + } |
| + |
| // If we're blocked on the policy fetch, now is a good time to issue it. |
| if (client()->is_registered()) { |
| service()->RefreshPolicy( |
| @@ -180,6 +217,11 @@ void UserCloudPolicyManagerChromeOS::OnClientError( |
| CloudPolicyClient* cloud_policy_client) { |
| DCHECK_EQ(client(), cloud_policy_client); |
| CancelWaitForPolicyFetch(); |
| + |
| + if (wait_for_policy_fetch_) { |
| + UMA_HISTOGRAM_SPARSE_SLOWLY(kUMAInitialFetchClientError, |
| + cloud_policy_client->status()); |
| + } |
| } |
| void UserCloudPolicyManagerChromeOS::OnComponentCloudPolicyRefreshNeeded() { |
| @@ -215,6 +257,13 @@ void UserCloudPolicyManagerChromeOS::OnOAuth2PolicyTokenFetched( |
| const std::string& policy_token, |
| const GoogleServiceAuthError& error) { |
| DCHECK(!client()->is_registered()); |
| + |
| + time_token_available_ = base::Time::Now(); |
| + if (wait_for_policy_fetch_) { |
| + UMA_HISTOGRAM_TIMES(kUMAInitialFetchDelayOAuth2Token, |
| + time_token_available_ - time_init_completed_); |
| + } |
| + |
| if (error.state() == GoogleServiceAuthError::NONE) { |
| // Start client registration. Either OnRegistrationStateChanged() or |
| // OnClientError() will be called back. |
| @@ -223,6 +272,14 @@ void UserCloudPolicyManagerChromeOS::OnOAuth2PolicyTokenFetched( |
| } else { |
| // Failed to get a token, stop waiting and use an empty policy. |
| CancelWaitForPolicyFetch(); |
| + |
| + UMA_HISTOGRAM_ENUMERATION(kUMAInitialFetchOAuth2Error, |
| + error.state(), |
| + GoogleServiceAuthError::NUM_STATES); |
| + if (error.state() == GoogleServiceAuthError::CONNECTION_FAILED) { |
| + UMA_HISTOGRAM_SPARSE_SLOWLY(kUMAInitialFetchOAuth2NetworkError, |
| + error.network_error()); |
| + } |
| } |
| token_fetcher_.reset(); |
| @@ -230,6 +287,11 @@ void UserCloudPolicyManagerChromeOS::OnOAuth2PolicyTokenFetched( |
| void UserCloudPolicyManagerChromeOS::OnInitialPolicyFetchComplete( |
| bool success) { |
| + |
| + base::Time now = base::Time::Now(); |
|
bartfab (slow)
2013/08/30 10:04:40
Nit: const
Mattias Nissler (ping if slow)
2013/09/03 11:09:22
Done.
|
| + UMA_HISTOGRAM_TIMES(kUMAInitialFetchDelayPolicyFetch, |
| + now - time_client_registered_); |
| + UMA_HISTOGRAM_TIMES(kUMAInitialFetchDelayTotal, now - time_init_started_); |
| CancelWaitForPolicyFetch(); |
| } |