Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "base/base64.h" | |
| 6 #include "base/bind.h" | |
| 7 #include "base/strings/stringprintf.h" | |
| 5 #include "components/safe_browsing_db/v4_store.h" | 8 #include "components/safe_browsing_db/v4_store.h" |
| 6 | 9 |
| 7 namespace safe_browsing { | 10 namespace safe_browsing { |
| 8 | 11 |
| 12 std::ostream& operator<<(std::ostream& os, const V4Store& store) { | |
| 13 os << store.DebugString(); | |
| 14 return os; | |
| 15 } | |
| 16 | |
| 9 V4Store* V4StoreFactory::CreateV4Store( | 17 V4Store* V4StoreFactory::CreateV4Store( |
| 10 const scoped_refptr<base::SequencedTaskRunner>& task_runner, | 18 const scoped_refptr<base::SequencedTaskRunner>& task_runner, |
| 11 const base::FilePath& store_path) { | 19 const base::FilePath& store_path) { |
| 12 return new V4Store(task_runner, store_path); | 20 return new V4Store(task_runner, store_path); |
| 13 } | 21 } |
| 14 | 22 |
| 15 V4Store::V4Store(const scoped_refptr<base::SequencedTaskRunner>& task_runner, | 23 V4Store::V4Store(const scoped_refptr<base::SequencedTaskRunner>& task_runner, |
| 16 const base::FilePath& store_path) | 24 const base::FilePath& store_path) |
| 17 : task_runner_(task_runner), store_path_(store_path) {} | 25 : task_runner_(task_runner), store_path_(store_path) {} |
| 18 | 26 |
| 19 V4Store::~V4Store() {} | 27 V4Store::V4Store(const V4Store& other) |
| 28 : task_runner_(other.task_runner_), store_path_(other.store_path_) {} | |
| 29 | |
| 30 V4Store::~V4Store() { | |
| 31 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.
| |
| 32 } | |
| 33 | |
| 34 std::string V4Store::DebugString() const { | |
| 35 std::string value; | |
| 36 base::SStringPrintf(&value, "path: %s; state: %s", | |
| 37 store_path_.value().c_str(), | |
| 38 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.
| |
| 39 return value; | |
| 40 } | |
| 20 | 41 |
| 21 bool V4Store::Reset() { | 42 bool V4Store::Reset() { |
| 22 // TODO(vakh): Implement skeleton. | 43 // TODO(vakh): Implement skeleton. |
| 44 state_ = ""; | |
| 23 return true; | 45 return true; |
| 24 } | 46 } |
| 25 | 47 |
| 48 void V4Store::ApplyUpdate( | |
| 49 const ListUpdateResponse& response, | |
| 50 const scoped_refptr<base::SingleThreadTaskRunner>& callback_task_runner, | |
| 51 UpdatedStoreReadyCallback callback) { | |
| 52 std::unique_ptr<V4Store> new_store(new V4Store(*this)); | |
| 53 | |
| 54 // TODO(vakh): The new store currently only picks up the new state. Do more. | |
| 55 new_store->state_ = response.new_client_state(); | |
| 56 | |
| 57 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.
| |
| 58 | |
| 59 // new_store is done updating, pass it to the callback. | |
| 60 callback_task_runner->PostTask( | |
| 61 FROM_HERE, base::Bind(callback, base::Passed(&new_store))); | |
| 62 } | |
| 63 | |
| 64 std::string V4Store::GetHumanReadableState() const { | |
| 65 std::string state_base64; | |
| 66 base::Base64Encode(state_, &state_base64); | |
| 67 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.
| |
| 68 } | |
| 69 | |
| 26 } // namespace safe_browsing | 70 } // namespace safe_browsing |
| OLD | NEW |