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.
5 #ifndef NET_DISK_CACHE_TRACING_TRACING_CACHE_BACKEND_H_
6 #define NET_DISK_CACHE_TRACING_TRACING_CACHE_BACKEND_H_
10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/weak_ptr.h"
12 #include "net/disk_cache/blockfile/stats.h"
13 #include "net/disk_cache/disk_cache.h"
15 namespace disk_cache
{
19 // The TracingCacheBackend implements the Cache Backend interface. It intercepts
20 // all backend operations from the IO thread and records the time from the start
21 // of the operation until the result is delivered.
22 class NET_EXPORT TracingCacheBackend
: public Backend
,
23 public base::SupportsWeakPtr
<TracingCacheBackend
> {
25 explicit TracingCacheBackend(scoped_ptr
<Backend
> backend
);
27 virtual net::CacheType
GetCacheType() const OVERRIDE
;
28 virtual int32
GetEntryCount() const OVERRIDE
;
29 virtual int OpenEntry(const std::string
& key
, Entry
** entry
,
30 const CompletionCallback
& callback
) OVERRIDE
;
31 virtual int CreateEntry(const std::string
& key
, Entry
** entry
,
32 const CompletionCallback
& callback
) OVERRIDE
;
33 virtual int DoomEntry(const std::string
& key
,
34 const CompletionCallback
& callback
) OVERRIDE
;
35 virtual int DoomAllEntries(const CompletionCallback
& callback
) OVERRIDE
;
36 virtual int DoomEntriesBetween(base::Time initial_time
,
38 const CompletionCallback
& callback
) OVERRIDE
;
39 virtual int DoomEntriesSince(base::Time initial_time
,
40 const CompletionCallback
& callback
) OVERRIDE
;
41 virtual int OpenNextEntry(void** iter
, Entry
** next_entry
,
42 const CompletionCallback
& callback
) OVERRIDE
;
43 virtual void EndEnumeration(void** iter
) OVERRIDE
;
44 virtual void GetStats(StatsItems
* stats
) OVERRIDE
;
45 virtual void OnExternalCacheHit(const std::string
& key
) OVERRIDE
;
48 friend class EntryProxy
;
57 virtual ~TracingCacheBackend();
59 EntryProxy
* FindOrCreateEntryProxy(Entry
* entry
);
61 void OnDeleteEntry(Entry
* e
);
63 void RecordEvent(base::TimeTicks start_time
, Operation op
, std::string key
,
64 Entry
* entry
, int result
);
66 void BackendOpComplete(base::TimeTicks start_time
, Operation op
,
67 std::string key
, Entry
** entry
,
68 const CompletionCallback
& callback
, int result
);
70 net::CompletionCallback
BindCompletion(Operation op
,
71 base::TimeTicks start_time
,
72 const std::string
& key
, Entry
**entry
,
73 const net::CompletionCallback
& cb
);
75 scoped_ptr
<Backend
> backend_
;
76 typedef std::map
<Entry
*, EntryProxy
*> EntryToProxyMap
;
77 EntryToProxyMap open_entries_
;
79 DISALLOW_COPY_AND_ASSIGN(TracingCacheBackend
);
82 } // namespace disk_cache
84 #endif // NET_DISK_CACHE_TRACING_TRACING_CACHE_BACKEND_H_