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

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

Issue 14130015: Support overlapping operations on the SimpleEntryImpl. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix a bug in GetDataSize() Created 7 years, 8 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
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_ENTRY_IMPL_H_ 5 #ifndef NET_DISK_CACHE_SIMPLE_SIMPLE_ENTRY_IMPL_H_
6 #define NET_DISK_CACHE_SIMPLE_SIMPLE_ENTRY_IMPL_H_ 6 #define NET_DISK_CACHE_SIMPLE_SIMPLE_ENTRY_IMPL_H_
7 7
8 #include <queue>
8 #include <string> 9 #include <string>
9 10
10 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
11 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
12 #include "base/threading/thread_checker.h" 13 #include "base/threading/thread_checker.h"
13 #include "net/disk_cache/disk_cache.h" 14 #include "net/disk_cache/disk_cache.h"
14 #include "net/disk_cache/simple/simple_entry_format.h" 15 #include "net/disk_cache/simple/simple_entry_format.h"
15 #include "net/disk_cache/simple/simple_index.h" 16 #include "net/disk_cache/simple/simple_index.h"
16 17
17 18
(...skipping 20 matching lines...) Expand all
38 const base::FilePath& path, 39 const base::FilePath& path,
39 const std::string& key, 40 const std::string& key,
40 Entry** entry, 41 Entry** entry,
41 const CompletionCallback& callback); 42 const CompletionCallback& callback);
42 43
43 static int DoomEntry(base::WeakPtr<SimpleIndex> index, 44 static int DoomEntry(base::WeakPtr<SimpleIndex> index,
44 const base::FilePath& path, 45 const base::FilePath& path,
45 const std::string& key, 46 const std::string& key,
46 const CompletionCallback& callback); 47 const CompletionCallback& callback);
47 48
49 std::string key() const { return key_; }
50 void RunNextOperationIfNeeded();
51
48 // From Entry: 52 // From Entry:
49 virtual void Doom() OVERRIDE; 53 virtual void Doom() OVERRIDE;
50 virtual void Close() OVERRIDE; 54 virtual void Close() OVERRIDE;
51 virtual std::string GetKey() const OVERRIDE; 55 virtual std::string GetKey() const OVERRIDE;
52 virtual base::Time GetLastUsed() const OVERRIDE; 56 virtual base::Time GetLastUsed() const OVERRIDE;
53 virtual base::Time GetLastModified() const OVERRIDE; 57 virtual base::Time GetLastModified() const OVERRIDE;
54 virtual int32 GetDataSize(int index) const OVERRIDE; 58 virtual int32 GetDataSize(int index) const OVERRIDE;
55 virtual int ReadData(int index, 59 virtual int ReadData(int index,
56 int offset, 60 int offset,
57 net::IOBuffer* buf, 61 net::IOBuffer* buf,
58 int buf_len, 62 int buf_len,
59 const CompletionCallback& callback) OVERRIDE; 63 const CompletionCallback& callback) OVERRIDE;
64
60 virtual int WriteData(int index, 65 virtual int WriteData(int index,
61 int offset, 66 int offset,
62 net::IOBuffer* buf, 67 net::IOBuffer* buf,
63 int buf_len, 68 int buf_len,
64 const CompletionCallback& callback, 69 const CompletionCallback& callback,
65 bool truncate) OVERRIDE; 70 bool truncate) OVERRIDE;
66 virtual int ReadSparseData(int64 offset, 71 virtual int ReadSparseData(int64 offset,
67 net::IOBuffer* buf, 72 net::IOBuffer* buf,
68 int buf_len, 73 int buf_len,
69 const CompletionCallback& callback) OVERRIDE; 74 const CompletionCallback& callback) OVERRIDE;
70 virtual int WriteSparseData(int64 offset, 75 virtual int WriteSparseData(int64 offset,
71 net::IOBuffer* buf, 76 net::IOBuffer* buf,
72 int buf_len, 77 int buf_len,
73 const CompletionCallback& callback) OVERRIDE; 78 const CompletionCallback& callback) OVERRIDE;
74 virtual int GetAvailableRange(int64 offset, 79 virtual int GetAvailableRange(int64 offset,
75 int len, 80 int len,
76 int64* start, 81 int64* start,
77 const CompletionCallback& callback) OVERRIDE; 82 const CompletionCallback& callback) OVERRIDE;
78 virtual bool CouldBeSparse() const OVERRIDE; 83 virtual bool CouldBeSparse() const OVERRIDE;
79 virtual void CancelSparseIO() OVERRIDE; 84 virtual void CancelSparseIO() OVERRIDE;
80 virtual int ReadyForSparseIO(const CompletionCallback& callback) OVERRIDE; 85 virtual int ReadyForSparseIO(const CompletionCallback& callback) OVERRIDE;
81 86
82 private: 87 private:
83 SimpleEntryImpl(SimpleSynchronousEntry* synchronous_entry, 88 SimpleEntryImpl(SimpleSynchronousEntry* synchronous_entry,
84 base::WeakPtr<SimpleIndex> index); 89 base::WeakPtr<SimpleIndex> index);
85 90
86 virtual ~SimpleEntryImpl(); 91 virtual ~SimpleEntryImpl();
87 92
93 void DoomInternal();
94
95 void ReadDataInternal(int index,
96 int offset,
97 scoped_refptr<net::IOBuffer> buf,
98 int buf_len,
99 const CompletionCallback& callback);
100 void WriteDataInternal(int index,
101 int offset,
102 scoped_refptr<net::IOBuffer> buf,
103 int buf_len,
104 const CompletionCallback& callback,
105 bool truncate);
106
107
108
88 // Called after a SimpleSynchronousEntry has completed CreateEntry() or 109 // Called after a SimpleSynchronousEntry has completed CreateEntry() or
89 // OpenEntry(). Constructs the new SimpleEntryImpl (if |result| is net::OK) 110 // OpenEntry(). Constructs the new SimpleEntryImpl (if |result| is net::OK)
90 // and passes it back to the caller via |out_entry|. Also runs 111 // and passes it back to the caller via |out_entry|. Also runs
91 // |completion_callback|. 112 // |completion_callback|.
92 static void CreationOperationComplete( 113 static void CreationOperationComplete(
93 base::WeakPtr<SimpleIndex> index, 114 base::WeakPtr<SimpleIndex> index,
94 const CompletionCallback& completion_callback, 115 const CompletionCallback& completion_callback,
95 const std::string& key, 116 const std::string& key,
96 Entry** out_entry, 117 Entry** out_entry,
97 SimpleSynchronousEntry* sync_entry); 118 SimpleSynchronousEntry* sync_entry);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 // |synchronous_entry_in_use_by_worker_| is false (i.e. when an operation 155 // |synchronous_entry_in_use_by_worker_| is false (i.e. when an operation
135 // is not pending on the worker pool). When an operation is pending on the 156 // is not pending on the worker pool). When an operation is pending on the
136 // worker pool, the |synchronous_entry_| is owned by itself. 157 // worker pool, the |synchronous_entry_| is owned by itself.
137 SimpleSynchronousEntry* synchronous_entry_; 158 SimpleSynchronousEntry* synchronous_entry_;
138 159
139 // Set to true when a worker operation is posted on the |synchronous_entry_|, 160 // Set to true when a worker operation is posted on the |synchronous_entry_|,
140 // and false after. Used to ensure thread safety by not allowing multiple 161 // and false after. Used to ensure thread safety by not allowing multiple
141 // threads to access the |synchronous_entry_| simultaneously. 162 // threads to access the |synchronous_entry_| simultaneously.
142 bool synchronous_entry_in_use_by_worker_; 163 bool synchronous_entry_in_use_by_worker_;
143 164
165 bool read_only_operation_;
166 std::queue<base::Closure> operations_;
167
168
144 base::WeakPtr<SimpleIndex> index_; 169 base::WeakPtr<SimpleIndex> index_;
145 }; 170 };
146 171
147 } // namespace disk_cache 172 } // namespace disk_cache
148 173
149 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_ENTRY_IMPL_H_ 174 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_ENTRY_IMPL_H_
OLDNEW
« no previous file with comments | « no previous file | net/disk_cache/simple/simple_entry_impl.cc » ('j') | net/disk_cache/simple/simple_entry_impl.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698