| OLD | NEW |
| (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 |
| OLD | NEW |