Chromium Code Reviews| Index: components/safe_browsing_db/v4_local_database_manager.cc |
| diff --git a/components/safe_browsing_db/v4_local_database_manager.cc b/components/safe_browsing_db/v4_local_database_manager.cc |
| index 30812a01b3cf971d084c877d23d70708e5b844d3..38204ca786f0bb7ce70c0f10bed77af1773af9a4 100644 |
| --- a/components/safe_browsing_db/v4_local_database_manager.cc |
| +++ b/components/safe_browsing_db/v4_local_database_manager.cc |
| @@ -152,27 +152,11 @@ void V4LocalDatabaseManager::StartOnIOThread( |
| void V4LocalDatabaseManager::SetupUpdateProtocolManager( |
| net::URLRequestContextGetter* request_context_getter, |
| const V4ProtocolConfig& config) { |
| -#if defined(OS_WIN) || defined(OS_LINUX) || defined(OS_MACOSX) |
| - // TODO(vakh): Remove this if/endif block when the V4Database is implemented. |
| - // Filed as http://crbug.com/608075 |
| - UpdateListIdentifier update_list_identifier; |
| -#if defined(OS_WIN) |
| - update_list_identifier.platform_type = WINDOWS_PLATFORM; |
| -#elif defined(OS_LINUX) |
| - update_list_identifier.platform_type = LINUX_PLATFORM; |
| -#else |
| - update_list_identifier.platform_type = OSX_PLATFORM; |
| -#endif |
| - update_list_identifier.threat_entry_type = URL; |
| - update_list_identifier.threat_type = MALWARE_THREAT; |
| - current_list_states_[update_list_identifier] = ""; |
| -#endif |
| - |
| V4UpdateCallback callback = base::Bind( |
| &V4LocalDatabaseManager::UpdateRequestCompleted, base::Unretained(this)); |
| - v4_update_protocol_manager_ = V4UpdateProtocolManager::Create( |
| - request_context_getter, config, current_list_states_, callback); |
| + v4_update_protocol_manager_ = |
| + V4UpdateProtocolManager::Create(request_context_getter, config, callback); |
| } |
| void V4LocalDatabaseManager::SetupDatabase() { |
| @@ -187,16 +171,41 @@ void V4LocalDatabaseManager::SetupDatabase() { |
| pool->GetSequenceToken(), base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); |
| } |
| - // TODO(vakh): list_info_map should probably be a hard-coded map. |
| - ListInfoMap list_info_map; |
| + StoreFileNameMap store_file_name_map; |
| + PopulateStoreFileNameMap(&store_file_name_map); |
| // Do not create the database on the IO thread since this may be an expensive |
| // operation. Instead, do that on the task_runner and when the new database |
| // has been created, swap it out on the IO thread. |
| + DCHECK(!store_file_name_map.empty()); |
| + DatabaseUpdatedCallback db_updated_callback = base::Bind( |
| + &V4LocalDatabaseManager::DatabaseUpdated, base::Unretained(this)); |
| NewDatabaseReadyCallback db_ready_callback = base::Bind( |
| &V4LocalDatabaseManager::DatabaseReady, base::Unretained(this)); |
| - V4Database::Create(task_runner_, base_path_, list_info_map, |
| - db_ready_callback); |
| + V4Database::Create(task_runner_, base_path_, store_file_name_map, |
| + db_updated_callback, db_ready_callback); |
| +} |
| + |
| +void V4LocalDatabaseManager::PopulateStoreFileNameMap( |
| + StoreFileNameMap* store_file_name_map) { |
| +#if defined(OS_WIN) || defined(OS_LINUX) || defined(OS_MACOSX) |
| + // TODO(vakh): Implement this to populate the map appopriately. |
| + // Filed as http://crbug.com/608075 |
| + PlatformType platform_type; |
| +#if defined(OS_WIN) |
| + platform_type = WINDOWS_PLATFORM; |
| +#elif defined(OS_LINUX) |
| + platform_type = LINUX_PLATFORM; |
| +#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.
|
| + platform_type = OSX_PLATFORM; |
| +#endif |
| + UpdateListIdentifier update_list_identifier(platform_type, URL, |
| + MALWARE_THREAT); |
| + (*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
|
| + |
| + update_list_identifier.threat_type = SOCIAL_ENGINEERING_PUBLIC; |
| + (*store_file_name_map)[update_list_identifier] = "os_url_soceng.store"; |
| +#endif |
| } |
| void V4LocalDatabaseManager::DatabaseReady( |
| @@ -209,7 +218,8 @@ void V4LocalDatabaseManager::DatabaseReady( |
| v4_database_ = std::move(v4_database); |
| // The database is in place. Start fetching updates now. |
| - v4_update_protocol_manager_->ScheduleNextUpdate(); |
| + v4_update_protocol_manager_->ScheduleNextUpdate( |
| + v4_database_->store_state_map()); |
| } else { |
| // Schedule the deletion of v4_database off IO thread. |
| V4Database::Destroy(std::move(v4_database)); |
| @@ -236,9 +246,12 @@ void V4LocalDatabaseManager::StopOnIOThread(bool shutdown) { |
| void V4LocalDatabaseManager::UpdateRequestCompleted( |
| const std::vector<ListUpdateResponse>& responses) { |
| DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| + v4_database_->ApplyUpdate(responses); |
| +} |
| - // TODO(vakh): Updates downloaded. Store them on disk and record new state. |
| - v4_update_protocol_manager_->ScheduleNextUpdate(); |
| +void V4LocalDatabaseManager::DatabaseUpdated() { |
| + v4_update_protocol_manager_->ScheduleNextUpdate( |
| + v4_database_->store_state_map()); |
| } |
| } // namespace safe_browsing |