OLD | NEW |
(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_TRACING_CACHE_BACKEND_H_ |
| 6 #define NET_DISK_CACHE_TRACING_CACHE_BACKEND_H_ |
| 7 |
| 8 #include "base/memory/weak_ptr.h" |
| 9 #include "net/disk_cache/disk_cache.h" |
| 10 #include "net/disk_cache/stats.h" |
| 11 |
| 12 namespace disk_cache { |
| 13 |
| 14 class EntryProxy; |
| 15 |
| 16 // The TracingCacheBackend implements the Cache Backend interface. It intercepts |
| 17 // all backend operations from the IO thread and records the time from the start |
| 18 // of the operation until the result is delivered. |
| 19 class NET_EXPORT TracingCacheBackend : public Backend, |
| 20 public base::SupportsWeakPtr<TracingCacheBackend> { |
| 21 public: |
| 22 explicit TracingCacheBackend(Backend* backend); |
| 23 |
| 24 virtual net::CacheType GetCacheType() const OVERRIDE; |
| 25 virtual int32 GetEntryCount() const OVERRIDE; |
| 26 virtual int OpenEntry(const std::string& key, Entry** entry, |
| 27 const CompletionCallback& callback) OVERRIDE; |
| 28 virtual int CreateEntry(const std::string& key, Entry** entry, |
| 29 const CompletionCallback& callback) OVERRIDE; |
| 30 virtual int DoomEntry(const std::string& key, |
| 31 const CompletionCallback& callback) OVERRIDE; |
| 32 virtual int DoomAllEntries(const CompletionCallback& callback) OVERRIDE; |
| 33 virtual int DoomEntriesBetween(base::Time initial_time, |
| 34 base::Time end_time, |
| 35 const CompletionCallback& callback) OVERRIDE; |
| 36 virtual int DoomEntriesSince(base::Time initial_time, |
| 37 const CompletionCallback& callback) OVERRIDE; |
| 38 virtual int OpenNextEntry(void** iter, Entry** next_entry, |
| 39 const CompletionCallback& callback) OVERRIDE; |
| 40 virtual void EndEnumeration(void** iter) OVERRIDE; |
| 41 virtual void GetStats(StatsItems* stats) OVERRIDE; |
| 42 virtual void OnExternalCacheHit(const std::string& key) OVERRIDE; |
| 43 |
| 44 private: |
| 45 friend class EntryProxy; |
| 46 enum Operation { |
| 47 OP_OPEN, |
| 48 OP_CREATE, |
| 49 OP_DOOM_ENTRY, |
| 50 OP_READ, |
| 51 OP_WRITE |
| 52 }; |
| 53 |
| 54 virtual ~TracingCacheBackend(); |
| 55 |
| 56 EntryProxy* FindOrCreateEntryProxy(Entry* entry); |
| 57 |
| 58 void OnDeleteEntry(Entry* e); |
| 59 |
| 60 void RecordEvent(base::TimeTicks start_time, Operation op, std::string key, |
| 61 Entry* entry, int result); |
| 62 |
| 63 void BackendOpComplete(base::TimeTicks start_time, Operation op, |
| 64 std::string key, Entry** entry, |
| 65 const CompletionCallback& callback, int result); |
| 66 |
| 67 net::CompletionCallback BindCompletion(Operation op, |
| 68 base::TimeTicks start_time, |
| 69 const std::string& key, Entry **entry, |
| 70 const net::CompletionCallback& cb); |
| 71 |
| 72 scoped_ptr<Backend> backend_; |
| 73 typedef std::map<Entry*, EntryProxy*> EntryToProxyMap; |
| 74 EntryToProxyMap open_entries_; |
| 75 |
| 76 DISALLOW_COPY_AND_ASSIGN(TracingCacheBackend); |
| 77 }; |
| 78 |
| 79 } // namespace disk_cache |
| 80 |
| 81 #endif // NET_DISK_CACHE_TRACING_CACHE_BACKEND_H_ |
OLD | NEW |