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 std::string value; | |
34 return base::SStringPrintf(&value, "path: %s; state: %s", | |
35 store_path_.value().c_str(), state_base64.c_str()); | |
Scott Hess - ex-Googler
2016/06/21 22:23:25
You should be able to drop |value| and just return
vakh (use Gerrit instead)
2016/06/23 06:23:50
Done.
| |
36 } | |
37 | |
21 bool V4Store::Reset() { | 38 bool V4Store::Reset() { |
22 // TODO(vakh): Implement skeleton. | 39 // TODO(vakh): Implement skeleton. |
40 state_ = ""; | |
23 return true; | 41 return true; |
24 } | 42 } |
25 | 43 |
44 void V4Store::ApplyUpdate( | |
45 const ListUpdateResponse& response, | |
46 const scoped_refptr<base::SingleThreadTaskRunner>& callback_task_runner, | |
47 UpdatedStoreReadyCallback callback) { | |
48 std::unique_ptr<V4Store> new_store( | |
49 new V4Store(this->task_runner_, this->store_path_)); | |
50 | |
51 // TODO(vakh): The new store currently only picks up the new state. Do more. | |
52 new_store->state_ = response.new_client_state(); | |
53 | |
54 // new_store is done updating, pass it to the callback. | |
55 callback_task_runner->PostTask( | |
56 FROM_HERE, base::Bind(callback, base::Passed(&new_store))); | |
57 } | |
58 | |
26 } // namespace safe_browsing | 59 } // namespace safe_browsing |
OLD | NEW |