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

Side by Side Diff: net/disk_cache/tracing/tracing_cache_backend.cc

Issue 266243004: Clang format slam. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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 #include "net/disk_cache/tracing/tracing_cache_backend.h" 5 #include "net/disk_cache/tracing/tracing_cache_backend.h"
6 6
7 #include "net/base/net_errors.h" 7 #include "net/base/net_errors.h"
8 8
9 namespace disk_cache { 9 namespace disk_cache {
10 10
11 // Proxies entry objects created by the real underlying backend. Backend users 11 // Proxies entry objects created by the real underlying backend. Backend users
12 // will only see the proxy entries. It is necessary for recording the backend 12 // will only see the proxy entries. It is necessary for recording the backend
13 // operations since often non-trivial work is invoked directly on entries. 13 // operations since often non-trivial work is invoked directly on entries.
14 class EntryProxy : public Entry, public base::RefCountedThreadSafe<EntryProxy> { 14 class EntryProxy : public Entry, public base::RefCountedThreadSafe<EntryProxy> {
15 public: 15 public:
16 EntryProxy(Entry *entry, TracingCacheBackend* backend); 16 EntryProxy(Entry* entry, TracingCacheBackend* backend);
17 virtual void Doom() OVERRIDE; 17 virtual void Doom() OVERRIDE;
18 virtual void Close() OVERRIDE; 18 virtual void Close() OVERRIDE;
19 virtual std::string GetKey() const OVERRIDE; 19 virtual std::string GetKey() const OVERRIDE;
20 virtual base::Time GetLastUsed() const OVERRIDE; 20 virtual base::Time GetLastUsed() const OVERRIDE;
21 virtual base::Time GetLastModified() const OVERRIDE; 21 virtual base::Time GetLastModified() const OVERRIDE;
22 virtual int32 GetDataSize(int index) const OVERRIDE; 22 virtual int32 GetDataSize(int index) const OVERRIDE;
23 virtual int ReadData(int index, int offset, IOBuffer* buf, int buf_len, 23 virtual int ReadData(int index,
24 int offset,
25 IOBuffer* buf,
26 int buf_len,
24 const CompletionCallback& callback) OVERRIDE; 27 const CompletionCallback& callback) OVERRIDE;
25 virtual int WriteData(int index, int offset, IOBuffer* buf, int buf_len, 28 virtual int WriteData(int index,
29 int offset,
30 IOBuffer* buf,
31 int buf_len,
26 const CompletionCallback& callback, 32 const CompletionCallback& callback,
27 bool truncate) OVERRIDE; 33 bool truncate) OVERRIDE;
28 virtual int ReadSparseData(int64 offset, IOBuffer* buf, int buf_len, 34 virtual int ReadSparseData(int64 offset,
35 IOBuffer* buf,
36 int buf_len,
29 const CompletionCallback& callback) OVERRIDE; 37 const CompletionCallback& callback) OVERRIDE;
30 virtual int WriteSparseData(int64 offset, IOBuffer* buf, int buf_len, 38 virtual int WriteSparseData(int64 offset,
39 IOBuffer* buf,
40 int buf_len,
31 const CompletionCallback& callback) OVERRIDE; 41 const CompletionCallback& callback) OVERRIDE;
32 virtual int GetAvailableRange(int64 offset, int len, int64* start, 42 virtual int GetAvailableRange(int64 offset,
43 int len,
44 int64* start,
33 const CompletionCallback& callback) OVERRIDE; 45 const CompletionCallback& callback) OVERRIDE;
34 virtual bool CouldBeSparse() const OVERRIDE; 46 virtual bool CouldBeSparse() const OVERRIDE;
35 virtual void CancelSparseIO() OVERRIDE; 47 virtual void CancelSparseIO() OVERRIDE;
36 virtual int ReadyForSparseIO(const CompletionCallback& callback) OVERRIDE; 48 virtual int ReadyForSparseIO(const CompletionCallback& callback) OVERRIDE;
37 49
38 private: 50 private:
39 friend class base::RefCountedThreadSafe<EntryProxy>; 51 friend class base::RefCountedThreadSafe<EntryProxy>;
40 typedef TracingCacheBackend::Operation Operation; 52 typedef TracingCacheBackend::Operation Operation;
41 virtual ~EntryProxy(); 53 virtual ~EntryProxy();
42 54
43 struct RwOpExtra { 55 struct RwOpExtra {
44 int index; 56 int index;
45 int offset; 57 int offset;
46 int buf_len; 58 int buf_len;
47 bool truncate; 59 bool truncate;
48 }; 60 };
49 61
50 void RecordEvent(base::TimeTicks start_time, Operation op, RwOpExtra extra, 62 void RecordEvent(base::TimeTicks start_time,
63 Operation op,
64 RwOpExtra extra,
51 int result_to_record); 65 int result_to_record);
52 void EntryOpComplete(base::TimeTicks start_time, Operation op, 66 void EntryOpComplete(base::TimeTicks start_time,
53 RwOpExtra extra, const CompletionCallback& cb, 67 Operation op,
68 RwOpExtra extra,
69 const CompletionCallback& cb,
54 int result); 70 int result);
55 Entry* entry_; 71 Entry* entry_;
56 base::WeakPtr<TracingCacheBackend> backend_; 72 base::WeakPtr<TracingCacheBackend> backend_;
57 73
58 DISALLOW_COPY_AND_ASSIGN(EntryProxy); 74 DISALLOW_COPY_AND_ASSIGN(EntryProxy);
59 }; 75 };
60 76
61 EntryProxy::EntryProxy(Entry *entry, TracingCacheBackend* backend) 77 EntryProxy::EntryProxy(Entry* entry, TracingCacheBackend* backend)
62 : entry_(entry), 78 : entry_(entry), backend_(backend->AsWeakPtr()) {
63 backend_(backend->AsWeakPtr()) {
64 } 79 }
65 80
66 void EntryProxy::Doom() { 81 void EntryProxy::Doom() {
67 // TODO(pasko): Record the event. 82 // TODO(pasko): Record the event.
68 entry_->Doom(); 83 entry_->Doom();
69 } 84 }
70 85
71 void EntryProxy::Close() { 86 void EntryProxy::Close() {
72 // TODO(pasko): Record the event. 87 // TODO(pasko): Record the event.
73 entry_->Close(); 88 entry_->Close();
74 Release(); 89 Release();
75 } 90 }
76 91
77 std::string EntryProxy::GetKey() const { 92 std::string EntryProxy::GetKey() const {
78 return entry_->GetKey(); 93 return entry_->GetKey();
79 } 94 }
80 95
81 base::Time EntryProxy::GetLastUsed() const { 96 base::Time EntryProxy::GetLastUsed() const {
82 return entry_->GetLastUsed(); 97 return entry_->GetLastUsed();
83 } 98 }
84 99
85 base::Time EntryProxy::GetLastModified() const { 100 base::Time EntryProxy::GetLastModified() const {
86 return entry_->GetLastModified(); 101 return entry_->GetLastModified();
87 } 102 }
88 103
89 int32 EntryProxy::GetDataSize(int index) const { 104 int32 EntryProxy::GetDataSize(int index) const {
90 return entry_->GetDataSize(index); 105 return entry_->GetDataSize(index);
91 } 106 }
92 107
93 int EntryProxy::ReadData(int index, int offset, IOBuffer* buf, int buf_len, 108 int EntryProxy::ReadData(int index,
109 int offset,
110 IOBuffer* buf,
111 int buf_len,
94 const CompletionCallback& callback) { 112 const CompletionCallback& callback) {
95 base::TimeTicks start_time = base::TimeTicks::Now(); 113 base::TimeTicks start_time = base::TimeTicks::Now();
96 RwOpExtra extra; 114 RwOpExtra extra;
97 extra.index = index; 115 extra.index = index;
98 extra.offset = offset; 116 extra.offset = offset;
99 extra.buf_len = buf_len; 117 extra.buf_len = buf_len;
100 extra.truncate = false; 118 extra.truncate = false;
101 int rv = entry_->ReadData( 119 int rv = entry_->ReadData(index,
102 index, offset, buf, buf_len, 120 offset,
103 base::Bind(&EntryProxy::EntryOpComplete, this, start_time, 121 buf,
104 TracingCacheBackend::OP_READ, extra, callback)); 122 buf_len,
123 base::Bind(&EntryProxy::EntryOpComplete,
124 this,
125 start_time,
126 TracingCacheBackend::OP_READ,
127 extra,
128 callback));
105 if (rv != net::ERR_IO_PENDING) { 129 if (rv != net::ERR_IO_PENDING) {
106 RecordEvent(start_time, TracingCacheBackend::OP_READ, extra, rv); 130 RecordEvent(start_time, TracingCacheBackend::OP_READ, extra, rv);
107 } 131 }
108 return rv; 132 return rv;
109 } 133 }
110 134
111 int EntryProxy::WriteData(int index, int offset, IOBuffer* buf, int buf_len, 135 int EntryProxy::WriteData(int index,
112 const CompletionCallback& callback, 136 int offset,
113 bool truncate) { 137 IOBuffer* buf,
138 int buf_len,
139 const CompletionCallback& callback,
140 bool truncate) {
114 base::TimeTicks start_time = base::TimeTicks::Now(); 141 base::TimeTicks start_time = base::TimeTicks::Now();
115 RwOpExtra extra; 142 RwOpExtra extra;
116 extra.index = index; 143 extra.index = index;
117 extra.offset = offset; 144 extra.offset = offset;
118 extra.buf_len = buf_len; 145 extra.buf_len = buf_len;
119 extra.truncate = truncate; 146 extra.truncate = truncate;
120 int rv = entry_->WriteData(index, offset, buf, buf_len, 147 int rv = entry_->WriteData(index,
121 base::Bind(&EntryProxy::EntryOpComplete, this, start_time, 148 offset,
122 TracingCacheBackend::OP_WRITE, extra, callback), 149 buf,
123 truncate); 150 buf_len,
151 base::Bind(&EntryProxy::EntryOpComplete,
152 this,
153 start_time,
154 TracingCacheBackend::OP_WRITE,
155 extra,
156 callback),
157 truncate);
124 if (rv != net::ERR_IO_PENDING) { 158 if (rv != net::ERR_IO_PENDING) {
125 RecordEvent(start_time, TracingCacheBackend::OP_WRITE, extra, rv); 159 RecordEvent(start_time, TracingCacheBackend::OP_WRITE, extra, rv);
126 } 160 }
127 return rv; 161 return rv;
128 } 162 }
129 163
130 int EntryProxy::ReadSparseData(int64 offset, IOBuffer* buf, int buf_len, 164 int EntryProxy::ReadSparseData(int64 offset,
131 const CompletionCallback& callback) { 165 IOBuffer* buf,
166 int buf_len,
167 const CompletionCallback& callback) {
132 // TODO(pasko): Record the event. 168 // TODO(pasko): Record the event.
133 return entry_->ReadSparseData(offset, buf, buf_len, callback); 169 return entry_->ReadSparseData(offset, buf, buf_len, callback);
134 } 170 }
135 171
136 int EntryProxy::WriteSparseData(int64 offset, IOBuffer* buf, int buf_len, 172 int EntryProxy::WriteSparseData(int64 offset,
137 const CompletionCallback& callback) { 173 IOBuffer* buf,
174 int buf_len,
175 const CompletionCallback& callback) {
138 // TODO(pasko): Record the event. 176 // TODO(pasko): Record the event.
139 return entry_->WriteSparseData(offset, buf, buf_len, callback); 177 return entry_->WriteSparseData(offset, buf, buf_len, callback);
140 } 178 }
141 179
142 int EntryProxy::GetAvailableRange(int64 offset, int len, int64* start, 180 int EntryProxy::GetAvailableRange(int64 offset,
143 const CompletionCallback& callback) { 181 int len,
182 int64* start,
183 const CompletionCallback& callback) {
144 return entry_->GetAvailableRange(offset, len, start, callback); 184 return entry_->GetAvailableRange(offset, len, start, callback);
145 } 185 }
146 186
147 bool EntryProxy::CouldBeSparse() const { 187 bool EntryProxy::CouldBeSparse() const {
148 return entry_->CouldBeSparse(); 188 return entry_->CouldBeSparse();
149 } 189 }
150 190
151 void EntryProxy::CancelSparseIO() { 191 void EntryProxy::CancelSparseIO() {
152 return entry_->CancelSparseIO(); 192 return entry_->CancelSparseIO();
153 } 193 }
154 194
155 int EntryProxy::ReadyForSparseIO(const CompletionCallback& callback) { 195 int EntryProxy::ReadyForSparseIO(const CompletionCallback& callback) {
156 return entry_->ReadyForSparseIO(callback); 196 return entry_->ReadyForSparseIO(callback);
157 } 197 }
158 198
159 void EntryProxy::RecordEvent(base::TimeTicks start_time, Operation op, 199 void EntryProxy::RecordEvent(base::TimeTicks start_time,
160 RwOpExtra extra, int result_to_record) { 200 Operation op,
201 RwOpExtra extra,
202 int result_to_record) {
161 // TODO(pasko): Implement. 203 // TODO(pasko): Implement.
162 } 204 }
163 205
164 void EntryProxy::EntryOpComplete(base::TimeTicks start_time, Operation op, 206 void EntryProxy::EntryOpComplete(base::TimeTicks start_time,
165 RwOpExtra extra, const CompletionCallback& cb, 207 Operation op,
208 RwOpExtra extra,
209 const CompletionCallback& cb,
166 int result) { 210 int result) {
167 RecordEvent(start_time, op, extra, result); 211 RecordEvent(start_time, op, extra, result);
168 if (!cb.is_null()) { 212 if (!cb.is_null()) {
169 cb.Run(result); 213 cb.Run(result);
170 } 214 }
171 } 215 }
172 216
173 EntryProxy::~EntryProxy() { 217 EntryProxy::~EntryProxy() {
174 if (backend_.get()) { 218 if (backend_.get()) {
175 backend_->OnDeleteEntry(entry_); 219 backend_->OnDeleteEntry(entry_);
176 } 220 }
177 } 221 }
178 222
179 TracingCacheBackend::TracingCacheBackend(scoped_ptr<Backend> backend) 223 TracingCacheBackend::TracingCacheBackend(scoped_ptr<Backend> backend)
180 : backend_(backend.Pass()) { 224 : backend_(backend.Pass()) {
181 } 225 }
182 226
183 TracingCacheBackend::~TracingCacheBackend() { 227 TracingCacheBackend::~TracingCacheBackend() {
184 } 228 }
185 229
186 net::CacheType TracingCacheBackend::GetCacheType() const { 230 net::CacheType TracingCacheBackend::GetCacheType() const {
187 return backend_->GetCacheType(); 231 return backend_->GetCacheType();
188 } 232 }
189 233
190 int32 TracingCacheBackend::GetEntryCount() const { 234 int32 TracingCacheBackend::GetEntryCount() const {
191 return backend_->GetEntryCount(); 235 return backend_->GetEntryCount();
192 } 236 }
193 237
194 void TracingCacheBackend::RecordEvent(base::TimeTicks start_time, Operation op, 238 void TracingCacheBackend::RecordEvent(base::TimeTicks start_time,
195 std::string key, Entry* entry, int rv) { 239 Operation op,
240 std::string key,
241 Entry* entry,
242 int rv) {
196 // TODO(pasko): Implement. 243 // TODO(pasko): Implement.
197 } 244 }
198 245
199 EntryProxy* TracingCacheBackend::FindOrCreateEntryProxy(Entry* entry) { 246 EntryProxy* TracingCacheBackend::FindOrCreateEntryProxy(Entry* entry) {
200 EntryProxy* entry_proxy; 247 EntryProxy* entry_proxy;
201 EntryToProxyMap::iterator it = open_entries_.find(entry); 248 EntryToProxyMap::iterator it = open_entries_.find(entry);
202 if (it != open_entries_.end()) { 249 if (it != open_entries_.end()) {
203 entry_proxy = it->second; 250 entry_proxy = it->second;
204 entry_proxy->AddRef(); 251 entry_proxy->AddRef();
205 return entry_proxy; 252 return entry_proxy;
(...skipping 20 matching lines...) Expand all
226 RecordEvent(start_time, op, key, *entry, result); 273 RecordEvent(start_time, op, key, *entry, result);
227 if (*entry) { 274 if (*entry) {
228 *entry = FindOrCreateEntryProxy(*entry); 275 *entry = FindOrCreateEntryProxy(*entry);
229 } 276 }
230 if (!callback.is_null()) { 277 if (!callback.is_null()) {
231 callback.Run(result); 278 callback.Run(result);
232 } 279 }
233 } 280 }
234 281
235 net::CompletionCallback TracingCacheBackend::BindCompletion( 282 net::CompletionCallback TracingCacheBackend::BindCompletion(
236 Operation op, base::TimeTicks start_time, const std::string& key, 283 Operation op,
237 Entry **entry, const net::CompletionCallback& cb) { 284 base::TimeTicks start_time,
285 const std::string& key,
286 Entry** entry,
287 const net::CompletionCallback& cb) {
238 return base::Bind(&TracingCacheBackend::BackendOpComplete, 288 return base::Bind(&TracingCacheBackend::BackendOpComplete,
239 AsWeakPtr(), start_time, op, key, entry, cb); 289 AsWeakPtr(),
290 start_time,
291 op,
292 key,
293 entry,
294 cb);
240 } 295 }
241 296
242 int TracingCacheBackend::OpenEntry(const std::string& key, Entry** entry, 297 int TracingCacheBackend::OpenEntry(const std::string& key,
298 Entry** entry,
243 const CompletionCallback& callback) { 299 const CompletionCallback& callback) {
244 DCHECK(*entry == NULL); 300 DCHECK(*entry == NULL);
245 base::TimeTicks start_time = base::TimeTicks::Now(); 301 base::TimeTicks start_time = base::TimeTicks::Now();
246 int rv = backend_->OpenEntry(key, entry, 302 int rv = backend_->OpenEntry(
247 BindCompletion(OP_OPEN, start_time, key, entry, 303 key, entry, BindCompletion(OP_OPEN, start_time, key, entry, callback));
248 callback));
249 if (rv != net::ERR_IO_PENDING) { 304 if (rv != net::ERR_IO_PENDING) {
250 RecordEvent(start_time, OP_OPEN, key, *entry, rv); 305 RecordEvent(start_time, OP_OPEN, key, *entry, rv);
251 if (*entry) { 306 if (*entry) {
252 *entry = FindOrCreateEntryProxy(*entry); 307 *entry = FindOrCreateEntryProxy(*entry);
253 } 308 }
254 } 309 }
255 return rv; 310 return rv;
256 } 311 }
257 312
258 int TracingCacheBackend::CreateEntry(const std::string& key, Entry** entry, 313 int TracingCacheBackend::CreateEntry(const std::string& key,
314 Entry** entry,
259 const CompletionCallback& callback) { 315 const CompletionCallback& callback) {
260 base::TimeTicks start_time = base::TimeTicks::Now(); 316 base::TimeTicks start_time = base::TimeTicks::Now();
261 int rv = backend_->CreateEntry(key, entry, 317 int rv = backend_->CreateEntry(
262 BindCompletion(OP_CREATE, start_time, key, 318 key, entry, BindCompletion(OP_CREATE, start_time, key, entry, callback));
263 entry, callback));
264 if (rv != net::ERR_IO_PENDING) { 319 if (rv != net::ERR_IO_PENDING) {
265 RecordEvent(start_time, OP_CREATE, key, *entry, rv); 320 RecordEvent(start_time, OP_CREATE, key, *entry, rv);
266 if (*entry) { 321 if (*entry) {
267 *entry = FindOrCreateEntryProxy(*entry); 322 *entry = FindOrCreateEntryProxy(*entry);
268 } 323 }
269 } 324 }
270 return rv; 325 return rv;
271 } 326 }
272 327
273 int TracingCacheBackend::DoomEntry(const std::string& key, 328 int TracingCacheBackend::DoomEntry(const std::string& key,
274 const CompletionCallback& callback) { 329 const CompletionCallback& callback) {
275 base::TimeTicks start_time = base::TimeTicks::Now(); 330 base::TimeTicks start_time = base::TimeTicks::Now();
276 int rv = backend_->DoomEntry(key, BindCompletion(OP_DOOM_ENTRY, 331 int rv = backend_->DoomEntry(
277 start_time, key, NULL, 332 key, BindCompletion(OP_DOOM_ENTRY, start_time, key, NULL, callback));
278 callback));
279 if (rv != net::ERR_IO_PENDING) { 333 if (rv != net::ERR_IO_PENDING) {
280 RecordEvent(start_time, OP_DOOM_ENTRY, key, NULL, rv); 334 RecordEvent(start_time, OP_DOOM_ENTRY, key, NULL, rv);
281 } 335 }
282 return rv; 336 return rv;
283 } 337 }
284 338
285 int TracingCacheBackend::DoomAllEntries(const CompletionCallback& callback) { 339 int TracingCacheBackend::DoomAllEntries(const CompletionCallback& callback) {
286 return backend_->DoomAllEntries(callback); 340 return backend_->DoomAllEntries(callback);
287 } 341 }
288 342
289 int TracingCacheBackend::DoomEntriesBetween(base::Time initial_time, 343 int TracingCacheBackend::DoomEntriesBetween(base::Time initial_time,
290 base::Time end_time, 344 base::Time end_time,
291 const CompletionCallback& cb) { 345 const CompletionCallback& cb) {
292 return backend_->DoomEntriesBetween(initial_time, end_time, cb); 346 return backend_->DoomEntriesBetween(initial_time, end_time, cb);
293 } 347 }
294 348
295 int TracingCacheBackend::DoomEntriesSince(base::Time initial_time, 349 int TracingCacheBackend::DoomEntriesSince(base::Time initial_time,
296 const CompletionCallback& callback) { 350 const CompletionCallback& callback) {
297 return backend_->DoomEntriesSince(initial_time, callback); 351 return backend_->DoomEntriesSince(initial_time, callback);
298 } 352 }
299 353
300 int TracingCacheBackend::OpenNextEntry(void** iter, Entry** next_entry, 354 int TracingCacheBackend::OpenNextEntry(void** iter,
355 Entry** next_entry,
301 const CompletionCallback& callback) { 356 const CompletionCallback& callback) {
302 return backend_->OpenNextEntry(iter, next_entry, callback); 357 return backend_->OpenNextEntry(iter, next_entry, callback);
303 } 358 }
304 359
305 void TracingCacheBackend::EndEnumeration(void** iter) { 360 void TracingCacheBackend::EndEnumeration(void** iter) {
306 return backend_->EndEnumeration(iter); 361 return backend_->EndEnumeration(iter);
307 } 362 }
308 363
309 void TracingCacheBackend::GetStats(StatsItems* stats) { 364 void TracingCacheBackend::GetStats(StatsItems* stats) {
310 return backend_->GetStats(stats); 365 return backend_->GetStats(stats);
311 } 366 }
312 367
313 void TracingCacheBackend::OnExternalCacheHit(const std::string& key) { 368 void TracingCacheBackend::OnExternalCacheHit(const std::string& key) {
314 return backend_->OnExternalCacheHit(key); 369 return backend_->OnExternalCacheHit(key);
315 } 370 }
316 371
317 } // namespace disk_cache 372 } // namespace disk_cache
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698