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 : store_path_(store_path), task_runner_(task_runner) {} |
18 | 26 |
19 V4Store::~V4Store() {} | 27 V4Store::~V4Store() {} |
20 | 28 |
| 29 std::string V4Store::DebugString() const { |
| 30 std::string state_base64; |
| 31 base::Base64Encode(state_, &state_base64); |
| 32 |
| 33 return base::StringPrintf("path: %s; state: %s", store_path_.value().c_str(), |
| 34 state_base64.c_str()); |
| 35 } |
| 36 |
21 bool V4Store::Reset() { | 37 bool V4Store::Reset() { |
22 // TODO(vakh): Implement skeleton. | 38 // TODO(vakh): Implement skeleton. |
| 39 state_ = ""; |
23 return true; | 40 return true; |
24 } | 41 } |
25 | 42 |
| 43 void V4Store::ApplyUpdate( |
| 44 const ListUpdateResponse& response, |
| 45 const scoped_refptr<base::SingleThreadTaskRunner>& callback_task_runner, |
| 46 UpdatedStoreReadyCallback callback) { |
| 47 std::unique_ptr<V4Store> new_store( |
| 48 new V4Store(this->task_runner_, this->store_path_)); |
| 49 |
| 50 // TODO(vakh): The new store currently only picks up the new state. Do more. |
| 51 new_store->state_ = response.new_client_state(); |
| 52 |
| 53 // new_store is done updating, pass it to the callback. |
| 54 callback_task_runner->PostTask( |
| 55 FROM_HERE, base::Bind(callback, base::Passed(&new_store))); |
| 56 } |
| 57 |
26 } // namespace safe_browsing | 58 } // namespace safe_browsing |
OLD | NEW |