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