Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
|
willchan no longer on Chromium
2012/12/11 19:23:34
Why is this not marked [D]eleted?
| |
| 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_EXTENSIONS_AUTOUPDATE_INTERCEPTOR_H_ | |
| 6 #define CHROME_BROWSER_EXTENSIONS_AUTOUPDATE_INTERCEPTOR_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 #include <string> | |
| 10 | |
| 11 #include "googleurl/src/gurl.h" | |
| 12 #include "net/url_request/url_request.h" | |
| 13 | |
| 14 namespace extensions { | |
| 15 | |
| 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. | |
| 18 class AutoUpdateInterceptor | |
| 19 : public net::URLRequest::Interceptor, | |
| 20 public base::RefCountedThreadSafe<AutoUpdateInterceptor> { | |
| 21 public: | |
| 22 AutoUpdateInterceptor(); | |
| 23 | |
| 24 // When computing matches, this ignores query parameters (since the autoupdate | |
| 25 // fetch code appends a bunch of them to manifest fetches). | |
| 26 virtual net::URLRequestJob* MaybeIntercept( | |
| 27 net::URLRequest* request, | |
| 28 net::NetworkDelegate* network_delegate) OVERRIDE; | |
| 29 | |
| 30 // 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 // must be "http" so MaybeIntercept can ignore "chrome" and other schemes. | |
| 33 // Also, the match for |url| will ignore any query parameters. | |
| 34 void SetResponse(const std::string url, const FilePath& path); | |
| 35 | |
| 36 // A helper function to call SetResponse on the I/O thread. | |
| 37 void SetResponseOnIOThread(const std::string url, const FilePath& path); | |
| 38 | |
| 39 private: | |
| 40 friend class base::RefCountedThreadSafe<AutoUpdateInterceptor>; | |
| 41 | |
| 42 virtual ~AutoUpdateInterceptor(); | |
| 43 | |
| 44 std::map<GURL, FilePath> responses_; | |
| 45 | |
| 46 DISALLOW_COPY_AND_ASSIGN(AutoUpdateInterceptor); | |
| 47 }; | |
| 48 | |
| 49 } // namespace extensions | |
| 50 | |
| 51 #endif // CHROME_BROWSER_EXTENSIONS_AUTOUPDATE_INTERCEPTOR_H_ | |
| OLD | NEW |