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

Side by Side Diff: net/url_request/view_cache_helper.h

Issue 2168004: view-cache: Refactor ViewCacheHelper and ViewHttpCacheJobFactory... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 6 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/net.gyp ('k') | net/url_request/view_cache_helper.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef NET_URL_REQUEST_VIEW_CACHE_HELPER_H_ 5 #ifndef NET_URL_REQUEST_VIEW_CACHE_HELPER_H_
6 #define NET_URL_REQUEST_VIEW_CACHE_HELPER_H_ 6 #define NET_URL_REQUEST_VIEW_CACHE_HELPER_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "net/base/completion_callback.h"
11 #include "net/base/io_buffer.h"
12
10 class URLRequestContext; 13 class URLRequestContext;
11 14
15 namespace disk_cache {
16 class Backend;
17 class Entry;
18 }
19
20 namespace net {
21
12 class ViewCacheHelper { 22 class ViewCacheHelper {
13 public: 23 public:
14 // Formats the cache information for |key| as HTML. 24 ViewCacheHelper()
15 static void GetEntryInfoHTML(const std::string& key, 25 : disk_cache_(NULL), entry_(NULL), iter_(NULL), buf_len_(0), index_(0),
16 URLRequestContext* context, 26 data_(NULL), callback_(NULL), next_state_(STATE_NONE),
17 const std::string& url_prefix, 27 ALLOW_THIS_IN_INITIALIZER_LIST(
18 std::string* out); 28 cache_callback_(this, &ViewCacheHelper::OnIOComplete)),
29 ALLOW_THIS_IN_INITIALIZER_LIST(
30 entry_callback_(new CancelableCompletionCallback<ViewCacheHelper>(
31 this, &ViewCacheHelper::OnIOComplete))) {}
32 ~ViewCacheHelper();
19 33
20 static void GetStatisticsHTML(URLRequestContext* context, 34 // Formats the cache information for |key| as HTML. Returns a net error code.
21 std::string* out); 35 // If this method returns ERR_IO_PENDING, |callback| will be notified when the
36 // operation completes. |out| must remain valid until this operation completes
37 // or the object is destroyed.
38 int GetEntryInfoHTML(const std::string& key, URLRequestContext* context,
39 std::string* out, CompletionCallback* callback);
40
41 // Formats the cache contents as HTML. Returns a net error code.
42 // If this method returns ERR_IO_PENDING, |callback| will be notified when the
43 // operation completes. |out| must remain valid until this operation completes
44 // or the object is destroyed. |url_prefix| will be prepended to each entry
45 // key as a link to the entry.
46 int GetContentsHTML(URLRequestContext* context, const std::string& url_prefix,
47 std::string* out, CompletionCallback* callback);
48
49 private:
50 enum State {
51 STATE_NONE,
52 STATE_GET_BACKEND,
53 STATE_GET_BACKEND_COMPLETE,
54 STATE_OPEN_NEXT_ENTRY,
55 STATE_OPEN_NEXT_ENTRY_COMPLETE,
56 STATE_OPEN_ENTRY,
57 STATE_OPEN_ENTRY_COMPLETE,
58 STATE_READ_RESPONSE,
59 STATE_READ_RESPONSE_COMPLETE,
60 STATE_READ_DATA,
61 STATE_READ_DATA_COMPLETE
62 };
63
64 // Implements GetEntryInfoHTML and GetContentsHTML.
65 int GetInfoHTML(const std::string& key, URLRequestContext* context,
66 const std::string& url_prefix, std::string* out,
67 CompletionCallback* callback);
68
69 // This is a helper function used to trigger a completion callback. It may
70 // only be called if callback_ is non-null.
71 void DoCallback(int rv);
72
73 // This will trigger the completion callback if appropriate.
74 void HandleResult(int rv);
75
76 // Runs the state transition loop.
77 int DoLoop(int result);
78
79 // Each of these methods corresponds to a State value. If there is an
80 // argument, the value corresponds to the return of the previous state or
81 // corresponding callback.
82 int DoGetBackend();
83 int DoGetBackendComplete(int result);
84 int DoOpenNextEntry();
85 int DoOpenNextEntryComplete(int result);
86 int DoOpenEntry();
87 int DoOpenEntryComplete(int result);
88 int DoReadResponse();
89 int DoReadResponseComplete(int result);
90 int DoReadData();
91 int DoReadDataComplete(int result);
92
93 // Called to signal completion of asynchronous IO.
94 void OnIOComplete(int result);
95
96 scoped_refptr<URLRequestContext> context_;
97 disk_cache::Backend* disk_cache_;
98 disk_cache::Entry* entry_;
99 void* iter_;
100 scoped_refptr<net::IOBuffer> buf_;
101 int buf_len_;
102 int index_;
103
104 std::string key_;
105 std::string url_prefix_;
106 std::string* data_;
107 CompletionCallback* callback_;
108
109 State next_state_;
110
111 CompletionCallbackImpl<ViewCacheHelper> cache_callback_;
112 scoped_refptr<CancelableCompletionCallback<ViewCacheHelper> > entry_callback_;
113
114 DISALLOW_COPY_AND_ASSIGN(ViewCacheHelper);
22 }; 115 };
23 116
117 } // namespace net.
118
24 #endif // NET_URL_REQUEST_VIEW_CACHE_HELPER_H_ 119 #endif // NET_URL_REQUEST_VIEW_CACHE_HELPER_H_
OLDNEW
« no previous file with comments | « net/net.gyp ('k') | net/url_request/view_cache_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698