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 <memory> |
| 6 |
5 #include "components/safe_browsing_db/v4_database.h" | 7 #include "components/safe_browsing_db/v4_database.h" |
6 | 8 |
7 namespace safe_browsing { | 9 namespace safe_browsing { |
8 | 10 |
| 11 namespace { |
| 12 |
| 13 V4Store* CreateStore( |
| 14 const scoped_refptr<base::SequencedTaskRunner>& task_runner, |
| 15 const base::FilePath& store_path) { |
| 16 return new V4Store(task_runner, store_path); |
| 17 } |
| 18 |
| 19 } // namespace |
| 20 |
9 // static | 21 // static |
10 V4DatabaseFactory* V4Database::factory_ = NULL; | 22 V4DatabaseFactory* V4Database::factory_ = NULL; |
11 | 23 |
12 // static | 24 // static |
13 // Factory method, should be called on the Safe Browsing sequenced task runner, | 25 // Factory method, should be called on the Safe Browsing sequenced task runner, |
14 // which is also passed to the function as |db_task_runner|. | 26 // which is also passed to the function as |db_task_runner|. |
15 V4Database* V4Database::Create( | 27 V4Database* V4Database::Create( |
16 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner, | 28 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner, |
17 const base::FilePath& base_path, | 29 const base::FilePath& base_path, |
18 ListInfoMap list_info_map) { | 30 ListInfoMap list_info_map) { |
19 DCHECK(db_task_runner->RunsTasksOnCurrentThread()); | 31 DCHECK(db_task_runner->RunsTasksOnCurrentThread()); |
| 32 DCHECK(!base_path.empty()); |
| 33 DCHECK(!list_info_map.empty()); |
| 34 |
20 if (!factory_) { | 35 if (!factory_) { |
21 StoreMap store_map; | 36 StoreMap store_map; |
22 // TODO(vakh): Populate the store_map using list_suffix_map. | 37 |
| 38 for (const auto& list_info : list_info_map) { |
| 39 UpdateListIdentifier update_list_identifier = list_info.first; |
| 40 const base::FilePath::CharType suffix = list_info.second; |
| 41 |
| 42 const base::FilePath store_path = |
| 43 base::FilePath(base_path.value() + suffix); |
| 44 (*store_map)[update_list_identifier].reset( |
| 45 CreateStore(db_task_runner, store_path)); |
| 46 } |
23 return new V4Database(db_task_runner, std::move(store_map)); | 47 return new V4Database(db_task_runner, std::move(store_map)); |
24 } else { | 48 } else { |
25 return factory_->CreateV4Database(db_task_runner, base_path, list_info_map); | 49 return factory_->CreateV4Database(db_task_runner, base_path, list_info_map); |
26 } | 50 } |
27 } | 51 } |
28 | 52 |
29 V4Database::V4Database( | 53 V4Database::V4Database( |
30 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner, | 54 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner, |
31 StoreMap store_map) { | 55 StoreMap store_map) |
| 56 : db_task_runner_(db_task_runner), store_map_(std::move(store_map)) { |
32 // TODO(vakh): Implement skeleton | 57 // TODO(vakh): Implement skeleton |
33 } | 58 } |
34 | 59 |
35 V4Database::~V4Database() {} | 60 V4Database::~V4Database() {} |
36 | 61 |
37 bool V4Database::ResetDatabase() { | 62 bool V4Database::ResetDatabase() { |
38 // TODO(vakh): Delete the stores. Delete the backing files. | 63 bool reset_success = true; |
39 return true; | 64 for (const auto& store_id_and_store : *store_map_) { |
| 65 bool store_reset_success = store_id_and_store.second->Reset(); |
| 66 reset_success = reset_success && store_reset_success; |
| 67 } |
| 68 return reset_success; |
40 } | 69 } |
41 | 70 |
42 } // namespace safe_browsing | 71 } // namespace safe_browsing |
OLD | NEW |