OLD | NEW |
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 #ifndef CHROME_BROWSER_EXTENSIONS_AUTOUPDATE_INTERCEPTOR_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_AUTOUPDATE_INTERCEPTOR_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_AUTOUPDATE_INTERCEPTOR_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_AUTOUPDATE_INTERCEPTOR_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "googleurl/src/gurl.h" | 11 #include "googleurl/src/gurl.h" |
12 #include "net/url_request/url_request.h" | 12 #include "net/url_request/url_request.h" |
13 | 13 |
14 namespace extensions { | 14 namespace extensions { |
15 | 15 |
16 // This url request interceptor lets us respond to localhost http request urls | 16 // This url request interceptor lets us respond to localhost http request urls |
17 // with the contents of files on disk for use in tests. | 17 // with the contents of files on disk for use in tests. |
18 class AutoUpdateInterceptor | 18 class AutoUpdateInterceptor |
19 : public net::URLRequest::Interceptor, | 19 : public net::URLRequest::Interceptor, |
20 public base::RefCountedThreadSafe<AutoUpdateInterceptor> { | 20 public base::RefCountedThreadSafe<AutoUpdateInterceptor> { |
21 public: | 21 public: |
22 AutoUpdateInterceptor(); | 22 AutoUpdateInterceptor(); |
23 | 23 |
24 // When computing matches, this ignores query parameters (since the autoupdate | 24 // When computing matches, this ignores query parameters (since the autoupdate |
25 // fetch code appends a bunch of them to manifest fetches). | 25 // fetch code appends a bunch of them to manifest fetches). |
26 virtual net::URLRequestJob* MaybeIntercept(net::URLRequest* request) OVERRIDE; | 26 virtual net::URLRequestJob* MaybeIntercept( |
| 27 net::URLRequest* request, |
| 28 net::NetworkDelegate* network_delegate) OVERRIDE; |
27 | 29 |
28 // When requests for |url| arrive, respond with the contents of |path|. The | 30 // 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 | 31 // hostname of |url| must be "localhost" to avoid DNS lookups, and the scheme |
30 // must be "http" so MaybeIntercept can ignore "chrome" and other schemes. | 32 // must be "http" so MaybeIntercept can ignore "chrome" and other schemes. |
31 // Also, the match for |url| will ignore any query parameters. | 33 // Also, the match for |url| will ignore any query parameters. |
32 void SetResponse(const std::string url, const FilePath& path); | 34 void SetResponse(const std::string url, const FilePath& path); |
33 | 35 |
34 // A helper function to call SetResponse on the I/O thread. | 36 // A helper function to call SetResponse on the I/O thread. |
35 void SetResponseOnIOThread(const std::string url, const FilePath& path); | 37 void SetResponseOnIOThread(const std::string url, const FilePath& path); |
36 | 38 |
37 private: | 39 private: |
38 friend class base::RefCountedThreadSafe<AutoUpdateInterceptor>; | 40 friend class base::RefCountedThreadSafe<AutoUpdateInterceptor>; |
39 | 41 |
40 virtual ~AutoUpdateInterceptor(); | 42 virtual ~AutoUpdateInterceptor(); |
41 | 43 |
42 std::map<GURL, FilePath> responses_; | 44 std::map<GURL, FilePath> responses_; |
43 | 45 |
44 DISALLOW_COPY_AND_ASSIGN(AutoUpdateInterceptor); | 46 DISALLOW_COPY_AND_ASSIGN(AutoUpdateInterceptor); |
45 }; | 47 }; |
46 | 48 |
47 } // namespace extensions | 49 } // namespace extensions |
48 | 50 |
49 #endif // CHROME_BROWSER_EXTENSIONS_AUTOUPDATE_INTERCEPTOR_H_ | 51 #endif // CHROME_BROWSER_EXTENSIONS_AUTOUPDATE_INTERCEPTOR_H_ |
OLD | NEW |