| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 NET_DISK_CACHE_IN_FLIGHT_BACKEND_IO_H_ | 5 #ifndef NET_DISK_CACHE_IN_FLIGHT_BACKEND_IO_H_ |
| 6 #define NET_DISK_CACHE_IN_FLIGHT_BACKEND_IO_H_ | 6 #define NET_DISK_CACHE_IN_FLIGHT_BACKEND_IO_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <list> | 9 #include <list> |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 27 public: | 27 public: |
| 28 BackendIO(InFlightIO* controller, BackendImpl* backend, | 28 BackendIO(InFlightIO* controller, BackendImpl* backend, |
| 29 const net::CompletionCallback& callback); | 29 const net::CompletionCallback& callback); |
| 30 | 30 |
| 31 // Runs the actual operation on the background thread. | 31 // Runs the actual operation on the background thread. |
| 32 void ExecuteOperation(); | 32 void ExecuteOperation(); |
| 33 | 33 |
| 34 // Callback implementation. | 34 // Callback implementation. |
| 35 void OnIOComplete(int result); | 35 void OnIOComplete(int result); |
| 36 | 36 |
| 37 // Called when we are finishing this operation. If |cancel| is true, the user |
| 38 // callback will not be invoked. |
| 39 void OnDone(bool cancel); |
| 40 |
| 37 // Returns true if this operation is directed to an entry (vs. the backend). | 41 // Returns true if this operation is directed to an entry (vs. the backend). |
| 38 bool IsEntryOperation(); | 42 bool IsEntryOperation(); |
| 39 | 43 |
| 40 net::CompletionCallback callback() const { return callback_; } | 44 net::CompletionCallback callback() const { return callback_; } |
| 41 | 45 |
| 42 // Grabs an extra reference of entry_. | 46 // Grabs an extra reference of entry_. |
| 43 void ReferenceEntry(); | 47 void ReferenceEntry(); |
| 44 | 48 |
| 45 // Returns the time that has passed since the operation was created. | |
| 46 base::TimeDelta ElapsedTime() const; | |
| 47 | |
| 48 // The operations we proxy: | 49 // The operations we proxy: |
| 49 void Init(); | 50 void Init(); |
| 50 void OpenEntry(const std::string& key, Entry** entry); | 51 void OpenEntry(const std::string& key, Entry** entry); |
| 51 void CreateEntry(const std::string& key, Entry** entry); | 52 void CreateEntry(const std::string& key, Entry** entry); |
| 52 void DoomEntry(const std::string& key); | 53 void DoomEntry(const std::string& key); |
| 53 void DoomAllEntries(); | 54 void DoomAllEntries(); |
| 54 void DoomEntriesBetween(const base::Time initial_time, | 55 void DoomEntriesBetween(const base::Time initial_time, |
| 55 const base::Time end_time); | 56 const base::Time end_time); |
| 56 void DoomEntriesSince(const base::Time initial_time); | 57 void DoomEntriesSince(const base::Time initial_time); |
| 57 void OpenNextEntry(void** iter, Entry** next_entry); | 58 void OpenNextEntry(void** iter, Entry** next_entry); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 OP_WRITE, | 103 OP_WRITE, |
| 103 OP_READ_SPARSE, | 104 OP_READ_SPARSE, |
| 104 OP_WRITE_SPARSE, | 105 OP_WRITE_SPARSE, |
| 105 OP_GET_RANGE, | 106 OP_GET_RANGE, |
| 106 OP_CANCEL_IO, | 107 OP_CANCEL_IO, |
| 107 OP_IS_READY | 108 OP_IS_READY |
| 108 }; | 109 }; |
| 109 | 110 |
| 110 virtual ~BackendIO(); | 111 virtual ~BackendIO(); |
| 111 | 112 |
| 113 // Returns true if this operation returns an entry. |
| 114 bool ReturnsEntry(); |
| 115 |
| 116 // Returns the time that has passed since the operation was created. |
| 117 base::TimeDelta ElapsedTime() const; |
| 118 |
| 112 void ExecuteBackendOperation(); | 119 void ExecuteBackendOperation(); |
| 113 void ExecuteEntryOperation(); | 120 void ExecuteEntryOperation(); |
| 114 | 121 |
| 115 BackendImpl* backend_; | 122 BackendImpl* backend_; |
| 116 net::CompletionCallback callback_; | 123 net::CompletionCallback callback_; |
| 117 Operation operation_; | 124 Operation operation_; |
| 118 | 125 |
| 119 // The arguments of all the operations we proxy: | 126 // The arguments of all the operations we proxy: |
| 120 std::string key_; | 127 std::string key_; |
| 121 Entry** entry_ptr_; | 128 Entry** entry_ptr_; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 | 196 |
| 190 scoped_refptr<base::MessageLoopProxy> background_thread() { | 197 scoped_refptr<base::MessageLoopProxy> background_thread() { |
| 191 return background_thread_; | 198 return background_thread_; |
| 192 } | 199 } |
| 193 | 200 |
| 194 // Returns true if the current thread is the background thread. | 201 // Returns true if the current thread is the background thread. |
| 195 bool BackgroundIsCurrentThread() { | 202 bool BackgroundIsCurrentThread() { |
| 196 return background_thread_->BelongsToCurrentThread(); | 203 return background_thread_->BelongsToCurrentThread(); |
| 197 } | 204 } |
| 198 | 205 |
| 206 base::WeakPtr<InFlightBackendIO> GetWeakPtr(); |
| 207 |
| 199 protected: | 208 protected: |
| 200 virtual void OnOperationComplete(BackgroundIO* operation, | 209 virtual void OnOperationComplete(BackgroundIO* operation, |
| 201 bool cancel) OVERRIDE; | 210 bool cancel) OVERRIDE; |
| 202 | 211 |
| 203 private: | 212 private: |
| 204 void PostOperation(BackendIO* operation); | 213 void PostOperation(BackendIO* operation); |
| 205 | 214 |
| 206 BackendImpl* backend_; | 215 BackendImpl* backend_; |
| 207 scoped_refptr<base::MessageLoopProxy> background_thread_; | 216 scoped_refptr<base::MessageLoopProxy> background_thread_; |
| 217 base::WeakPtrFactory<InFlightBackendIO> ptr_factory_; |
| 208 | 218 |
| 209 DISALLOW_COPY_AND_ASSIGN(InFlightBackendIO); | 219 DISALLOW_COPY_AND_ASSIGN(InFlightBackendIO); |
| 210 }; | 220 }; |
| 211 | 221 |
| 212 } // namespace disk_cache | 222 } // namespace disk_cache |
| 213 | 223 |
| 214 #endif // NET_DISK_CACHE_IN_FLIGHT_BACKEND_IO_H_ | 224 #endif // NET_DISK_CACHE_IN_FLIGHT_BACKEND_IO_H_ |
| OLD | NEW |