Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / content / test / net / url_request_prepackaged_interceptor.h
blobcc5736d9e2738cb332bf186c544e0fb555f130da
1 // Copyright (c) 2012 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.
5 #ifndef CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_UPDATER_INTERCEPTOR_H_
6 #define CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_UPDATER_INTERCEPTOR_H_
8 #include <string>
10 #include "base/basictypes.h"
12 class GURL;
14 namespace base {
15 class FilePath;
18 namespace content {
20 // Intercepts HTTP requests and gives pre-defined responses to specified URLs.
21 // The pre-defined responses are loaded from files on disk. The interception
22 // occurs while the URLRequestPrepackagedInterceptor is alive.
23 class URLRequestPrepackagedInterceptor {
24 public:
25 // Registers an interceptor for urls using |scheme| and |hostname|. Urls
26 // passed to "SetResponse" are required to use |scheme| and |hostname|.
27 URLRequestPrepackagedInterceptor(const std::string& scheme,
28 const std::string& hostname);
29 virtual ~URLRequestPrepackagedInterceptor();
31 // When requests for |url| arrive, respond with the contents of |path|. The
32 // hostname and scheme of |url| must match the corresponding parameters
33 // passed as constructor arguments.
34 void SetResponse(const GURL& url, const base::FilePath& path);
36 // Identical to SetResponse except that query parameters are ignored on
37 // incoming URLs when comparing against |url|.
38 void SetResponseIgnoreQuery(const GURL& url, const base::FilePath& path);
40 // Returns how many requests have been issued that have a stored reply.
41 int GetHitCount();
43 private:
44 class Delegate;
46 const std::string scheme_;
47 const std::string hostname_;
49 // After creation, |delegate_| lives on the IO thread, and a task to delete
50 // it is posted from ~URLRequestPrepackagedInterceptor().
51 Delegate* delegate_;
53 DISALLOW_COPY_AND_ASSIGN(URLRequestPrepackagedInterceptor);
56 // Specialization of URLRequestPrepackagedInterceptor where scheme is "http" and
57 // hostname is "localhost".
58 class URLLocalHostRequestPrepackagedInterceptor
59 : public URLRequestPrepackagedInterceptor {
60 public:
61 URLLocalHostRequestPrepackagedInterceptor();
63 private:
64 DISALLOW_COPY_AND_ASSIGN(URLLocalHostRequestPrepackagedInterceptor);
67 } // namespace content
69 #endif // CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_UPDATER_INTERCEPTOR_H_