| 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 74032594930f86b5468580c9b1089b9df1e8fede..a228a17a6acbad73a43fca3ee51e7bb92c74780c 100644
|
| --- a/components/safe_browsing_db/v4_local_database_manager.cc
|
| +++ b/components/safe_browsing_db/v4_local_database_manager.cc
|
| @@ -2,6 +2,9 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| +// This file should not be build on Android but is currently getting built.
|
| +// TODO(vakh): Fix that: http://crbug.com/621647
|
| +
|
| #include "components/safe_browsing_db/v4_local_database_manager.h"
|
|
|
| #include <vector>
|
| @@ -152,27 +155,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 +174,38 @@ void V4LocalDatabaseManager::SetupDatabase() {
|
| pool->GetSequenceToken(), base::SequencedWorkerPool::SKIP_ON_SHUTDOWN);
|
| }
|
|
|
| - // TODO(vakh): store_file_name_map should probably be a hard-coded map.
|
| - StoreFileNameMap store_file_name_map;
|
| + StoreFileNameMap store_file_name_map = CreateStoreFileNameMap();
|
|
|
| // 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_, store_file_name_map,
|
| - db_ready_callback);
|
| + db_updated_callback, db_ready_callback);
|
| +}
|
| +
|
| +StoreFileNameMap V4LocalDatabaseManager::CreateStoreFileNameMap() {
|
| + StoreFileNameMap store_file_name_map;
|
| +// TODO(vakh): Implement this to populate the map appopriately.
|
| +// Filed as http://crbug.com/608075
|
| +#if defined(OS_WIN)
|
| + PlatformType platform_type = WINDOWS_PLATFORM;
|
| +#elif defined(OS_LINUX)
|
| + PlatformType platform_type = LINUX_PLATFORM;
|
| +#else
|
| + PlatformType platform_type = OSX_PLATFORM;
|
| +#endif
|
| +
|
| + UpdateListIdentifier malware_id(platform_type, URL, MALWARE_THREAT);
|
| + store_file_name_map[malware_id] = "os_url_malware.store";
|
| + UpdateListIdentifier soceng_id(platform_type, URL, SOCIAL_ENGINEERING_PUBLIC);
|
| + store_file_name_map[soceng_id] = "os_url_soceng.store";
|
| +
|
| + return store_file_name_map;
|
| }
|
|
|
| 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_->GetStoreStateMap());
|
| } 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_->GetStoreStateMap());
|
| }
|
|
|
| } // namespace safe_browsing
|
|
|