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

Side by Side Diff: content/test/test_url_fetcher_factory.cc

Issue 7820003: Add support to download web store promo logos over https. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cleanup Created 9 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
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 #include "content/test/test_url_fetcher_factory.h" 5 #include "content/test/test_url_fetcher_factory.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 // This class is used by the FakeURLFetcherFactory below. 118 // This class is used by the FakeURLFetcherFactory below.
119 class FakeURLFetcher : public URLFetcher { 119 class FakeURLFetcher : public URLFetcher {
120 public: 120 public:
121 // Normal URL fetcher constructor but also takes in a pre-baked response. 121 // Normal URL fetcher constructor but also takes in a pre-baked response.
122 FakeURLFetcher(const GURL& url, RequestType request_type, Delegate* d, 122 FakeURLFetcher(const GURL& url, RequestType request_type, Delegate* d,
123 const std::string& response_data, bool success) 123 const std::string& response_data, bool success)
124 : URLFetcher(url, request_type, d), 124 : URLFetcher(url, request_type, d),
125 url_(url), 125 url_(url),
126 response_data_(response_data), 126 response_data_(response_data),
127 success_(success), 127 success_(success),
128 status_(success ? net::URLRequestStatus::SUCCESS :
129 net::URLRequestStatus::FAILED, 0),
128 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { 130 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {
129 } 131 }
130 132
131 // Start the request. This will call the given delegate asynchronously 133 // Start the request. This will call the given delegate asynchronously
132 // with the pre-baked response as parameter. 134 // with the pre-baked response as parameter.
133 virtual void Start() { 135 virtual void Start() {
134 MessageLoop::current()->PostTask( 136 MessageLoop::current()->PostTask(
135 FROM_HERE, 137 FROM_HERE,
136 method_factory_.NewRunnableMethod(&FakeURLFetcher::RunDelegate)); 138 method_factory_.NewRunnableMethod(&FakeURLFetcher::RunDelegate));
137 } 139 }
138 140
141 // These methods are overriden so we can use the version of
Mihai Parparita -not on Chrome 2011/08/31 23:26:23 Add OVERRIDE to the methods that you're overriding
jstritar 2011/09/01 16:10:13 Done.
142 // OnURLFetchComplete that only has a single URLFetcher argument.
143 virtual const net::ResponseCookies& cookies() const { return cookies_; }
144
145 virtual const std::string& GetResponseStringRef() const {
146 return response_data_;
147 }
148
149 virtual bool GetResponseAsString(std::string* out_response_string) const {
150 *out_response_string = response_data_;
151 return true;
152 }
153
154 virtual int response_code() const { return success_ ? 200 : 500; }
155
156 virtual const net::URLRequestStatus& status() const { return status_; }
157
139 private: 158 private:
140 virtual ~FakeURLFetcher() { 159 virtual ~FakeURLFetcher() {
141 } 160 }
142 161
143 // This is the method which actually calls the delegate that is passed in the 162 // This is the method which actually calls the delegate that is passed in the
144 // constructor. 163 // constructor.
145 void RunDelegate() { 164 void RunDelegate() {
146 net::URLRequestStatus status; 165 delegate()->OnURLFetchComplete(this);
147 status.set_status(success_ ? net::URLRequestStatus::SUCCESS :
148 net::URLRequestStatus::FAILED);
149 delegate()->OnURLFetchComplete(this, url_, status, success_ ? 200 : 500,
150 net::ResponseCookies(), response_data_);
151 } 166 }
152 167
153 // Pre-baked response data and flag which indicates whether the request should 168 // Pre-baked response data and flag which indicates whether the request should
154 // be successful or not. 169 // be successful or not.
155 GURL url_; 170 GURL url_;
156 std::string response_data_; 171 std::string response_data_;
157 bool success_; 172 bool success_;
173 net::URLRequestStatus status_;
174 net::ResponseCookies cookies_;
158 175
159 // Method factory used to run the delegate. 176 // Method factory used to run the delegate.
160 ScopedRunnableMethodFactory<FakeURLFetcher> method_factory_; 177 ScopedRunnableMethodFactory<FakeURLFetcher> method_factory_;
161 178
162 DISALLOW_COPY_AND_ASSIGN(FakeURLFetcher); 179 DISALLOW_COPY_AND_ASSIGN(FakeURLFetcher);
163 }; 180 };
164 181
165 FakeURLFetcherFactory::FakeURLFetcherFactory() 182 FakeURLFetcherFactory::FakeURLFetcherFactory()
166 : ScopedURLFetcherFactory(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { 183 : ScopedURLFetcherFactory(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
167 } 184 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 225
209 URLFetcherFactory::~URLFetcherFactory() {} 226 URLFetcherFactory::~URLFetcherFactory() {}
210 227
211 URLFetcher* URLFetcherFactory::CreateURLFetcher( 228 URLFetcher* URLFetcherFactory::CreateURLFetcher(
212 int id, 229 int id,
213 const GURL& url, 230 const GURL& url,
214 URLFetcher::RequestType request_type, 231 URLFetcher::RequestType request_type,
215 URLFetcher::Delegate* d) { 232 URLFetcher::Delegate* d) {
216 return new URLFetcher(url, request_type, d); 233 return new URLFetcher(url, request_type, d);
217 } 234 }
OLDNEW
« chrome/browser/web_resource/promo_resource_service.cc ('K') | « chrome/common/pref_names.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698