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

Unified Diff: components/safe_browsing_db/v4_local_database_manager.cc

Issue 1954393002: Initialize and reset V4LocalDBManager. Instantiate V4Stores. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@v4_01_db_realz
Patch Set: CR feedback Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
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 376d26edac729bd59e0727bb0a9588be447cd9e2..90481e80667daca85892b5c3a7d34452d131174f 100644
--- a/components/safe_browsing_db/v4_local_database_manager.cc
+++ b/components/safe_browsing_db/v4_local_database_manager.cc
@@ -6,6 +6,7 @@
#include <vector>
+#include "base/callback.h"
#include "components/safe_browsing_db/safebrowsing.pb.h"
#include "content/public/browser/browser_thread.h"
@@ -13,7 +14,12 @@ using content::BrowserThread;
namespace safe_browsing {
-V4LocalDatabaseManager::V4LocalDatabaseManager() : enabled_(false) {}
+V4LocalDatabaseManager::V4LocalDatabaseManager(const base::FilePath& base_path)
+ : base_path_(base_path), enabled_(false) {
+ DCHECK(!base_path_.empty());
+ DVLOG(1) << "V4LocalDatabaseManager::V4LocalDatabaseManager: "
+ << "base_path_: " << base_path_.AsUTF8Unsafe();
+}
V4LocalDatabaseManager::~V4LocalDatabaseManager() {
DCHECK(!enabled_);
@@ -123,8 +129,9 @@ bool V4LocalDatabaseManager::IsCsdWhitelistKillSwitchOn() {
bool V4LocalDatabaseManager::CheckBrowseUrl(const GURL& url, Client* client) {
// TODO(vakh): Implement this skeleton.
DCHECK_CURRENTLY_ON(BrowserThread::IO);
- if (!enabled_)
+ if (!enabled_) {
return true;
+ }
// Don't defer the resource load.
return true;
@@ -141,13 +148,23 @@ void V4LocalDatabaseManager::StartOnIOThread(
const V4ProtocolConfig& config) {
SafeBrowsingDatabaseManager::StartOnIOThread(request_context_getter, config);
-#if defined(OS_WIN) || defined (OS_LINUX) || defined (OS_MACOSX)
+ SetupUpdateProtocolManager(request_context_getter, config);
+
+ SetupDatabase();
+
+ enabled_ = true;
+}
+
+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)
+#elif defined(OS_LINUX)
update_list_identifier.platform_type = LINUX_PLATFORM;
#else
update_list_identifier.platform_type = OSX_PLATFORM;
@@ -159,28 +176,71 @@ void V4LocalDatabaseManager::StartOnIOThread(
V4UpdateCallback callback = base::Bind(
&V4LocalDatabaseManager::UpdateRequestCompleted, base::Unretained(this));
+
v4_update_protocol_manager_ = V4UpdateProtocolManager::Create(
request_context_getter, config, current_list_states_, callback);
+}
- enabled_ = true;
+void V4LocalDatabaseManager::SetupDatabase() {
+ DCHECK(!base_path_.empty());
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+
+ // Only get a new task runner if there isn't one already. If the service has
+ // previously been started and stopped, a task runner could already exist.
+ if (!task_runner_) {
+ base::SequencedWorkerPool* pool = BrowserThread::GetBlockingPool();
+ task_runner_ = pool->GetSequencedTaskRunnerWithShutdownBehavior(
+ pool->GetSequenceToken(), base::SequencedWorkerPool::SKIP_ON_SHUTDOWN);
+ }
+
+ // TODO(vakh): list_info_map should probably be a hard-coded map.
+ ListInfoMap list_info_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.
+ NewDatabaseReadyCallback db_ready_callback = base::Bind(
+ &V4LocalDatabaseManager::DatabaseReady, base::Unretained(this));
+ V4Database::Create(task_runner_, base_path_, list_info_map,
+ db_ready_callback);
+}
+
+void V4LocalDatabaseManager::DatabaseReady(
+ std::unique_ptr<V4Database> v4_database) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+
+ v4_database_ = std::move(v4_database);
+
+ // The database is in place. Start fetching updates now.
+ v4_update_protocol_manager_->ScheduleNextUpdate();
}
void V4LocalDatabaseManager::StopOnIOThread(bool shutdown) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ enabled_ = false;
+
+ // Delete the V4Database.
+ // Any pending writes to disk are completed.
+ if (v4_database_.get()) {
+ v4_database_.reset();
+ }
Scott Hess - ex-Googler 2016/05/12 23:18:00 With this and the one below, is there any value to
vakh (use Gerrit instead) 2016/05/13 00:07:32 I think I saw other places in codesearch that were
+
// Delete the V4UpdateProtocolManager.
// This cancels any in-flight update request.
if (v4_update_protocol_manager_.get()) {
v4_update_protocol_manager_.reset();
}
- enabled_ = false;
SafeBrowsingDatabaseManager::StopOnIOThread(shutdown);
}
void V4LocalDatabaseManager::UpdateRequestCompleted(
const std::vector<ListUpdateResponse>& responses) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+
// TODO(vakh): Updates downloaded. Store them on disk and record new state.
+ v4_update_protocol_manager_->ScheduleNextUpdate();
}
} // namespace safe_browsing

Powered by Google App Engine
This is Rietveld 408576698