OLD | NEW |
---|---|
(Empty) | |
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 #include "components/safe_browsing/base_safe_browsing_service.h" | |
6 | |
7 #include <stddef.h> | |
8 | |
9 #include "base/bind.h" | |
10 #include "base/macros.h" | |
11 #include "base/path_service.h" | |
12 #include "components/safe_browsing/base_ui_manager.h" | |
13 #include "components/safe_browsing/common/safebrowsing_constants.h" | |
14 #include "components/safe_browsing_db/database_manager.h" | |
15 #include "components/safe_browsing_db/safe_browsing_prefs.h" | |
16 #include "components/safe_browsing_db/v4_feature_list.h" | |
17 #include "content/public/browser/browser_thread.h" | |
18 #include "content/public/browser/resource_request_info.h" | |
19 #include "google_apis/google_api_keys.h" | |
20 #include "net/url_request/url_request_context.h" | |
21 #include "net/url_request/url_request_context_getter.h" | |
22 | |
23 #if defined(SAFE_BROWSING_DB_REMOTE) | |
24 #include "components/safe_browsing_db/remote_database_manager.h" | |
25 #endif | |
26 | |
27 using content::BrowserThread; | |
28 | |
29 namespace safe_browsing { | |
30 | |
31 BaseSafeBrowsingService::BaseSafeBrowsingService() | |
32 : enabled_(false), | |
33 enabled_by_prefs_(false), | |
34 enabled_v4_only_(safe_browsing::V4FeatureList::IsV4OnlyEnabled()) {} | |
35 | |
36 BaseSafeBrowsingService::~BaseSafeBrowsingService() { | |
37 // We should have already been shut down. If we're still enabled, then the | |
38 // database isn't going to be closed properly, which could lead to corruption. | |
39 DCHECK(!enabled_); | |
40 } | |
41 | |
42 void BaseSafeBrowsingService::Initialize() { | |
43 // TODO(ntfschr): initialize ui_manager_ once CreateUIManager is componentized | |
Jialiu Lin
2016/12/29 17:41:37
CreateUIManager can simply return a BaseUIManager
Nate Fischer
2017/01/03 22:39:53
This is tricky, since other files (e.g. permission
Jialiu Lin
2017/01/04 01:36:34
Ah, I see. Thanks for your explanation.
| |
44 | |
45 if (!enabled_v4_only_) { | |
46 database_manager_ = CreateDatabaseManager(); | |
47 } | |
48 } | |
49 | |
50 void BaseSafeBrowsingService::ShutDown() { | |
51 return; | |
52 } | |
53 | |
54 scoped_refptr<net::URLRequestContextGetter> | |
55 BaseSafeBrowsingService::url_request_context() { | |
56 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
57 return nullptr; | |
58 } | |
59 | |
60 const scoped_refptr<SafeBrowsingDatabaseManager>& | |
61 BaseSafeBrowsingService::database_manager() const { | |
62 return database_manager_; | |
63 } | |
64 | |
65 void BaseSafeBrowsingService::OnResourceRequest( | |
66 const net::URLRequest* request) { | |
67 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
68 } | |
69 | |
70 SafeBrowsingDatabaseManager* BaseSafeBrowsingService::CreateDatabaseManager() { | |
71 #if defined(SAFE_BROWSING_DB_REMOTE) | |
72 return new RemoteSafeBrowsingDatabaseManager(); | |
73 #else | |
74 return NULL; | |
75 #endif | |
76 } | |
77 | |
78 std::string BaseSafeBrowsingService::GetProtocolConfigClientName() const { | |
Jialiu Lin
2016/12/29 17:41:37
Since this function is not called in the base clas
Nate Fischer
2017/01/03 22:39:52
Done
| |
79 std::string client_name; | |
80 // On Windows, get the safe browsing client name from the browser | |
81 // distribution classes in installer util. These classes don't yet have | |
82 // an analog on non-Windows builds so just keep the name specified here. | |
83 #if defined(OS_WIN) | |
84 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | |
85 client_name = dist->GetSafeBrowsingName(); | |
86 #else | |
87 #if defined(GOOGLE_CHROME_BUILD) | |
88 client_name = "googlechrome"; | |
89 #else | |
90 client_name = "chromium"; | |
91 #endif | |
92 | |
93 // Mark client string to allow server to differentiate mobile. | |
94 #if defined(OS_ANDROID) | |
95 client_name.append("-a"); | |
96 #endif | |
97 | |
98 #endif // defined(OS_WIN) | |
99 | |
100 return client_name; | |
101 } | |
102 | |
103 void BaseSafeBrowsingService::StartOnIOThread( | |
104 net::URLRequestContextGetter* url_request_context_getter) { | |
105 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
106 if (enabled_) | |
107 return; | |
108 enabled_ = true; | |
109 return; | |
110 } | |
111 | |
112 void BaseSafeBrowsingService::StopOnIOThread(bool shutdown) { | |
113 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
114 return; | |
115 } | |
116 | |
117 void BaseSafeBrowsingService::Start() { | |
118 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
119 return; | |
120 } | |
121 | |
122 void BaseSafeBrowsingService::Stop(bool shutdown) { | |
123 return; | |
124 } | |
125 | |
126 void BaseSafeBrowsingService::Observe( | |
127 int type, | |
128 const content::NotificationSource& source, | |
129 const content::NotificationDetails& details) { | |
130 return; | |
131 } | |
132 | |
133 std::unique_ptr<BaseSafeBrowsingService::StateSubscription> | |
134 BaseSafeBrowsingService::RegisterStateCallback( | |
135 const base::Callback<void(void)>& callback) { | |
136 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
137 return state_callback_list_.Add(callback); | |
138 } | |
139 | |
140 void BaseSafeBrowsingService::RefreshState() { | |
141 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
142 return; | |
143 } | |
144 | |
145 void BaseSafeBrowsingService::ProcessResourceRequest( | |
146 const ResourceRequestInfo& request) { | |
147 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
148 return; | |
149 } | |
150 | |
151 } // namespace safe_browsing | |
OLD | NEW |