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

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

Issue 2890293005: Network traffic annotation stored in url_request. (Closed)
Patch Set: Created 3 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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_TEST_URL_FETCHER_FACTORY_H_ 5 #ifndef NET_URL_REQUEST_TEST_URL_FETCHER_FACTORY_H_
6 #define NET_URL_REQUEST_TEST_URL_FETCHER_FACTORY_H_ 6 #define NET_URL_REQUEST_TEST_URL_FETCHER_FACTORY_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <list> 10 #include <list>
11 #include <map> 11 #include <map>
12 #include <memory> 12 #include <memory>
13 #include <string> 13 #include <string>
14 #include <utility> 14 #include <utility>
15 15
16 #include "base/callback.h" 16 #include "base/callback.h"
17 #include "base/compiler_specific.h" 17 #include "base/compiler_specific.h"
18 #include "base/files/file_path.h" 18 #include "base/files/file_path.h"
19 #include "base/macros.h" 19 #include "base/macros.h"
20 #include "base/memory/weak_ptr.h" 20 #include "base/memory/weak_ptr.h"
21 #include "base/sequenced_task_runner.h" 21 #include "base/sequenced_task_runner.h"
22 #include "base/threading/non_thread_safe.h" 22 #include "base/threading/non_thread_safe.h"
23 #include "net/http/http_request_headers.h" 23 #include "net/http/http_request_headers.h"
24 #include "net/http/http_status_code.h" 24 #include "net/http/http_status_code.h"
25 #include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
25 #include "net/url_request/url_fetcher_factory.h" 26 #include "net/url_request/url_fetcher_factory.h"
26 #include "net/url_request/url_request_status.h" 27 #include "net/url_request/url_request_status.h"
27 #include "url/gurl.h" 28 #include "url/gurl.h"
28 29
29 namespace net { 30 namespace net {
30 31
31 // Changes URLFetcher's Factory for the lifetime of the object. 32 // Changes URLFetcher's Factory for the lifetime of the object.
32 // Note that this scoper cannot be nested (to make it even harder to misuse). 33 // Note that this scoper cannot be nested (to make it even harder to misuse).
33 class ScopedURLFetcherFactory : public base::NonThreadSafe { 34 class ScopedURLFetcherFactory : public base::NonThreadSafe {
34 public: 35 public:
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 class TestURLFetcherFactory : public URLFetcherFactory, 249 class TestURLFetcherFactory : public URLFetcherFactory,
249 public ScopedURLFetcherFactory { 250 public ScopedURLFetcherFactory {
250 public: 251 public:
251 TestURLFetcherFactory(); 252 TestURLFetcherFactory();
252 ~TestURLFetcherFactory() override; 253 ~TestURLFetcherFactory() override;
253 254
254 std::unique_ptr<URLFetcher> CreateURLFetcher( 255 std::unique_ptr<URLFetcher> CreateURLFetcher(
255 int id, 256 int id,
256 const GURL& url, 257 const GURL& url,
257 URLFetcher::RequestType request_type, 258 URLFetcher::RequestType request_type,
258 URLFetcherDelegate* d) override; 259 URLFetcherDelegate* d,
260 NetworkTrafficAnnotationTag traffic_annotation) override;
259 TestURLFetcher* GetFetcherByID(int id) const; 261 TestURLFetcher* GetFetcherByID(int id) const;
260 void RemoveFetcherFromMap(int id); 262 void RemoveFetcherFromMap(int id);
261 void SetDelegateForTests(TestURLFetcherDelegateForTests* delegate_for_tests); 263 void SetDelegateForTests(TestURLFetcherDelegateForTests* delegate_for_tests);
262 void set_remove_fetcher_on_delete(bool remove_fetcher_on_delete) { 264 void set_remove_fetcher_on_delete(bool remove_fetcher_on_delete) {
263 remove_fetcher_on_delete_ = remove_fetcher_on_delete; 265 remove_fetcher_on_delete_ = remove_fetcher_on_delete;
264 } 266 }
265 267
266 private: 268 private:
267 // Maps from id passed to create to the returned URLFetcher. 269 // Maps from id passed to create to the returned URLFetcher.
268 typedef std::map<int, TestURLFetcher*> Fetchers; 270 typedef std::map<int, TestURLFetcher*> Fetchers;
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 412
411 // If no fake response is set for the given URL this method will delegate the 413 // If no fake response is set for the given URL this method will delegate the
412 // call to |default_factory_| if it is not NULL, or return NULL if it is 414 // call to |default_factory_| if it is not NULL, or return NULL if it is
413 // NULL. 415 // NULL.
414 // Otherwise, it will return a URLFetcher object which will respond with the 416 // Otherwise, it will return a URLFetcher object which will respond with the
415 // pre-baked response that the client has set by calling SetFakeResponse(). 417 // pre-baked response that the client has set by calling SetFakeResponse().
416 std::unique_ptr<URLFetcher> CreateURLFetcher( 418 std::unique_ptr<URLFetcher> CreateURLFetcher(
417 int id, 419 int id,
418 const GURL& url, 420 const GURL& url,
419 URLFetcher::RequestType request_type, 421 URLFetcher::RequestType request_type,
420 URLFetcherDelegate* d) override; 422 URLFetcherDelegate* d,
423 NetworkTrafficAnnotationTag traffic_annotation) override;
421 424
422 // Sets the fake response for a given URL. The |response_data| may be empty. 425 // Sets the fake response for a given URL. The |response_data| may be empty.
423 // The |response_code| may be any HttpStatusCode. For instance, HTTP_OK will 426 // The |response_code| may be any HttpStatusCode. For instance, HTTP_OK will
424 // return an HTTP/200 and HTTP_INTERNAL_SERVER_ERROR will return an HTTP/500. 427 // return an HTTP/200 and HTTP_INTERNAL_SERVER_ERROR will return an HTTP/500.
425 // The |status| argument may be any URLRequestStatus::Status value. Typically, 428 // The |status| argument may be any URLRequestStatus::Status value. Typically,
426 // requests that return a valid HttpStatusCode have the SUCCESS status, while 429 // requests that return a valid HttpStatusCode have the SUCCESS status, while
427 // requests that indicate a failure to connect to the server have the FAILED 430 // requests that indicate a failure to connect to the server have the FAILED
428 // status. 431 // status.
429 void SetFakeResponse(const GURL& url, 432 void SetFakeResponse(const GURL& url,
430 const std::string& response_data, 433 const std::string& response_data,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 class URLFetcherImplFactory : public URLFetcherFactory { 466 class URLFetcherImplFactory : public URLFetcherFactory {
464 public: 467 public:
465 URLFetcherImplFactory(); 468 URLFetcherImplFactory();
466 ~URLFetcherImplFactory() override; 469 ~URLFetcherImplFactory() override;
467 470
468 // This method will create a real URLFetcher. 471 // This method will create a real URLFetcher.
469 std::unique_ptr<URLFetcher> CreateURLFetcher( 472 std::unique_ptr<URLFetcher> CreateURLFetcher(
470 int id, 473 int id,
471 const GURL& url, 474 const GURL& url,
472 URLFetcher::RequestType request_type, 475 URLFetcher::RequestType request_type,
473 URLFetcherDelegate* d) override; 476 URLFetcherDelegate* d,
477 NetworkTrafficAnnotationTag traffic_annotation) override;
474 }; 478 };
475 479
476 } // namespace net 480 } // namespace net
477 481
478 #endif // NET_URL_REQUEST_TEST_URL_FETCHER_FACTORY_H_ 482 #endif // NET_URL_REQUEST_TEST_URL_FETCHER_FACTORY_H_
OLDNEW
« no previous file with comments | « net/traffic_annotation/network_traffic_annotation.h ('k') | net/url_request/test_url_fetcher_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698