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

Side by Side Diff: chrome/common/net/url_fetcher.h

Issue 6904057: Schetch changes required to support URLFetcher saving response to a file (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 7 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 // This file contains URLFetcher, a wrapper around net::URLRequest that handles 5 // This file contains URLFetcher, a wrapper around net::URLRequest that handles
6 // low-level details like thread safety, ref counting, and incremental buffer 6 // low-level details like thread safety, ref counting, and incremental buffer
7 // reading. This is useful for callers who simply want to get the data from a 7 // reading. This is useful for callers who simply want to get the data from a
8 // URL and don't care about all the nitty-gritty details. 8 // URL and don't care about all the nitty-gritty details.
9 // 9 //
10 // NOTE(willchan): Only one "IO" thread is supported for URLFetcher. This is a 10 // NOTE(willchan): Only one "IO" thread is supported for URLFetcher. This is a
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 // interception is explicitly enabled in tests. 60 // interception is explicitly enabled in tests.
61 61
62 class URLFetcher { 62 class URLFetcher {
63 public: 63 public:
64 enum RequestType { 64 enum RequestType {
65 GET, 65 GET,
66 POST, 66 POST,
67 HEAD, 67 HEAD,
68 }; 68 };
69 69
70 // Abstract class used to hold the response body. Delegate generates
71 // an implementation of this interface, and gets a pointer to it when
72 // the fetch is complete.
73 class ResponseBodyContainerInterface {
74 public:
75 // Add bytes to the response body.
76 virtual void Append(char* data, int data_length) = 0;
77
78 // If the class supports returning the body as a string, return true
79 // and set |out_body| to the response body. Otherwise, return false.
80 virtual bool GetAsString(std::string* out_body) const = 0;
81 };
82
70 class Delegate { 83 class Delegate {
71 public: 84 public:
72 // This will be called when the URL has been fetched, successfully or not. 85 // This will be called when the URL has been fetched, successfully or not.
73 // |response_code| is the HTTP response code (200, 404, etc.) if 86 // |response_code| is the HTTP response code (200, 404, etc.) if
74 // applicable. |url|, |status| and |data| are all valid until the 87 // applicable. |url|, |status| and |data| are all valid until the
75 // URLFetcher instance is destroyed. 88 // URLFetcher instance is destroyed.
89 virtual void OnURLFetchCompleteNew(
90 const URLFetcher* source,
91 const GURL& url,
92 const net::URLRequestStatus& status,
93 int response_code,
94 const ResponseCookies& cookies,
95 const ResponseBodyContainerInterface& response_body);
96
97 // TODO(skerner): To avoid changing existing code, keep the old
98 // method, whre |data| is a string. Once we finalize interface changes,
99 // this will be removed.
76 virtual void OnURLFetchComplete(const URLFetcher* source, 100 virtual void OnURLFetchComplete(const URLFetcher* source,
77 const GURL& url, 101 const GURL& url,
78 const net::URLRequestStatus& status, 102 const net::URLRequestStatus& status,
79 int response_code, 103 int response_code,
80 const ResponseCookies& cookies, 104 const ResponseCookies& cookies,
81 const std::string& data) = 0; 105 const std::string& data) = 0;
82 106
107 // Get a container into which the response body can be written.
108 // Delegate can control how response is held by the choice of the
109 // concrete type this method returns. For example, to process the
110 // response body as it is received, return a class that does
111 // processing on each call to ResponseBodyContainerInterface::Append().
112 virtual ResponseBodyContainerInterface* CreateResponseBodyContainer();
113
83 protected: 114 protected:
84 virtual ~Delegate() {} 115 virtual ~Delegate() {}
85 }; 116 };
86 117
87 // URLFetcher::Create uses the currently registered Factory to create the 118 // URLFetcher::Create uses the currently registered Factory to create the
88 // URLFetcher. Factory is intended for testing. 119 // URLFetcher. Factory is intended for testing.
89 class Factory { 120 class Factory {
90 public: 121 public:
91 virtual URLFetcher* CreateURLFetcher(int id, 122 virtual URLFetcher* CreateURLFetcher(int id,
92 const GURL& url, 123 const GURL& url,
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 base::TimeDelta backoff_delay_; 264 base::TimeDelta backoff_delay_;
234 // Maximum retries allowed. 265 // Maximum retries allowed.
235 int max_retries_; 266 int max_retries_;
236 267
237 static bool g_interception_enabled; 268 static bool g_interception_enabled;
238 269
239 DISALLOW_COPY_AND_ASSIGN(URLFetcher); 270 DISALLOW_COPY_AND_ASSIGN(URLFetcher);
240 }; 271 };
241 272
242 #endif // CHROME_COMMON_NET_URL_FETCHER_H_ 273 #endif // CHROME_COMMON_NET_URL_FETCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698