| 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_TRACING_CACHE_BACKEND_H_ | |
| 6 #define NET_DISK_CACHE_TRACING_TRACING_CACHE_BACKEND_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 | |
| 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" | |
| 14 | |
| 15 namespace disk_cache { | |
| 16 | |
| 17 class EntryProxy; | |
| 18 | |
| 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> { | |
| 24 public: | |
| 25 explicit TracingCacheBackend(scoped_ptr<Backend> backend); | |
| 26 | |
| 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, | |
| 37 base::Time end_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; | |
| 46 | |
| 47 private: | |
| 48 friend class EntryProxy; | |
| 49 enum Operation { | |
| 50 OP_OPEN, | |
| 51 OP_CREATE, | |
| 52 OP_DOOM_ENTRY, | |
| 53 OP_READ, | |
| 54 OP_WRITE | |
| 55 }; | |
| 56 | |
| 57 virtual ~TracingCacheBackend(); | |
| 58 | |
| 59 EntryProxy* FindOrCreateEntryProxy(Entry* entry); | |
| 60 | |
| 61 void OnDeleteEntry(Entry* e); | |
| 62 | |
| 63 void RecordEvent(base::TimeTicks start_time, Operation op, std::string key, | |
| 64 Entry* entry, int result); | |
| 65 | |
| 66 void BackendOpComplete(base::TimeTicks start_time, Operation op, | |
| 67 std::string key, Entry** entry, | |
| 68 const CompletionCallback& callback, int result); | |
| 69 | |
| 70 net::CompletionCallback BindCompletion(Operation op, | |
| 71 base::TimeTicks start_time, | |
| 72 const std::string& key, Entry **entry, | |
| 73 const net::CompletionCallback& cb); | |
| 74 | |
| 75 scoped_ptr<Backend> backend_; | |
| 76 typedef std::map<Entry*, EntryProxy*> EntryToProxyMap; | |
| 77 EntryToProxyMap open_entries_; | |
| 78 | |
| 79 DISALLOW_COPY_AND_ASSIGN(TracingCacheBackend); | |
| 80 }; | |
| 81 | |
| 82 } // namespace disk_cache | |
| 83 | |
| 84 #endif // NET_DISK_CACHE_TRACING_TRACING_CACHE_BACKEND_H_ | |
| OLD | NEW |