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

Side by Side Diff: content/browser/cache_storage/cache_storage_operation.cc

Issue 2168123002: [CacheStorage] Add metrics to the scheduler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add unit Created 4 years, 4 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
(Empty)
1 // Copyright 2016 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 "content/browser/cache_storage/cache_storage_operation.h"
6
7 #include "content/browser/cache_storage/cache_storage_histogram_macros.h"
8
9 namespace content {
10
11 namespace {
12 const int kNumSecondsForSlowOperation = 10;
13 }
14
15 CacheStorageOperation::CacheStorageOperation(
16 const base::Closure& closure,
17 CacheStorageSchedulerClient client_type,
18 scoped_refptr<base::SingleThreadTaskRunner> task_runner)
19 : closure_(closure),
20 creation_ticks_(base::TimeTicks::Now()),
21 client_type_(client_type),
22 task_runner_(std::move(task_runner)),
23 weak_ptr_factory_(this) {}
24
25 CacheStorageOperation::~CacheStorageOperation() {
26 CACHE_STORAGE_SCHEDULER_UMA(TIMES, "OperationDuration", client_type_,
27 base::TimeTicks::Now() - start_ticks_);
28
29 if (!was_slow_)
30 CACHE_STORAGE_SCHEDULER_UMA(BOOLEAN, "IsOperationSlow", client_type_,
31 false);
32 }
33
34 void CacheStorageOperation::Run() {
35 start_ticks_ = base::TimeTicks::Now();
36
37 task_runner_->PostDelayedTask(
38 FROM_HERE, base::Bind(&CacheStorageOperation::NotifyOperationSlow,
39 weak_ptr_factory_.GetWeakPtr()),
40 base::TimeDelta::FromSeconds(kNumSecondsForSlowOperation));
41 closure_.Run();
42 }
43
44 void CacheStorageOperation::NotifyOperationSlow() {
45 was_slow_ = true;
46 CACHE_STORAGE_SCHEDULER_UMA(BOOLEAN, "IsOperationSlow", client_type_, true);
47 }
48
49 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698