| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 "content/browser/cache_storage/cache_storage_operation.h" | 5 #include "content/browser/cache_storage/cache_storage_operation.h" |
| 6 | 6 |
| 7 #include "content/browser/cache_storage/cache_storage_histogram_macros.h" | 7 #include "content/browser/cache_storage/cache_storage_histogram_macros.h" |
| 8 | 8 |
| 9 namespace content { | 9 namespace content { |
| 10 | 10 |
| 11 namespace { | 11 namespace { |
| 12 const int kNumSecondsForSlowOperation = 10; | 12 const int kNumSecondsForSlowOperation = 10; |
| 13 } | 13 } |
| 14 | 14 |
| 15 CacheStorageOperation::CacheStorageOperation( | 15 CacheStorageOperation::CacheStorageOperation( |
| 16 const base::Closure& closure, | 16 base::OnceClosure closure, |
| 17 CacheStorageSchedulerClient client_type, | 17 CacheStorageSchedulerClient client_type, |
| 18 scoped_refptr<base::SingleThreadTaskRunner> task_runner) | 18 scoped_refptr<base::SingleThreadTaskRunner> task_runner) |
| 19 : closure_(closure), | 19 : closure_(std::move(closure)), |
| 20 creation_ticks_(base::TimeTicks::Now()), | 20 creation_ticks_(base::TimeTicks::Now()), |
| 21 client_type_(client_type), | 21 client_type_(client_type), |
| 22 task_runner_(std::move(task_runner)), | 22 task_runner_(std::move(task_runner)), |
| 23 weak_ptr_factory_(this) {} | 23 weak_ptr_factory_(this) {} |
| 24 | 24 |
| 25 CacheStorageOperation::~CacheStorageOperation() { | 25 CacheStorageOperation::~CacheStorageOperation() { |
| 26 CACHE_STORAGE_SCHEDULER_UMA(TIMES, "OperationDuration", client_type_, | 26 CACHE_STORAGE_SCHEDULER_UMA(TIMES, "OperationDuration", client_type_, |
| 27 base::TimeTicks::Now() - start_ticks_); | 27 base::TimeTicks::Now() - start_ticks_); |
| 28 | 28 |
| 29 if (!was_slow_) | 29 if (!was_slow_) |
| 30 CACHE_STORAGE_SCHEDULER_UMA(BOOLEAN, "IsOperationSlow", client_type_, | 30 CACHE_STORAGE_SCHEDULER_UMA(BOOLEAN, "IsOperationSlow", client_type_, |
| 31 false); | 31 false); |
| 32 } | 32 } |
| 33 | 33 |
| 34 void CacheStorageOperation::Run() { | 34 void CacheStorageOperation::Run() { |
| 35 start_ticks_ = base::TimeTicks::Now(); | 35 start_ticks_ = base::TimeTicks::Now(); |
| 36 | 36 |
| 37 task_runner_->PostDelayedTask( | 37 task_runner_->PostDelayedTask( |
| 38 FROM_HERE, base::Bind(&CacheStorageOperation::NotifyOperationSlow, | 38 FROM_HERE, |
| 39 weak_ptr_factory_.GetWeakPtr()), | 39 base::BindOnce(&CacheStorageOperation::NotifyOperationSlow, |
| 40 weak_ptr_factory_.GetWeakPtr()), |
| 40 base::TimeDelta::FromSeconds(kNumSecondsForSlowOperation)); | 41 base::TimeDelta::FromSeconds(kNumSecondsForSlowOperation)); |
| 41 closure_.Run(); | 42 std::move(closure_).Run(); |
| 42 } | 43 } |
| 43 | 44 |
| 44 void CacheStorageOperation::NotifyOperationSlow() { | 45 void CacheStorageOperation::NotifyOperationSlow() { |
| 45 was_slow_ = true; | 46 was_slow_ = true; |
| 46 CACHE_STORAGE_SCHEDULER_UMA(BOOLEAN, "IsOperationSlow", client_type_, true); | 47 CACHE_STORAGE_SCHEDULER_UMA(BOOLEAN, "IsOperationSlow", client_type_, true); |
| 47 } | 48 } |
| 48 | 49 |
| 49 } // namespace content | 50 } // namespace content |
| OLD | NEW |