Chromium Code Reviews
|
| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 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 // This is the interface of a simulated infinite cache. The purpose of this | |
| 6 // code is to evaluate the performance of an HTTP cache that is not constrained | |
| 7 // to evict resources. | |
| 8 | |
| 9 #ifndef NET_HTTP_INFINITE_CACHE_H_ | |
| 10 #define NET_HTTP_INFINITE_CACHE_H_ | |
| 11 | |
| 12 #include <string> | |
| 13 | |
| 14 #include "base/basictypes.h" | |
| 15 #include "base/memory/scoped_ptr.h" | |
| 16 #include "base/memory/weak_ptr.h" | |
| 17 #include "base/timer.h" | |
| 18 #include "net/base/completion_callback.h" | |
|
gavinp
2012/09/13 04:45:43
Can't we drop this include?
rvargas (doing something else)
2012/09/13 23:50:28
I cannot forward declare it, because it is a typed
| |
| 19 #include "net/base/net_export.h" | |
| 20 | |
| 21 class FilePath; | |
| 22 | |
| 23 namespace base { | |
| 24 class SequencedTaskRunner; | |
| 25 class SequencedWorkerPool; | |
| 26 } | |
| 27 | |
| 28 namespace net { | |
| 29 | |
| 30 class HttpCache; | |
| 31 class HttpResponseInfo; | |
| 32 class InfiniteCache; | |
| 33 struct HttpRequestInfo; | |
| 34 | |
| 35 // An InfiniteCacheTransaction is paired with an HttpCache::Transaction to track | |
| 36 // every request that goes through the HttpCache. This object is notified when | |
| 37 // relevant steps are reached while processing the request. | |
| 38 class NET_EXPORT_PRIVATE InfiniteCacheTransaction { | |
|
gavinp
2012/09/13 04:45:43
A question: Is the NET_EXPORT_PRIVATE required whe
rvargas (doing something else)
2012/09/13 22:44:07
net_unittests doesn't link in net on the component
| |
| 39 public: | |
| 40 explicit InfiniteCacheTransaction(InfiniteCache* cache); | |
| 41 ~InfiniteCacheTransaction(); | |
| 42 | |
| 43 // Called when a new HttpTransaction is started. | |
| 44 void OnRequestStart(const HttpRequestInfo* request); | |
| 45 | |
| 46 // Called when the response headers are available. | |
| 47 void OnResponseReceived(const HttpResponseInfo* response); | |
| 48 | |
| 49 // Called when the response data is received from the network. | |
| 50 void OnDataRead(const char* data, int data_len); | |
| 51 | |
| 52 // Called when the resource is marked as truncated by the HttpCache. | |
| 53 void OnTruncatedResponse(); | |
| 54 | |
| 55 // Called when the resource is served from the cache, so OnDataRead will not | |
| 56 // be called for this request. | |
| 57 void OnServedFromCache(); | |
| 58 | |
| 59 private: | |
| 60 friend class InfiniteCache; | |
| 61 struct ResourceData; | |
| 62 void Finish(); | |
| 63 | |
| 64 base::WeakPtr<InfiniteCache> cache_; | |
| 65 scoped_ptr<ResourceData> resource_data_; | |
| 66 bool done_; | |
| 67 bool doom_method_; | |
|
gavinp
2012/09/13 04:45:43
Nit: I don't think this is well named. It stores i
rvargas (doing something else)
2012/09/13 22:44:07
I don't get the part about multiple entries, but y
gavinp
2012/09/14 03:27:28
It's just that GETs replace anything with the same
| |
| 68 DISALLOW_COPY_AND_ASSIGN(InfiniteCacheTransaction); | |
| 69 }; | |
| 70 | |
| 71 // An InfiniteCache is paired with an HttpCache instance to simulate an infinite | |
| 72 // backend storage. | |
| 73 class NET_EXPORT_PRIVATE InfiniteCache | |
| 74 : public base::SupportsWeakPtr<InfiniteCache> { | |
| 75 public: | |
| 76 InfiniteCache(); | |
| 77 ~InfiniteCache(); | |
| 78 | |
| 79 // Initializes this object to start tracking requests. |path| is the location | |
| 80 // of the file to use to store data; it can be empty, in which case the data | |
| 81 // will not be persisted to disk. | |
| 82 void Init(const FilePath& path); | |
| 83 | |
| 84 InfiniteCacheTransaction* CreateInfiniteCacheTransaction(); | |
| 85 | |
| 86 // Removes all data for this experiment. Returns a net error code. | |
| 87 int DeleteData(const CompletionCallback& callback); | |
| 88 | |
| 89 // Removes requests between |initial_time| and |end_time|. | |
| 90 int DeleteDataBetween(base::Time initial_time, | |
| 91 base::Time end_time, | |
| 92 const CompletionCallback& callback); | |
| 93 | |
| 94 // Returns the number of elements currently tracked. | |
| 95 int QueryItemsForTest(const CompletionCallback& callback); | |
| 96 | |
| 97 // Flush the data to disk, preventing flushing when the destructor runs. | |
|
gavinp
2012/09/13 04:45:43
Document what happens if we add more data after ca
| |
| 98 int FlushDataForTest(const CompletionCallback& callback); | |
| 99 | |
| 100 private: | |
| 101 class Worker; | |
| 102 friend class base::RepeatingTimer<InfiniteCache>; | |
| 103 friend class InfiniteCacheTransaction; | |
| 104 | |
| 105 std::string GenerateKey(const HttpRequestInfo* request); | |
| 106 void ProcessResource(scoped_ptr<InfiniteCacheTransaction::ResourceData> data); | |
| 107 void OnTimer(); | |
| 108 | |
| 109 scoped_refptr<Worker> worker_; | |
| 110 scoped_refptr<base::SequencedWorkerPool> worker_pool_; | |
| 111 scoped_refptr<base::SequencedTaskRunner> task_runner_; | |
| 112 base::RepeatingTimer<InfiniteCache> timer_; | |
| 113 | |
| 114 DISALLOW_COPY_AND_ASSIGN(InfiniteCache); | |
| 115 }; | |
| 116 | |
| 117 } // namespace net | |
| 118 | |
| 119 #endif // NET_HTTP_INFINITE_CACHE_H_ | |
| OLD | NEW |