Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(595)

Side by Side Diff: components/safe_browsing_db/v4_local_database_manager.cc

Issue 2062013002: Fetch incremental updates. Store new state in V4Store. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nit: Use base::SStringPrintf instead of string concat Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/safe_browsing_db/v4_local_database_manager.h" 5 #include "components/safe_browsing_db/v4_local_database_manager.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "components/safe_browsing_db/safebrowsing.pb.h" 10 #include "components/safe_browsing_db/safebrowsing.pb.h"
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 SetupUpdateProtocolManager(request_context_getter, config); 145 SetupUpdateProtocolManager(request_context_getter, config);
146 146
147 SetupDatabase(); 147 SetupDatabase();
148 148
149 enabled_ = true; 149 enabled_ = true;
150 } 150 }
151 151
152 void V4LocalDatabaseManager::SetupUpdateProtocolManager( 152 void V4LocalDatabaseManager::SetupUpdateProtocolManager(
153 net::URLRequestContextGetter* request_context_getter, 153 net::URLRequestContextGetter* request_context_getter,
154 const V4ProtocolConfig& config) { 154 const V4ProtocolConfig& config) {
155 #if defined(OS_WIN) || defined(OS_LINUX) || defined(OS_MACOSX)
156 // TODO(vakh): Remove this if/endif block when the V4Database is implemented.
157 // Filed as http://crbug.com/608075
158 UpdateListIdentifier update_list_identifier;
159 #if defined(OS_WIN)
160 update_list_identifier.platform_type = WINDOWS_PLATFORM;
161 #elif defined(OS_LINUX)
162 update_list_identifier.platform_type = LINUX_PLATFORM;
163 #else
164 update_list_identifier.platform_type = OSX_PLATFORM;
165 #endif
166 update_list_identifier.threat_entry_type = URL;
167 update_list_identifier.threat_type = MALWARE_THREAT;
168 current_list_states_[update_list_identifier] = "";
169 #endif
170
171 V4UpdateCallback callback = base::Bind( 155 V4UpdateCallback callback = base::Bind(
172 &V4LocalDatabaseManager::UpdateRequestCompleted, base::Unretained(this)); 156 &V4LocalDatabaseManager::UpdateRequestCompleted, base::Unretained(this));
173 157
174 v4_update_protocol_manager_ = V4UpdateProtocolManager::Create( 158 v4_update_protocol_manager_ =
175 request_context_getter, config, current_list_states_, callback); 159 V4UpdateProtocolManager::Create(request_context_getter, config, callback);
176 } 160 }
177 161
178 void V4LocalDatabaseManager::SetupDatabase() { 162 void V4LocalDatabaseManager::SetupDatabase() {
179 DCHECK(!base_path_.empty()); 163 DCHECK(!base_path_.empty());
180 DCHECK_CURRENTLY_ON(BrowserThread::IO); 164 DCHECK_CURRENTLY_ON(BrowserThread::IO);
181 165
182 // Only get a new task runner if there isn't one already. If the service has 166 // Only get a new task runner if there isn't one already. If the service has
183 // previously been started and stopped, a task runner could already exist. 167 // previously been started and stopped, a task runner could already exist.
184 if (!task_runner_) { 168 if (!task_runner_) {
185 base::SequencedWorkerPool* pool = BrowserThread::GetBlockingPool(); 169 base::SequencedWorkerPool* pool = BrowserThread::GetBlockingPool();
186 task_runner_ = pool->GetSequencedTaskRunnerWithShutdownBehavior( 170 task_runner_ = pool->GetSequencedTaskRunnerWithShutdownBehavior(
187 pool->GetSequenceToken(), base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); 171 pool->GetSequenceToken(), base::SequencedWorkerPool::SKIP_ON_SHUTDOWN);
188 } 172 }
189 173
190 // TODO(vakh): list_info_map should probably be a hard-coded map. 174 StoreFileNameMap store_file_name_map;
191 ListInfoMap list_info_map; 175 PopulateStoreFileNameMap(&store_file_name_map);
192 176
193 // Do not create the database on the IO thread since this may be an expensive 177 // Do not create the database on the IO thread since this may be an expensive
194 // operation. Instead, do that on the task_runner and when the new database 178 // operation. Instead, do that on the task_runner and when the new database
195 // has been created, swap it out on the IO thread. 179 // has been created, swap it out on the IO thread.
180 DCHECK(!store_file_name_map.empty());
181 DatabaseUpdatedCallback db_updated_callback = base::Bind(
182 &V4LocalDatabaseManager::DatabaseUpdated, base::Unretained(this));
196 NewDatabaseReadyCallback db_ready_callback = base::Bind( 183 NewDatabaseReadyCallback db_ready_callback = base::Bind(
197 &V4LocalDatabaseManager::DatabaseReady, base::Unretained(this)); 184 &V4LocalDatabaseManager::DatabaseReady, base::Unretained(this));
198 V4Database::Create(task_runner_, base_path_, list_info_map, 185 V4Database::Create(task_runner_, base_path_, store_file_name_map,
199 db_ready_callback); 186 db_updated_callback, db_ready_callback);
187 }
188
189 void V4LocalDatabaseManager::PopulateStoreFileNameMap(
190 StoreFileNameMap* store_file_name_map) {
191 #if defined(OS_WIN) || defined(OS_LINUX) || defined(OS_MACOSX)
192 // TODO(vakh): Implement this to populate the map appopriately.
193 // Filed as http://crbug.com/608075
194 PlatformType platform_type;
195 #if defined(OS_WIN)
196 platform_type = WINDOWS_PLATFORM;
197 #elif defined(OS_LINUX)
198 platform_type = LINUX_PLATFORM;
199 #else
Nathan Parker 2016/06/15 21:24:18 An idea: How about requiring a known OS? You coul
vakh (use Gerrit instead) 2016/06/16 01:07:35 Done.
200 platform_type = OSX_PLATFORM;
201 #endif
202 UpdateListIdentifier update_list_identifier(platform_type, URL,
203 MALWARE_THREAT);
204 (*store_file_name_map)[update_list_identifier] = "os_url_malware.store";
Nathan Parker 2016/06/15 21:24:19 We should come up with a list of all the filenames
vakh (use Gerrit instead) 2016/06/16 01:07:35 Acknowledged. Work for a later CL.
Nathan Parker 2016/06/17 21:34:19 When we we change the names later, we'll need to w
vakh (use Gerrit instead) 2016/06/23 00:28:06 Done. The files are being created under the "Safe
205
206 update_list_identifier.threat_type = SOCIAL_ENGINEERING_PUBLIC;
207 (*store_file_name_map)[update_list_identifier] = "os_url_soceng.store";
208 #endif
200 } 209 }
201 210
202 void V4LocalDatabaseManager::DatabaseReady( 211 void V4LocalDatabaseManager::DatabaseReady(
203 std::unique_ptr<V4Database> v4_database) { 212 std::unique_ptr<V4Database> v4_database) {
204 DCHECK_CURRENTLY_ON(BrowserThread::IO); 213 DCHECK_CURRENTLY_ON(BrowserThread::IO);
205 214
206 // The following check is needed because it is possible that by the time the 215 // The following check is needed because it is possible that by the time the
207 // database is ready, StopOnIOThread has been called. 216 // database is ready, StopOnIOThread has been called.
208 if (enabled_) { 217 if (enabled_) {
209 v4_database_ = std::move(v4_database); 218 v4_database_ = std::move(v4_database);
210 219
211 // The database is in place. Start fetching updates now. 220 // The database is in place. Start fetching updates now.
212 v4_update_protocol_manager_->ScheduleNextUpdate(); 221 v4_update_protocol_manager_->ScheduleNextUpdate(
222 v4_database_->store_state_map());
213 } else { 223 } else {
214 // Schedule the deletion of v4_database off IO thread. 224 // Schedule the deletion of v4_database off IO thread.
215 V4Database::Destroy(std::move(v4_database)); 225 V4Database::Destroy(std::move(v4_database));
216 } 226 }
217 } 227 }
218 228
219 void V4LocalDatabaseManager::StopOnIOThread(bool shutdown) { 229 void V4LocalDatabaseManager::StopOnIOThread(bool shutdown) {
220 DCHECK_CURRENTLY_ON(BrowserThread::IO); 230 DCHECK_CURRENTLY_ON(BrowserThread::IO);
221 231
222 enabled_ = false; 232 enabled_ = false;
223 233
224 // Delete the V4Database. Any pending writes to disk are completed. 234 // Delete the V4Database. Any pending writes to disk are completed.
225 // This operation happens on the task_runner on which v4_database_ operates 235 // This operation happens on the task_runner on which v4_database_ operates
226 // and doesn't block the IO thread. 236 // and doesn't block the IO thread.
227 V4Database::Destroy(std::move(v4_database_)); 237 V4Database::Destroy(std::move(v4_database_));
228 238
229 // Delete the V4UpdateProtocolManager. 239 // Delete the V4UpdateProtocolManager.
230 // This cancels any in-flight update request. 240 // This cancels any in-flight update request.
231 v4_update_protocol_manager_.reset(); 241 v4_update_protocol_manager_.reset();
232 242
233 SafeBrowsingDatabaseManager::StopOnIOThread(shutdown); 243 SafeBrowsingDatabaseManager::StopOnIOThread(shutdown);
234 } 244 }
235 245
236 void V4LocalDatabaseManager::UpdateRequestCompleted( 246 void V4LocalDatabaseManager::UpdateRequestCompleted(
237 const std::vector<ListUpdateResponse>& responses) { 247 const std::vector<ListUpdateResponse>& responses) {
238 DCHECK_CURRENTLY_ON(BrowserThread::IO); 248 DCHECK_CURRENTLY_ON(BrowserThread::IO);
249 v4_database_->ApplyUpdate(responses);
250 }
239 251
240 // TODO(vakh): Updates downloaded. Store them on disk and record new state. 252 void V4LocalDatabaseManager::DatabaseUpdated() {
241 v4_update_protocol_manager_->ScheduleNextUpdate(); 253 v4_update_protocol_manager_->ScheduleNextUpdate(
254 v4_database_->store_state_map());
242 } 255 }
243 256
244 } // namespace safe_browsing 257 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698