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