| 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, "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 |
| OLD | NEW |