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

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: Don't use unnamed namespace in header file Created 4 years, 5 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, "OperationSlow", client_type_, false);
31 }
32
33 void CacheStorageOperation::Run() {
34 start_ticks_ = base::TimeTicks::Now();
35
36 task_runner_->PostDelayedTask(
37 FROM_HERE, base::Bind(&CacheStorageOperation::NotifyOperationSlow,
38 weak_ptr_factory_.GetWeakPtr()),
39 base::TimeDelta::FromSeconds(kNumSecondsForSlowOperation));
40 closure_.Run();
41 }
42
43 void CacheStorageOperation::NotifyOperationSlow() {
44 was_slow_ = true;
45 CACHE_STORAGE_SCHEDULER_UMA(BOOLEAN, "OperationSlow", client_type_, true);
46 }
47
48 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698