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

Side by Side Diff: chrome/browser/component_updater/component_updater_interceptor.h

Issue 11293252: Change Interceptors into URLRequestJobFactory::ProtocolHandlers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync Created 8 years 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_UPDATER_INTERCEPTOR_H_
6 #define CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_UPDATER_INTERCEPTOR_H_
7
8 #include <map>
9 #include <string>
10
11 #include "base/compiler_specific.h"
12 #include "base/file_path.h"
13 #include "googleurl/src/gurl.h"
14 #include "net/url_request/url_request.h"
15
16 #if !defined(UNIT_TEST)
17 #error "use this class only in unit tests"
18 #endif
19
20 // This url request interceptor lets us respond to localhost http request urls
21 // with the contents of files on disk for use in tests.
22 class ComponentUpdateInterceptor
23 : public net::URLRequest::Interceptor,
24 public base::RefCountedThreadSafe<ComponentUpdateInterceptor> {
25 public:
26 ComponentUpdateInterceptor();
27
28 // When requests for |url| arrive, respond with the contents of |path|. The
29 // hostname of |url| must be "localhost" to avoid DNS lookups, and the scheme
30 // must be "http".
31 void SetResponse(const std::string& url,
32 const std::string& headers,
33 const FilePath& path);
34
35 // Returns how many requests have been issued that have a stored reply.
36 int hit_count() const { return hit_count_; }
37
38 private:
39 // When computing matches, this ignores the query parameters of the url.
40 virtual net::URLRequestJob* MaybeIntercept(
41 net::URLRequest* request,
42 net::NetworkDelegate* network_delegate) OVERRIDE;
43
44 friend class base::RefCountedThreadSafe<ComponentUpdateInterceptor>;
45
46 virtual ~ComponentUpdateInterceptor();
47
48 struct Response {
49 FilePath data_path;
50 std::string headers;
51 };
52
53 typedef std::map<GURL, Response> ResponseMap;
54 ResponseMap responses_;
55 int hit_count_;
56
57 DISALLOW_COPY_AND_ASSIGN(ComponentUpdateInterceptor);
58 };
59
60 #endif // CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_UPDATER_INTERCEPTOR_H_
OLDNEW
« no previous file with comments | « android_webview/native/net_init_native_callback.cc ('k') | chrome/browser/component_updater/component_updater_interceptor.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698