safe_browsing_resource_throttle_factory.h revision 58537e28ecd584eab876aee8be7156509866d23a
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.
4
5#ifndef CHROME_BROWSER_RENDERER_HOST_SAFE_BROWSING_RESOURCE_THROTTLE_FACTORY_H_
6#define CHROME_BROWSER_RENDERER_HOST_SAFE_BROWSING_RESOURCE_THROTTLE_FACTORY_H_
7
8#include "base/basictypes.h"
9
10class SafeBrowsingService;
11
12namespace content {
13class ResourceThrottle;
14}
15
16namespace net {
17class URLRequest;
18}
19
20// Factory for creating a SafeBrowsingResourceThrottle. When FULL_SAFE_BROWSING
21// is enabled, creates a SafeBrowsingResourceThrottle. When MOBILE_SAFE_BROWSING
22// is enabled, the default implementation creates a null resource throttle,
23// therefore, a factory has to be registered before using this.
24class SafeBrowsingResourceThrottleFactory {
25 public:
26#if defined(MOBILE_SAFE_BROWSING)
27  // Registers a factory. Does not take the ownership of the factory. The
28  // caller has to make sure the factory stays alive and properly destroyed.
29  static void RegisterFactory(SafeBrowsingResourceThrottleFactory* factory) {
30    factory_ = factory;
31  }
32#endif
33
34  // Creates a new resource throttle for safe browsing
35  static content::ResourceThrottle* Create(
36      net::URLRequest* request,
37      bool is_subresource,
38      SafeBrowsingService* service);
39
40 protected:
41  SafeBrowsingResourceThrottleFactory() { }
42  virtual ~SafeBrowsingResourceThrottleFactory() { }
43
44  virtual content::ResourceThrottle* CreateResourceThrottle(
45      net::URLRequest* request,
46      bool is_subresource,
47      SafeBrowsingService* service) = 0;
48
49 private:
50  static SafeBrowsingResourceThrottleFactory* factory_;
51
52  DISALLOW_COPY_AND_ASSIGN(SafeBrowsingResourceThrottleFactory);
53};
54
55#endif  // CHROME_BROWSER_RENDERER_HOST_SAFE_BROWSING_RESOURCE_THROTTLE_FACTORY_H_
56