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

Side by Side Diff: net/http/infinite_cache.h

Issue 10909136: Http Cache: Add code for simulating an infinite HTTP cache. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 3 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
« no previous file with comments | « net/http/http_cache_transaction.cc ('k') | net/http/infinite_cache.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(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"
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 {
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 must_doom_entry_;
67 DISALLOW_COPY_AND_ASSIGN(InfiniteCacheTransaction);
68 };
69
70 // An InfiniteCache is paired with an HttpCache instance to simulate an infinite
71 // backend storage.
72 class NET_EXPORT_PRIVATE InfiniteCache
73 : public base::SupportsWeakPtr<InfiniteCache> {
74 public:
75 InfiniteCache();
76 ~InfiniteCache();
77
78 // Initializes this object to start tracking requests. |path| is the location
79 // of the file to use to store data; it can be empty, in which case the data
80 // will not be persisted to disk.
81 void Init(const FilePath& path);
82
83 InfiniteCacheTransaction* CreateInfiniteCacheTransaction();
84
85 // Removes all data for this experiment. Returns a net error code.
86 int DeleteData(const CompletionCallback& callback);
87
88 // Removes requests between |initial_time| and |end_time|.
89 int DeleteDataBetween(base::Time initial_time,
90 base::Time end_time,
91 const CompletionCallback& callback);
92
93 // Returns the number of elements currently tracked.
94 int QueryItemsForTest(const CompletionCallback& callback);
95
96 // Flush the data to disk, preventing flushing when the destructor runs. Any
97 // data added to the cache after calling this method will not be written to
98 // disk, unless this method is called again to do so.
99 int FlushDataForTest(const CompletionCallback& callback);
100
101 private:
102 class Worker;
103 friend class base::RepeatingTimer<InfiniteCache>;
104 friend class InfiniteCacheTransaction;
105
106 std::string GenerateKey(const HttpRequestInfo* request);
107 void ProcessResource(scoped_ptr<InfiniteCacheTransaction::ResourceData> data);
108 void OnTimer();
109
110 scoped_refptr<Worker> worker_;
111 scoped_refptr<base::SequencedWorkerPool> worker_pool_;
112 scoped_refptr<base::SequencedTaskRunner> task_runner_;
113 base::RepeatingTimer<InfiniteCache> timer_;
114
115 DISALLOW_COPY_AND_ASSIGN(InfiniteCache);
116 };
117
118 } // namespace net
119
120 #endif // NET_HTTP_INFINITE_CACHE_H_
OLDNEW
« no previous file with comments | « net/http/http_cache_transaction.cc ('k') | net/http/infinite_cache.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698