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 #include "chrome/browser/renderer_host/safe_browsing_resource_throttle_factory.h"
7 // Compiling this file only makes sense if SAFE_BROWSING_SERVICE is enabled.
8 // If the build is breaking here, it probably means that a gyp or gn file has
9 // been modified to build this file with safe_browsing=0 (gn
10 // safe_browsing_mode=0).
11 #if !defined(SAFE_BROWSING_SERVICE)
12 #error Need to define safe_browsing mode.
15 #if defined(SAFE_BROWSING_DB_LOCAL) || defined(SAFE_BROWSING_DB_REMOTE)
16 #include "chrome/browser/renderer_host/safe_browsing_resource_throttle.h"
19 using content::ResourceThrottle
;
23 SafeBrowsingResourceThrottleFactory
* g_factory
= nullptr;
28 void SafeBrowsingResourceThrottleFactory::RegisterFactory(
29 SafeBrowsingResourceThrottleFactory
* factory
) {
34 ResourceThrottle
* SafeBrowsingResourceThrottleFactory::Create(
35 net::URLRequest
* request
,
36 content::ResourceContext
* resource_context
,
37 content::ResourceType resource_type
,
38 SafeBrowsingService
* service
) {
40 return g_factory
->CreateResourceThrottle(
41 request
, resource_context
, resource_type
, service
);
43 return CreateWithoutRegisteredFactory(request
, resource_type
, service
);
47 SafeBrowsingResourceThrottleFactory::CreateWithoutRegisteredFactory(
48 net::URLRequest
* request
,
49 content::ResourceType resource_type
,
50 SafeBrowsingService
* service
) {
51 #if defined(SAFE_BROWSING_DB_LOCAL)
52 // Throttle consults a local database before starting the resource request.
53 return new SafeBrowsingResourceThrottle(request
, resource_type
, service
,
54 true /* defer_at_start */);
55 #elif defined(SAFE_BROWSING_DB_REMOTE)
56 // Throttle consults a remote database before processing the response.
57 return new SafeBrowsingResourceThrottle(request
, resource_type
, service
,
58 false /* defer_at_start */);