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

Side by Side Diff: net/disk_cache/simple/simple_synchronous_entry.h

Issue 12192005: Add new simple disk cache backend. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase before remediation Created 7 years, 10 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 | Annotate | Revision Log
OLDNEW
(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/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 // All callbacks include the pointer to the SynchronousEntry being operated on
34 // if it is valid after the operation.
35 typedef base::Callback<void(SimpleSynchronousEntry*, int)>
36 SynchronousEntryCallback;
37
38 static void OpenEntry(
39 const FilePath& path,
40 const std::string& key,
41 const scoped_refptr<base::TaskRunner>& callback_runner,
42 const SynchronousEntryCallback& callback);
43
44 static void CreateEntry(
45 const FilePath& path,
46 const std::string& key,
47 const scoped_refptr<base::TaskRunner>& callback_runner,
48 const SynchronousEntryCallback& callback);
49
50 // Deletes an entry without first Opening it. Does not check if there is
51 // already an Entry object in memory holding the open files. Be careful! This
52 // is meant to be used by the Backend::DoomEntry() call. |callback| will be
53 // run by |callback_runner|.
54 static void DoomEntry(const FilePath& path,
55 const std::string& key,
56 scoped_refptr<base::TaskRunner> callback_runner,
57 const net::CompletionCallback& callback);
58
59 // N.B. DoomAndClose(), Close(), ReadData() and WriteData() may block on IO.
60 void DoomAndClose();
61 void Close();
62 void ReadData(int index,
63 int offset,
64 net::IOBuffer* buf,
65 int buf_len,
66 const SynchronousEntryCallback& callback);
67 void WriteData(int index,
68 int offset,
69 net::IOBuffer* buf,
70 int buf_len,
71 const SynchronousEntryCallback& callback,
72 bool truncate);
73
74 std::string key() const { return key_; }
75 base::Time last_used() const { return last_used_; }
76 base::Time last_modified() const { return last_modified_; }
77 int32 data_size(int index) const { return data_size_[index]; }
78
79 private:
80 static const int kIndexCount = 3;
81
82 struct EntryStatus {
83 enum Mode {
84 ENTRY_UNINITIALIZED,
85 ENTRY_READER,
86 ENTRY_WRITER,
87 };
88
89 EntryStatus();
90
91 Mode mode;
92 int64 data_offset;
93 };
94
95 SimpleSynchronousEntry(
96 const scoped_refptr<base::TaskRunner>& callback_runner,
97 const FilePath& path,
98 const std::string& key);
99
100 // Like Entry, the SimpleSynchronousEntry self releases when Close() is
101 // called.
102 ~SimpleSynchronousEntry();
103
104 bool OpenOrCreateFiles(bool create);
105 bool InitializeForOpen();
106 bool InitializeForCreate();
107
108 scoped_refptr<base::TaskRunner> callback_runner_;
109 const FilePath path_;
110 const std::string key_;
111
112 bool initialized_;
113
114 base::Time last_used_;
115 base::Time last_modified_;
116 int32 data_size_[kIndexCount];
117
118 base::PlatformFile files_[kIndexCount];
119 EntryStatus status_[kIndexCount];
120 };
121
122 } // namespace disk_cache
123
124 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_SYNCHRONOUS_ENTRY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698