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

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

Issue 2413993003: Add UMA histogram to show how many retries we had to do to execute a DeviceManagementRequestJob. (Closed)
Patch Set: Fix histogram summary Created 4 years, 2 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
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/device_management_service.h" 5 #include "components/policy/core/common/cloud/device_management_service.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
11 #include "base/location.h" 11 #include "base/location.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/metrics/histogram.h"
13 #include "base/single_thread_task_runner.h" 14 #include "base/single_thread_task_runner.h"
14 #include "base/threading/thread_task_runner_handle.h" 15 #include "base/threading/thread_task_runner_handle.h"
15 #include "components/data_use_measurement/core/data_use_user_data.h" 16 #include "components/data_use_measurement/core/data_use_user_data.h"
16 #include "net/base/escape.h" 17 #include "net/base/escape.h"
17 #include "net/base/load_flags.h" 18 #include "net/base/load_flags.h"
18 #include "net/base/net_errors.h" 19 #include "net/base/net_errors.h"
19 #include "net/http/http_response_headers.h" 20 #include "net/http/http_response_headers.h"
20 #include "net/url_request/url_fetcher.h" 21 #include "net/url_request/url_fetcher.h"
21 #include "net/url_request/url_request_context_getter.h" 22 #include "net/url_request/url_request_context_getter.h"
22 #include "net/url_request/url_request_status.h" 23 #include "net/url_request/url_request_status.h"
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 223
223 // The request context to use for this job. 224 // The request context to use for this job.
224 scoped_refptr<net::URLRequestContextGetter> request_context_; 225 scoped_refptr<net::URLRequestContextGetter> request_context_;
225 226
226 // Used to get notified if the job has been canceled while waiting for retry. 227 // Used to get notified if the job has been canceled while waiting for retry.
227 base::WeakPtrFactory<DeviceManagementRequestJobImpl> weak_ptr_factory_; 228 base::WeakPtrFactory<DeviceManagementRequestJobImpl> weak_ptr_factory_;
228 229
229 DISALLOW_COPY_AND_ASSIGN(DeviceManagementRequestJobImpl); 230 DISALLOW_COPY_AND_ASSIGN(DeviceManagementRequestJobImpl);
230 }; 231 };
231 232
233 // Used in the Enterprise.DMServerRequestSuccess histogram, shows how many
234 // retries we had to do to execute the DeviceManagementRequestJob.
235 enum DMServerRequestSuccess {
236 // No retries happened, the request succeeded for the first try.
237 REQUEST_NO_RETRY = 0,
238
239 // 1..kMaxRetries: number of retries
240
241 // The request failed (too many retries or non-retriable error).
242 REQUEST_FAILED = 10,
243 // The server responded with an error.
244 REQUEST_ERROR,
245
246 REQUEST_MAX
247 };
248
232 DeviceManagementRequestJobImpl::DeviceManagementRequestJobImpl( 249 DeviceManagementRequestJobImpl::DeviceManagementRequestJobImpl(
233 JobType type, 250 JobType type,
234 const std::string& agent_parameter, 251 const std::string& agent_parameter,
235 const std::string& platform_parameter, 252 const std::string& platform_parameter,
236 DeviceManagementService* service, 253 DeviceManagementService* service,
237 const scoped_refptr<net::URLRequestContextGetter>& request_context) 254 const scoped_refptr<net::URLRequestContextGetter>& request_context)
238 : DeviceManagementRequestJob(type, agent_parameter, platform_parameter), 255 : DeviceManagementRequestJob(type, agent_parameter, platform_parameter),
239 service_(service), 256 service_(service),
240 bypass_proxy_(false), 257 bypass_proxy_(false),
241 retries_count_(0), 258 retries_count_(0),
242 request_context_(request_context), 259 request_context_(request_context),
243 weak_ptr_factory_(this) {} 260 weak_ptr_factory_(this) {}
244 261
245 DeviceManagementRequestJobImpl::~DeviceManagementRequestJobImpl() { 262 DeviceManagementRequestJobImpl::~DeviceManagementRequestJobImpl() {
246 service_->RemoveJob(this); 263 service_->RemoveJob(this);
247 } 264 }
248 265
249 void DeviceManagementRequestJobImpl::Run() { 266 void DeviceManagementRequestJobImpl::Run() {
250 service_->AddJob(this); 267 service_->AddJob(this);
251 } 268 }
252 269
253 void DeviceManagementRequestJobImpl::HandleResponse( 270 void DeviceManagementRequestJobImpl::HandleResponse(
254 const net::URLRequestStatus& status, 271 const net::URLRequestStatus& status,
255 int response_code, 272 int response_code,
256 const std::string& data) { 273 const std::string& data) {
257 if (status.status() != net::URLRequestStatus::SUCCESS) { 274 if (status.status() != net::URLRequestStatus::SUCCESS) {
275 UMA_HISTOGRAM_ENUMERATION("Enterprise.DMServerRequestSuccess",
276 DMServerRequestSuccess::REQUEST_FAILED,
277 DMServerRequestSuccess::REQUEST_MAX);
258 LOG(WARNING) << "DMServer request failed, status: " << status.status() 278 LOG(WARNING) << "DMServer request failed, status: " << status.status()
259 << ", error: " << status.error(); 279 << ", error: " << status.error();
260 em::DeviceManagementResponse dummy_response; 280 em::DeviceManagementResponse dummy_response;
261 callback_.Run(DM_STATUS_REQUEST_FAILED, status.error(), dummy_response); 281 callback_.Run(DM_STATUS_REQUEST_FAILED, status.error(), dummy_response);
262 return; 282 return;
263 } 283 }
264 284
265 if (response_code != kSuccess) 285 if (response_code != kSuccess) {
286 UMA_HISTOGRAM_ENUMERATION("Enterprise.DMServerRequestSuccess",
287 DMServerRequestSuccess::REQUEST_ERROR,
288 DMServerRequestSuccess::REQUEST_MAX);
266 LOG(WARNING) << "DMServer sent an error response: " << response_code; 289 LOG(WARNING) << "DMServer sent an error response: " << response_code;
290 } else {
291 // Success with retries_count_ retries.
292 UMA_HISTOGRAM_ENUMERATION("Enterprise.DMServerRequestSuccess",
293 retries_count_,
294 DMServerRequestSuccess::REQUEST_MAX);
295 }
267 296
268 switch (response_code) { 297 switch (response_code) {
269 case kSuccess: { 298 case kSuccess: {
270 em::DeviceManagementResponse response; 299 em::DeviceManagementResponse response;
271 if (!response.ParseFromString(data)) { 300 if (!response.ParseFromString(data)) {
272 ReportError(DM_STATUS_RESPONSE_DECODING_ERROR); 301 ReportError(DM_STATUS_RESPONSE_DECODING_ERROR);
273 return; 302 return;
274 } 303 }
275 callback_.Run(DM_STATUS_SUCCESS, net::OK, response); 304 callback_.Run(DM_STATUS_SUCCESS, net::OK, response);
276 return; 305 return;
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 } 639 }
611 } 640 }
612 641
613 const JobQueue::iterator elem = 642 const JobQueue::iterator elem =
614 std::find(queued_jobs_.begin(), queued_jobs_.end(), job); 643 std::find(queued_jobs_.begin(), queued_jobs_.end(), job);
615 if (elem != queued_jobs_.end()) 644 if (elem != queued_jobs_.end())
616 queued_jobs_.erase(elem); 645 queued_jobs_.erase(elem);
617 } 646 }
618 647
619 } // namespace policy 648 } // namespace policy
OLDNEW
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698