OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 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_SIMPLE_SIMPLE_SYNCHRONOUS_ENTRY_H_ | 5 #ifndef NET_DISK_CACHE_SIMPLE_SIMPLE_SYNCHRONOUS_ENTRY_H_ |
6 #define NET_DISK_CACHE_SIMPLE_SIMPLE_SYNCHRONOUS_ENTRY_H_ | 6 #define NET_DISK_CACHE_SIMPLE_SIMPLE_SYNCHRONOUS_ENTRY_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/callback_forward.h" | 10 #include "base/callback_forward.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 typedef base::Callback<void(SimpleSynchronousEntry* new_entry)> | 38 typedef base::Callback<void(SimpleSynchronousEntry* new_entry)> |
39 SynchronousCreationCallback; | 39 SynchronousCreationCallback; |
40 | 40 |
41 // Callback type for IO operations on an entry not requiring special callback | 41 // Callback type for IO operations on an entry not requiring special callback |
42 // arguments (e.g. Write). |result| is a net::Error result code. | 42 // arguments (e.g. Write). |result| is a net::Error result code. |
43 typedef base::Callback<void(int result)> SynchronousOperationCallback; | 43 typedef base::Callback<void(int result)> SynchronousOperationCallback; |
44 | 44 |
45 static void OpenEntry( | 45 static void OpenEntry( |
46 const base::FilePath& path, | 46 const base::FilePath& path, |
47 const std::string& key, | 47 const std::string& key, |
48 const scoped_refptr<base::TaskRunner>& callback_runner, | 48 base::SingleThreadTaskRunner* callback_runner, |
49 const SynchronousCreationCallback& callback); | 49 const SynchronousCreationCallback& callback); |
50 | 50 |
51 static void CreateEntry( | 51 static void CreateEntry( |
52 const base::FilePath& path, | 52 const base::FilePath& path, |
53 const std::string& key, | 53 const std::string& key, |
54 const scoped_refptr<base::TaskRunner>& callback_runner, | 54 base::SingleThreadTaskRunner* callback_runner, |
55 const SynchronousCreationCallback& callback); | 55 const SynchronousCreationCallback& callback); |
56 | 56 |
57 // Deletes an entry without first Opening it. Does not check if there is | 57 // Deletes an entry without first Opening it. Does not check if there is |
58 // already an Entry object in memory holding the open files. Be careful! This | 58 // already an Entry object in memory holding the open files. Be careful! This |
59 // is meant to be used by the Backend::DoomEntry() call. |callback| will be | 59 // is meant to be used by the Backend::DoomEntry() call. |callback| will be |
60 // run by |callback_runner|. | 60 // run by |callback_runner|. |
61 static void DoomEntry(const base::FilePath& path, | 61 static void DoomEntry(const base::FilePath& path, |
62 const std::string& key, | 62 const std::string& key, |
63 const scoped_refptr<base::TaskRunner>& callback_runner, | 63 base::SingleThreadTaskRunner* callback_runner, |
64 const net::CompletionCallback& callback); | 64 const net::CompletionCallback& callback); |
65 | 65 |
66 // N.B. Close(), ReadData() and WriteData() may block on IO. | 66 // N.B. Close(), ReadData() and WriteData() may block on IO. |
67 void Close(); | 67 void Close(); |
68 void ReadData(int index, | 68 void ReadData(int index, |
69 int offset, | 69 int offset, |
70 net::IOBuffer* buf, | 70 net::IOBuffer* buf, |
71 int buf_len, | 71 int buf_len, |
72 const SynchronousOperationCallback& callback); | 72 const SynchronousOperationCallback& callback); |
73 void WriteData(int index, | 73 void WriteData(int index, |
74 int offset, | 74 int offset, |
75 net::IOBuffer* buf, | 75 net::IOBuffer* buf, |
76 int buf_len, | 76 int buf_len, |
77 const SynchronousOperationCallback& callback, | 77 const SynchronousOperationCallback& callback, |
78 bool truncate); | 78 bool truncate); |
79 | 79 |
80 const base::FilePath& path() const { return path_; } | 80 const base::FilePath& path() const { return path_; } |
81 std::string key() const { return key_; } | 81 std::string key() const { return key_; } |
82 base::Time last_used() const { return last_used_; } | 82 base::Time last_used() const { return last_used_; } |
83 base::Time last_modified() const { return last_modified_; } | 83 base::Time last_modified() const { return last_modified_; } |
84 int32 data_size(int index) const { return data_size_[index]; } | 84 int32 data_size(int index) const { return data_size_[index]; } |
85 | 85 |
86 int64 GetFileSize() const; | 86 int64 GetFileSize() const; |
87 | 87 |
88 private: | 88 private: |
89 SimpleSynchronousEntry( | 89 SimpleSynchronousEntry( |
90 const scoped_refptr<base::TaskRunner>& callback_runner, | 90 base::SingleThreadTaskRunner* callback_runner, |
91 const base::FilePath& path, | 91 const base::FilePath& path, |
92 const std::string& key); | 92 const std::string& key); |
93 | 93 |
94 // Like Entry, the SimpleSynchronousEntry self releases when Close() is | 94 // Like Entry, the SimpleSynchronousEntry self releases when Close() is |
95 // called. | 95 // called. |
96 ~SimpleSynchronousEntry(); | 96 ~SimpleSynchronousEntry(); |
97 | 97 |
98 bool OpenOrCreateFiles(bool create); | 98 bool OpenOrCreateFiles(bool create); |
99 | 99 |
100 // Returns a net::Error, i.e. net::OK on success. | 100 // Returns a net::Error, i.e. net::OK on success. |
101 int InitializeForOpen(); | 101 int InitializeForOpen(); |
102 | 102 |
103 // Returns a net::Error, including net::OK on success and net::FILE_EXISTS | 103 // Returns a net::Error, including net::OK on success and net::FILE_EXISTS |
104 // when the entry already exists. | 104 // when the entry already exists. |
105 int InitializeForCreate(); | 105 int InitializeForCreate(); |
106 | 106 |
107 void Doom(); | 107 void Doom(); |
108 | 108 |
109 scoped_refptr<base::TaskRunner> callback_runner_; | 109 scoped_refptr<base::SingleThreadTaskRunner> callback_runner_; |
110 const base::FilePath path_; | 110 const base::FilePath path_; |
111 const std::string key_; | 111 const std::string key_; |
112 | 112 |
113 bool initialized_; | 113 bool initialized_; |
114 | 114 |
115 base::Time last_used_; | 115 base::Time last_used_; |
116 base::Time last_modified_; | 116 base::Time last_modified_; |
117 int32 data_size_[kSimpleEntryFileCount]; | 117 int32 data_size_[kSimpleEntryFileCount]; |
118 | 118 |
119 base::PlatformFile files_[kSimpleEntryFileCount]; | 119 base::PlatformFile files_[kSimpleEntryFileCount]; |
120 }; | 120 }; |
121 | 121 |
122 } // namespace disk_cache | 122 } // namespace disk_cache |
123 | 123 |
124 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_SYNCHRONOUS_ENTRY_H_ | 124 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_SYNCHRONOUS_ENTRY_H_ |
OLD | NEW |