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

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

Issue 2947753002: CacheStorage: Migrate to BindOnce/OnceCallback/OnceClosure (Closed)
Patch Set: Untangle Batch logic (relies on AdaptCallbackForRepeating) Created 3 years, 6 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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_scheduler.h" 5 #include "content/browser/cache_storage/cache_storage_scheduler.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/location.h" 10 #include "base/location.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "base/metrics/histogram_macros.h" 13 #include "base/metrics/histogram_macros.h"
14 #include "base/single_thread_task_runner.h" 14 #include "base/single_thread_task_runner.h"
15 #include "base/threading/thread_task_runner_handle.h" 15 #include "base/threading/thread_task_runner_handle.h"
16 #include "content/browser/cache_storage/cache_storage_histogram_macros.h" 16 #include "content/browser/cache_storage/cache_storage_histogram_macros.h"
17 #include "content/browser/cache_storage/cache_storage_operation.h" 17 #include "content/browser/cache_storage/cache_storage_operation.h"
18 18
19 namespace content { 19 namespace content {
20 20
21 CacheStorageScheduler::CacheStorageScheduler( 21 CacheStorageScheduler::CacheStorageScheduler(
22 CacheStorageSchedulerClient client_type) 22 CacheStorageSchedulerClient client_type)
23 : client_type_(client_type), weak_ptr_factory_(this) {} 23 : client_type_(client_type), weak_ptr_factory_(this) {}
24 24
25 CacheStorageScheduler::~CacheStorageScheduler() {} 25 CacheStorageScheduler::~CacheStorageScheduler() {}
26 26
27 void CacheStorageScheduler::ScheduleOperation(const base::Closure& closure) { 27 void CacheStorageScheduler::ScheduleOperation(base::OnceClosure closure) {
28 CACHE_STORAGE_SCHEDULER_UMA(COUNTS_10000, "QueueLength", client_type_, 28 CACHE_STORAGE_SCHEDULER_UMA(COUNTS_10000, "QueueLength", client_type_,
29 pending_operations_.size()); 29 pending_operations_.size());
30 30
31 pending_operations_.push_back(base::MakeUnique<CacheStorageOperation>( 31 pending_operations_.push_back(base::MakeUnique<CacheStorageOperation>(
32 closure, client_type_, base::ThreadTaskRunnerHandle::Get())); 32 std::move(closure), client_type_, base::ThreadTaskRunnerHandle::Get()));
33 RunOperationIfIdle(); 33 RunOperationIfIdle();
34 } 34 }
35 35
36 void CacheStorageScheduler::CompleteOperationAndRunNext() { 36 void CacheStorageScheduler::CompleteOperationAndRunNext() {
37 DCHECK(running_operation_); 37 DCHECK(running_operation_);
38 running_operation_.reset(); 38 running_operation_.reset();
39 39
40 RunOperationIfIdle(); 40 RunOperationIfIdle();
41 } 41 }
42 42
43 bool CacheStorageScheduler::ScheduledOperations() const { 43 bool CacheStorageScheduler::ScheduledOperations() const {
44 return running_operation_ || !pending_operations_.empty(); 44 return running_operation_ || !pending_operations_.empty();
45 } 45 }
46 46
47 void CacheStorageScheduler::RunOperationIfIdle() { 47 void CacheStorageScheduler::RunOperationIfIdle() {
48 if (!running_operation_ && !pending_operations_.empty()) { 48 if (!running_operation_ && !pending_operations_.empty()) {
49 // TODO(jkarlin): Run multiple operations in parallel where allowed. 49 // TODO(jkarlin): Run multiple operations in parallel where allowed.
50 running_operation_ = std::move(pending_operations_.front()); 50 running_operation_ = std::move(pending_operations_.front());
51 pending_operations_.pop_front(); 51 pending_operations_.pop_front();
52 52
53 CACHE_STORAGE_SCHEDULER_UMA( 53 CACHE_STORAGE_SCHEDULER_UMA(
54 TIMES, "QueueDuration", client_type_, 54 TIMES, "QueueDuration", client_type_,
55 base::TimeTicks::Now() - running_operation_->creation_ticks()); 55 base::TimeTicks::Now() - running_operation_->creation_ticks());
56 56
57 base::ThreadTaskRunnerHandle::Get()->PostTask( 57 base::ThreadTaskRunnerHandle::Get()->PostTask(
58 FROM_HERE, base::Bind(&CacheStorageOperation::Run, 58 FROM_HERE, base::BindOnce(&CacheStorageOperation::Run,
59 running_operation_->AsWeakPtr())); 59 running_operation_->AsWeakPtr()));
60 } 60 }
61 } 61 }
62 62
63 } // namespace content 63 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698