OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013 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 #ifndef NET_DISK_CACHE_SIMPLE_SIMPLE_SYNCHRONOUS_ENTRY_H_ |
| 6 #define NET_DISK_CACHE_SIMPLE_SIMPLE_SYNCHRONOUS_ENTRY_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/callback_forward.h" |
| 11 #include "base/files/file_path.h" |
| 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/platform_file.h" |
| 14 #include "base/task_runner.h" |
| 15 #include "base/time.h" |
| 16 #include "net/base/completion_callback.h" |
| 17 |
| 18 namespace base { |
| 19 class SingleThreadTaskRunner; |
| 20 } |
| 21 |
| 22 namespace net { |
| 23 class IOBuffer; |
| 24 } |
| 25 |
| 26 namespace disk_cache { |
| 27 |
| 28 // Worker thread interface to the very simple cache. This interface is not |
| 29 // thread safe, and callers must insure that it is only ever accessed from |
| 30 // a single thread between synchronization points. |
| 31 class SimpleSynchronousEntry { |
| 32 public: |
| 33 typedef base::Callback<void(SimpleSynchronousEntry*)> |
| 34 SynchronousCreationCallback; |
| 35 |
| 36 typedef base::Callback<void(int)> |
| 37 SynchronousOperationCallback; |
| 38 |
| 39 static void OpenEntry( |
| 40 const base::FilePath& path, |
| 41 const std::string& key, |
| 42 const scoped_refptr<base::TaskRunner>& callback_runner, |
| 43 const SynchronousCreationCallback& callback); |
| 44 |
| 45 static void CreateEntry( |
| 46 const base::FilePath& path, |
| 47 const std::string& key, |
| 48 const scoped_refptr<base::TaskRunner>& callback_runner, |
| 49 const SynchronousCreationCallback& callback); |
| 50 |
| 51 // Deletes an entry without first Opening it. Does not check if there is |
| 52 // already an Entry object in memory holding the open files. Be careful! This |
| 53 // is meant to be used by the Backend::DoomEntry() call. |callback| will be |
| 54 // run by |callback_runner|. |
| 55 static void DoomEntry(const base::FilePath& path, |
| 56 const std::string& key, |
| 57 scoped_refptr<base::TaskRunner> callback_runner, |
| 58 const net::CompletionCallback& callback); |
| 59 |
| 60 // N.B. DoomAndClose(), Close(), ReadData() and WriteData() may block on IO. |
| 61 void DoomAndClose(); |
| 62 void Close(); |
| 63 void ReadData(int index, |
| 64 int offset, |
| 65 net::IOBuffer* buf, |
| 66 int buf_len, |
| 67 const SynchronousOperationCallback& callback); |
| 68 void WriteData(int index, |
| 69 int offset, |
| 70 net::IOBuffer* buf, |
| 71 int buf_len, |
| 72 const SynchronousOperationCallback& callback, |
| 73 bool truncate); |
| 74 |
| 75 std::string key() const { return key_; } |
| 76 base::Time last_used() const { return last_used_; } |
| 77 base::Time last_modified() const { return last_modified_; } |
| 78 int32 data_size(int index) const { return data_size_[index]; } |
| 79 |
| 80 private: |
| 81 static const int kIndexCount = 3; |
| 82 |
| 83 SimpleSynchronousEntry( |
| 84 const scoped_refptr<base::TaskRunner>& callback_runner, |
| 85 const base::FilePath& path, |
| 86 const std::string& key); |
| 87 |
| 88 // Like Entry, the SimpleSynchronousEntry self releases when Close() is |
| 89 // called. |
| 90 ~SimpleSynchronousEntry(); |
| 91 |
| 92 bool OpenOrCreateFiles(bool create); |
| 93 bool InitializeForOpen(); |
| 94 bool InitializeForCreate(); |
| 95 |
| 96 scoped_refptr<base::TaskRunner> callback_runner_; |
| 97 const base::FilePath path_; |
| 98 const std::string key_; |
| 99 |
| 100 bool initialized_; |
| 101 |
| 102 base::Time last_used_; |
| 103 base::Time last_modified_; |
| 104 int32 data_size_[kIndexCount]; |
| 105 |
| 106 base::PlatformFile files_[kIndexCount]; |
| 107 }; |
| 108 |
| 109 } // namespace disk_cache |
| 110 |
| 111 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_SYNCHRONOUS_ENTRY_H_ |
OLD | NEW |