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

Unified Diff: components/safe_browsing_db/v4_store.cc

Issue 2062013002: Fetch incremental updates. Store new state in V4Store. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nits: Added some comments in BUILD.gn. Using #else for platform_type until I resolve the android bu… 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 side-by-side diff with in-line comments
Download patch
Index: components/safe_browsing_db/v4_store.cc
diff --git a/components/safe_browsing_db/v4_store.cc b/components/safe_browsing_db/v4_store.cc
index 0262965bedc5daf2f2ceffbf96d1e5b171b815fd..adc0c3be6ad47b41408f1fb1d67b035e2e4b1273 100644
--- a/components/safe_browsing_db/v4_store.cc
+++ b/components/safe_browsing_db/v4_store.cc
@@ -2,10 +2,18 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/base64.h"
+#include "base/bind.h"
+#include "base/strings/stringprintf.h"
#include "components/safe_browsing_db/v4_store.h"
namespace safe_browsing {
+std::ostream& operator<<(std::ostream& os, const V4Store& store) {
+ os << store.DebugString();
+ return os;
+}
+
V4Store* V4StoreFactory::CreateV4Store(
const scoped_refptr<base::SequencedTaskRunner>& task_runner,
const base::FilePath& store_path) {
@@ -16,11 +24,47 @@ V4Store::V4Store(const scoped_refptr<base::SequencedTaskRunner>& task_runner,
const base::FilePath& store_path)
: task_runner_(task_runner), store_path_(store_path) {}
-V4Store::~V4Store() {}
+V4Store::V4Store(const V4Store& other)
+ : task_runner_(other.task_runner_), store_path_(other.store_path_) {}
+
+V4Store::~V4Store() {
+ DVLOG(1) << "Destroying V4Store: " << *this;
Scott Hess - ex-Googler 2016/06/17 22:53:43 Is this necessary to check in?
vakh (use Gerrit instead) 2016/06/20 22:28:43 Done.
+}
+
+std::string V4Store::DebugString() const {
+ std::string value;
+ base::SStringPrintf(&value, "path: %s; state: %s",
+ store_path_.value().c_str(),
+ GetHumanReadableState().c_str());
Scott Hess - ex-Googler 2016/06/17 22:53:43 Why the interposition? Why not just return base::
vakh (use Gerrit instead) 2016/06/20 22:28:43 Done.
+ return value;
+}
bool V4Store::Reset() {
// TODO(vakh): Implement skeleton.
+ state_ = "";
return true;
}
+void V4Store::ApplyUpdate(
+ const ListUpdateResponse& response,
+ const scoped_refptr<base::SingleThreadTaskRunner>& callback_task_runner,
+ UpdatedStoreReadyCallback callback) {
+ std::unique_ptr<V4Store> new_store(new V4Store(*this));
+
+ // TODO(vakh): The new store currently only picks up the new state. Do more.
+ new_store->state_ = response.new_client_state();
+
+ DVLOG(1) << "Created V4Store: " << new_store->DebugString();
Scott Hess - ex-Googler 2016/06/17 22:53:43 I'd have expected operator<< to do this for you.
vakh (use Gerrit instead) 2016/06/20 22:28:43 Done.
+
+ // new_store is done updating, pass it to the callback.
+ callback_task_runner->PostTask(
+ FROM_HERE, base::Bind(callback, base::Passed(&new_store)));
+}
+
+std::string V4Store::GetHumanReadableState() const {
+ std::string state_base64;
+ base::Base64Encode(state_, &state_base64);
+ return state_base64;
Scott Hess - ex-Googler 2016/06/17 22:53:43 If you really want to have this, just inline it in
vakh (use Gerrit instead) 2016/06/20 22:28:43 Done.
+}
+
} // namespace safe_browsing

Powered by Google App Engine
This is Rietveld 408576698