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

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

Issue 508473002: Componentize component_updater: Move URLRequestPrepackagedInterceptor from content/ to net/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: run git cl format Created 6 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
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 CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_UPDATER_INTERCEPTOR_H_ 5 #ifndef NET_URL_REQUEST_TEST_URL_REQUEST_INTERCEPTOR_H_
6 #define CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_UPDATER_INTERCEPTOR_H_ 6 #define NET_URL_REQUEST_TEST_URL_REQUEST_INTERCEPTOR_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/memory/ref_counted.h"
11 12
12 class GURL; 13 class GURL;
13 14
14 namespace base { 15 namespace base {
15 class FilePath; 16 class FilePath;
17 class TaskRunner;
16 } 18 }
17 19
18 namespace content { 20 namespace net {
19 21
20 // Intercepts HTTP requests and gives pre-defined responses to specified URLs. 22 // Intercepts HTTP requests and gives pre-defined responses to specified URLs.
21 // The pre-defined responses are loaded from files on disk. The interception 23 // The pre-defined responses are loaded from files on disk. The interception
22 // occurs while the URLRequestPrepackagedInterceptor is alive. 24 // occurs while the TestURLRequestInterceptor is alive.
23 class URLRequestPrepackagedInterceptor { 25 class TestURLRequestInterceptor {
24 public: 26 public:
25 // Registers an interceptor for urls using |scheme| and |hostname|. Urls 27 // Registers an interceptor for urls using |scheme| and |hostname|. Urls
26 // passed to "SetResponse" are required to use |scheme| and |hostname|. 28 // passed to "SetResponse" are required to use |scheme| and |hostname|.
27 URLRequestPrepackagedInterceptor(const std::string& scheme, 29 TestURLRequestInterceptor(
28 const std::string& hostname); 30 const std::string& scheme,
29 virtual ~URLRequestPrepackagedInterceptor(); 31 const std::string& hostname,
32 const scoped_refptr<base::TaskRunner>& io_task_runner,
33 const scoped_refptr<base::TaskRunner>& worker_task_runner);
34 virtual ~TestURLRequestInterceptor();
30 35
31 // When requests for |url| arrive, respond with the contents of |path|. The 36 // When requests for |url| arrive, respond with the contents of |path|. The
32 // hostname and scheme of |url| must match the corresponding parameters 37 // hostname and scheme of |url| must match the corresponding parameters
33 // passed as constructor arguments. 38 // passed as constructor arguments.
34 void SetResponse(const GURL& url, const base::FilePath& path); 39 void SetResponse(const GURL& url, const base::FilePath& path);
35 40
36 // Identical to SetResponse except that query parameters are ignored on 41 // Identical to SetResponse except that query parameters are ignored on
37 // incoming URLs when comparing against |url|. 42 // incoming URLs when comparing against |url|.
38 void SetResponseIgnoreQuery(const GURL& url, const base::FilePath& path); 43 void SetResponseIgnoreQuery(const GURL& url, const base::FilePath& path);
39 44
40 // Returns how many requests have been issued that have a stored reply. 45 // Returns how many requests have been issued that have a stored reply.
41 int GetHitCount(); 46 int GetHitCount();
42 47
43 private: 48 private:
44 class Delegate; 49 class Delegate;
45 50
46 const std::string scheme_; 51 const std::string scheme_;
47 const std::string hostname_; 52 const std::string hostname_;
48 53
49 // After creation, |delegate_| lives on the IO thread, and a task to delete 54 const scoped_refptr<base::TaskRunner> io_task_runner_;
50 // it is posted from ~URLRequestPrepackagedInterceptor(). 55
56 // After creation, |delegate_| lives on the thread of the |io_task_runner_|,
57 // and a task to delete it is posted from ~TestURLRequestInterceptor().
51 Delegate* delegate_; 58 Delegate* delegate_;
52 59
53 DISALLOW_COPY_AND_ASSIGN(URLRequestPrepackagedInterceptor); 60 DISALLOW_COPY_AND_ASSIGN(TestURLRequestInterceptor);
54 }; 61 };
55 62
56 // Specialization of URLRequestPrepackagedInterceptor where scheme is "http" and 63 // Specialization of TestURLRequestInterceptor where scheme is "http" and
57 // hostname is "localhost". 64 // hostname is "localhost".
58 class URLLocalHostRequestPrepackagedInterceptor 65 class LocalHostTestURLRequestInterceptor : public TestURLRequestInterceptor {
59 : public URLRequestPrepackagedInterceptor {
60 public: 66 public:
61 URLLocalHostRequestPrepackagedInterceptor(); 67 LocalHostTestURLRequestInterceptor(
68 const scoped_refptr<base::TaskRunner>& io_task_runner,
69 const scoped_refptr<base::TaskRunner>& worker_task_runner);
62 70
63 private: 71 private:
64 DISALLOW_COPY_AND_ASSIGN(URLLocalHostRequestPrepackagedInterceptor); 72 DISALLOW_COPY_AND_ASSIGN(LocalHostTestURLRequestInterceptor);
65 }; 73 };
66 74
67 } // namespace content 75 } // namespace net
68 76
69 #endif // CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_UPDATER_INTERCEPTOR_H_ 77 #endif // NET_URL_REQUEST_TEST_URL_REQUEST_INTERCEPTOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698