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

Side by Side Diff: components/policy/core/common/cloud/cloud_policy_service.cc

Issue 2896863002: Add UMA histograms for time between policy fetches (Closed)
Patch Set: Created 3 years, 7 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
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 "components/policy/core/common/cloud/cloud_policy_service.h" 5 #include "components/policy/core/common/cloud/cloud_policy_service.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/metrics/histogram_macros.h"
12 #include "base/time/time.h"
13 #include "components/policy/core/common/cloud/cloud_policy_constants.h"
11 #include "components/policy/proto/device_management_backend.pb.h" 14 #include "components/policy/proto/device_management_backend.pb.h"
12 15
13 namespace em = enterprise_management; 16 namespace em = enterprise_management;
14 17
15 namespace policy { 18 namespace policy {
16 19
17 CloudPolicyService::CloudPolicyService(const std::string& policy_type, 20 CloudPolicyService::CloudPolicyService(const std::string& policy_type,
18 const std::string& settings_entity_id, 21 const std::string& settings_entity_id,
19 CloudPolicyClient* client, 22 CloudPolicyClient* client,
20 CloudPolicyStore* store) 23 CloudPolicyStore* store)
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 } 111 }
109 112
110 void CloudPolicyService::OnStoreLoaded(CloudPolicyStore* store) { 113 void CloudPolicyService::OnStoreLoaded(CloudPolicyStore* store) {
111 // Update the client with state from the store. 114 // Update the client with state from the store.
112 const em::PolicyData* policy(store_->policy()); 115 const em::PolicyData* policy(store_->policy());
113 116
114 // Timestamp. 117 // Timestamp.
115 base::Time policy_timestamp; 118 base::Time policy_timestamp;
116 if (policy && policy->has_timestamp()) 119 if (policy && policy->has_timestamp())
117 policy_timestamp = base::Time::FromJavaTime(policy->timestamp()); 120 policy_timestamp = base::Time::FromJavaTime(policy->timestamp());
121
122 const base::Time& old_timestamp = client_->last_policy_timestamp();
123 if (!policy_timestamp.is_null() && !old_timestamp.is_null() &&
124 policy_timestamp != old_timestamp) {
125 base::TimeDelta age = policy_timestamp - old_timestamp;
bartfab (slow) 2017/06/12 15:01:58 Nit: const
Denis Kuznetsov (DE-MUC) 2017/07/03 10:20:00 Done.
126 if (policy_type_ == dm_protocol::kChromeUserPolicyType) {
127 UMA_HISTOGRAM_CUSTOM_COUNTS("Enterprise.PolicyUpdatePeriod.User",
128 age.InDays(), 1, 1000, 100);
129 } else if (policy_type_ == dm_protocol::kChromeDevicePolicyType) {
130 UMA_HISTOGRAM_CUSTOM_COUNTS("Enterprise.PolicyUpdatePeriod.Device",
131 age.InDays(), 1, 1000, 100);
132 }
133 }
118 client_->set_last_policy_timestamp(policy_timestamp); 134 client_->set_last_policy_timestamp(policy_timestamp);
119 135
120 // Public key version. 136 // Public key version.
121 if (policy && policy->has_public_key_version()) 137 if (policy && policy->has_public_key_version())
122 client_->set_public_key_version(policy->public_key_version()); 138 client_->set_public_key_version(policy->public_key_version());
123 else 139 else
124 client_->clear_public_key_version(); 140 client_->clear_public_key_version();
125 141
126 // Finally, set up registration if necessary. 142 // Finally, set up registration if necessary.
127 if (policy && policy->has_request_token() && policy->has_device_id() && 143 if (policy && policy->has_request_token() && policy->has_device_id() &&
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 193
178 void CloudPolicyService::AddObserver(Observer* observer) { 194 void CloudPolicyService::AddObserver(Observer* observer) {
179 observers_.AddObserver(observer); 195 observers_.AddObserver(observer);
180 } 196 }
181 197
182 void CloudPolicyService::RemoveObserver(Observer* observer) { 198 void CloudPolicyService::RemoveObserver(Observer* observer) {
183 observers_.RemoveObserver(observer); 199 observers_.RemoveObserver(observer);
184 } 200 }
185 201
186 } // namespace policy 202 } // namespace policy
OLDNEW
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | tools/metrics/histograms/histograms.xml » ('J')

Powered by Google App Engine
This is Rietveld 408576698