| 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 #ifndef CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_OPERATION_H_ | 5 #ifndef CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_OPERATION_H_ |
| 6 #define CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_OPERATION_H_ | 6 #define CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_OPERATION_H_ |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 12 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
| 13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 14 #include "content/browser/cache_storage/cache_storage_scheduler_client.h" | 14 #include "content/browser/cache_storage/cache_storage_scheduler_client.h" |
| 15 #include "content/common/content_export.h" | 15 #include "content/common/content_export.h" |
| 16 | 16 |
| 17 namespace content { | 17 namespace content { |
| 18 | 18 |
| 19 // An operation to run in the CacheStorageScheduler. It's mostly just a closure | 19 // An operation to run in the CacheStorageScheduler. It's mostly just a closure |
| 20 // to run plus a bunch of metrics data. | 20 // to run plus a bunch of metrics data. |
| 21 class CONTENT_EXPORT CacheStorageOperation { | 21 class CONTENT_EXPORT CacheStorageOperation { |
| 22 public: | 22 public: |
| 23 CacheStorageOperation( | 23 CacheStorageOperation( |
| 24 const base::Closure& closure, | 24 base::OnceClosure closure, |
| 25 CacheStorageSchedulerClient client_type, | 25 CacheStorageSchedulerClient client_type, |
| 26 scoped_refptr<base::SingleThreadTaskRunner> task_runner); | 26 scoped_refptr<base::SingleThreadTaskRunner> task_runner); |
| 27 | 27 |
| 28 ~CacheStorageOperation(); | 28 ~CacheStorageOperation(); |
| 29 | 29 |
| 30 // Run the closure passed to the constructor. | 30 // Run the closure passed to the constructor. |
| 31 void Run(); | 31 void Run(); |
| 32 | 32 |
| 33 base::TimeTicks creation_ticks() const { return creation_ticks_; } | 33 base::TimeTicks creation_ticks() const { return creation_ticks_; } |
| 34 base::WeakPtr<CacheStorageOperation> AsWeakPtr() { | 34 base::WeakPtr<CacheStorageOperation> AsWeakPtr() { |
| 35 return weak_ptr_factory_.GetWeakPtr(); | 35 return weak_ptr_factory_.GetWeakPtr(); |
| 36 } | 36 } |
| 37 | 37 |
| 38 private: | 38 private: |
| 39 void NotifyOperationSlow(); | 39 void NotifyOperationSlow(); |
| 40 | 40 |
| 41 // The operation's closure to run. | 41 // The operation's closure to run. |
| 42 base::Closure closure_; | 42 base::OnceClosure closure_; |
| 43 | 43 |
| 44 // Ticks at time of object creation. | 44 // Ticks at time of object creation. |
| 45 base::TimeTicks creation_ticks_; | 45 base::TimeTicks creation_ticks_; |
| 46 | 46 |
| 47 // Ticks at time the operation's closure is run. | 47 // Ticks at time the operation's closure is run. |
| 48 base::TimeTicks start_ticks_; | 48 base::TimeTicks start_ticks_; |
| 49 | 49 |
| 50 // If the operation took a long time to run. | 50 // If the operation took a long time to run. |
| 51 bool was_slow_ = false; | 51 bool was_slow_ = false; |
| 52 | 52 |
| 53 CacheStorageSchedulerClient client_type_; | 53 CacheStorageSchedulerClient client_type_; |
| 54 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 54 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 55 base::WeakPtrFactory<CacheStorageOperation> weak_ptr_factory_; | 55 base::WeakPtrFactory<CacheStorageOperation> weak_ptr_factory_; |
| 56 | 56 |
| 57 DISALLOW_COPY_AND_ASSIGN(CacheStorageOperation); | 57 DISALLOW_COPY_AND_ASSIGN(CacheStorageOperation); |
| 58 }; | 58 }; |
| 59 | 59 |
| 60 } // namespace content | 60 } // namespace content |
| 61 | 61 |
| 62 #endif // CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_OPERATION_H_ | 62 #endif // CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_OPERATION_H_ |
| OLD | NEW |