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

Side by Side Diff: components/safe_browsing_db/v4_database.cc

Issue 2384893002: PVer4: Test checksum on startup outside the hotpath of DB load (Closed)
Patch Set: Verify that the checksum check happens async Created 4 years, 2 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 unified diff | Download patch
OLDNEW
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> 5 #include <memory>
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/debug/leak_annotations.h" 8 #include "base/debug/leak_annotations.h"
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 } 62 }
63 63
64 const base::FilePath store_path = base_path.AppendASCII(it.filename()); 64 const base::FilePath store_path = base_path.AppendASCII(it.filename());
65 (*store_map)[it.list_id()].reset( 65 (*store_map)[it.list_id()].reset(
66 factory_->CreateV4Store(db_task_runner, store_path)); 66 factory_->CreateV4Store(db_task_runner, store_path));
67 } 67 }
68 std::unique_ptr<V4Database> v4_database( 68 std::unique_ptr<V4Database> v4_database(
69 new V4Database(db_task_runner, std::move(store_map))); 69 new V4Database(db_task_runner, std::move(store_map)));
70 70
71 // Database is done loading, pass it to the new_db_callback on the caller's 71 // Database is done loading, pass it to the new_db_callback on the caller's
72 // thread. 72 // thread. This would unblock resource loads.
73 callback_task_runner->PostTask( 73 callback_task_runner->PostTask(
74 FROM_HERE, base::Bind(new_db_callback, base::Passed(&v4_database))); 74 FROM_HERE, base::Bind(new_db_callback, base::Passed(&v4_database)));
75 } 75 }
76 76
77 V4Database::V4Database( 77 V4Database::V4Database(
78 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner, 78 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner,
79 std::unique_ptr<StoreMap> store_map) 79 std::unique_ptr<StoreMap> store_map)
80 : db_task_runner_(db_task_runner), 80 : db_task_runner_(db_task_runner),
81 store_map_(std::move(store_map)), 81 store_map_(std::move(store_map)),
82 pending_store_updates_(0) { 82 pending_store_updates_(0) {
83 DCHECK(db_task_runner->RunsTasksOnCurrentThread()); 83 DCHECK(db_task_runner->RunsTasksOnCurrentThread());
84 // TODO(vakh): Implement skeleton
85 } 84 }
86 85
87 // static 86 // static
88 void V4Database::Destroy(std::unique_ptr<V4Database> v4_database) { 87 void V4Database::Destroy(std::unique_ptr<V4Database> v4_database) {
88 DCHECK_CURRENTLY_ON(BrowserThread::IO);
89 V4Database* v4_database_raw = v4_database.release(); 89 V4Database* v4_database_raw = v4_database.release();
90 if (v4_database_raw) { 90 if (v4_database_raw) {
91 v4_database_raw->db_task_runner_->DeleteSoon(FROM_HERE, v4_database_raw); 91 v4_database_raw->db_task_runner_->DeleteSoon(FROM_HERE, v4_database_raw);
92 } 92 }
93 } 93 }
94 94
95 V4Database::~V4Database() { 95 V4Database::~V4Database() {
96 DCHECK(db_task_runner_->RunsTasksOnCurrentThread()); 96 DCHECK(db_task_runner_->RunsTasksOnCurrentThread());
97 } 97 }
98 98
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 (*store_map_)[identifier] = std::move(new_store); 145 (*store_map_)[identifier] = std::move(new_store);
146 } 146 }
147 147
148 pending_store_updates_--; 148 pending_store_updates_--;
149 if (!pending_store_updates_) { 149 if (!pending_store_updates_) {
150 db_updated_callback_.Run(); 150 db_updated_callback_.Run();
151 db_updated_callback_.Reset(); 151 db_updated_callback_.Reset();
152 } 152 }
153 } 153 }
154 154
155 bool V4Database::ResetDatabase() {
156 DCHECK(db_task_runner_->RunsTasksOnCurrentThread());
157 bool reset_success = true;
158 for (const auto& store_map_iter : *store_map_) {
159 if (!store_map_iter.second->Reset()) {
160 reset_success = false;
161 }
162 }
163 return reset_success;
164 }
165
166 std::unique_ptr<StoreStateMap> V4Database::GetStoreStateMap() { 155 std::unique_ptr<StoreStateMap> V4Database::GetStoreStateMap() {
167 std::unique_ptr<StoreStateMap> store_state_map = 156 std::unique_ptr<StoreStateMap> store_state_map =
168 base::MakeUnique<StoreStateMap>(); 157 base::MakeUnique<StoreStateMap>();
169 for (const auto& store_map_iter : *store_map_) { 158 for (const auto& store_map_iter : *store_map_) {
170 (*store_state_map)[store_map_iter.first] = store_map_iter.second->state(); 159 (*store_state_map)[store_map_iter.first] = store_map_iter.second->state();
171 } 160 }
172 return store_state_map; 161 return store_state_map;
173 } 162 }
174 163
175 void V4Database::GetStoresMatchingFullHash( 164 void V4Database::GetStoresMatchingFullHash(
176 const FullHash& full_hash, 165 const FullHash& full_hash,
177 const StoresToCheck& stores_to_check, 166 const StoresToCheck& stores_to_check,
178 StoreAndHashPrefixes* matched_store_and_hash_prefixes) { 167 StoreAndHashPrefixes* matched_store_and_hash_prefixes) {
179 DCHECK_CURRENTLY_ON(BrowserThread::IO); 168 DCHECK_CURRENTLY_ON(BrowserThread::IO);
180 matched_store_and_hash_prefixes->clear(); 169 matched_store_and_hash_prefixes->clear();
181 for (const ListIdentifier& identifier : stores_to_check) { 170 for (const ListIdentifier& identifier : stores_to_check) {
182 const auto& store_pair = store_map_->find(identifier); 171 const auto& store_pair = store_map_->find(identifier);
183 DCHECK(store_pair != store_map_->end()); 172 DCHECK(store_pair != store_map_->end());
184 const std::unique_ptr<V4Store>& store = store_pair->second; 173 const std::unique_ptr<V4Store>& store = store_pair->second;
185 HashPrefix hash_prefix = store->GetMatchingHashPrefix(full_hash); 174 HashPrefix hash_prefix = store->GetMatchingHashPrefix(full_hash);
186 if (!hash_prefix.empty()) { 175 if (!hash_prefix.empty()) {
187 matched_store_and_hash_prefixes->emplace_back(identifier, hash_prefix); 176 matched_store_and_hash_prefixes->emplace_back(identifier, hash_prefix);
188 } 177 }
189 } 178 }
190 } 179 }
191 180
181 void V4Database::ResetStores(
182 const std::vector<ListIdentifier>& stores_to_reset) {
183 DCHECK_CURRENTLY_ON(BrowserThread::IO);
184 for (const ListIdentifier& identifier : stores_to_reset) {
185 store_map_->at(identifier)->Reset();
186 }
187 }
188
189 void V4Database::VerifyChecksum(
190 DatabaseReadyForUpdatesCallback db_ready_for_updates_callback) {
191 DCHECK_CURRENTLY_ON(BrowserThread::IO);
192 // TODO(vakh): Consider using PostTaskAndReply instead.
193 const scoped_refptr<base::SingleThreadTaskRunner> callback_task_runner =
194 base::ThreadTaskRunnerHandle::Get();
195 db_task_runner_->PostTask(
196 FROM_HERE, base::Bind(&V4Database::VerifyChecksumOnTaskRunner,
197 base::Unretained(this), callback_task_runner,
198 db_ready_for_updates_callback));
199 }
200
201 void V4Database::VerifyChecksumOnTaskRunner(
202 const scoped_refptr<base::SingleThreadTaskRunner>& callback_task_runner,
203 DatabaseReadyForUpdatesCallback db_ready_for_updates_callback) {
204 std::vector<ListIdentifier> stores_to_reset;
205 for (const auto& store_map_iter : *store_map_) {
206 if (!store_map_iter.second->VerifyChecksum()) {
207 stores_to_reset.push_back(store_map_iter.first);
208 }
209 }
210
211 callback_task_runner->PostTask(
212 FROM_HERE, base::Bind(db_ready_for_updates_callback, stores_to_reset));
213 }
214
192 ListInfo::ListInfo(const bool fetch_updates, 215 ListInfo::ListInfo(const bool fetch_updates,
193 const std::string& filename, 216 const std::string& filename,
194 const ListIdentifier& list_id, 217 const ListIdentifier& list_id,
195 const SBThreatType sb_threat_type) 218 const SBThreatType sb_threat_type)
196 : fetch_updates_(fetch_updates), 219 : fetch_updates_(fetch_updates),
197 filename_(filename), 220 filename_(filename),
198 list_id_(list_id), 221 list_id_(list_id),
199 sb_threat_type_(sb_threat_type) { 222 sb_threat_type_(sb_threat_type) {
200 DCHECK(!fetch_updates_ || !filename_.empty()); 223 DCHECK(!fetch_updates_ || !filename_.empty());
201 DCHECK_NE(SB_THREAT_TYPE_SAFE, sb_threat_type_); 224 DCHECK_NE(SB_THREAT_TYPE_SAFE, sb_threat_type_);
202 } 225 }
203 226
204 ListInfo::~ListInfo() {} 227 ListInfo::~ListInfo() {}
205 228
206 } // namespace safe_browsing 229 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « components/safe_browsing_db/v4_database.h ('k') | components/safe_browsing_db/v4_database_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698