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

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

Issue 2148673002: Parse the hash prefix map from the V4Store on disk. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@01_merge_only
Patch Set: Tiniest: typo: h->H Created 4 years, 5 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 "base/base64.h" 5 #include "base/base64.h"
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/files/file_util.h" 7 #include "base/files/file_util.h"
8 #include "base/metrics/histogram_macros.h" 8 #include "base/metrics/histogram_macros.h"
9 #include "base/metrics/sparse_histogram.h" 9 #include "base/metrics/sparse_histogram.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
(...skipping 22 matching lines...) Expand all
33 void RecordStoreWriteResult(StoreWriteResult result) { 33 void RecordStoreWriteResult(StoreWriteResult result) {
34 UMA_HISTOGRAM_ENUMERATION("SafeBrowsing.V4StoreWriteResult", result, 34 UMA_HISTOGRAM_ENUMERATION("SafeBrowsing.V4StoreWriteResult", result,
35 STORE_WRITE_RESULT_MAX); 35 STORE_WRITE_RESULT_MAX);
36 } 36 }
37 37
38 void RecordApplyUpdateResult(ApplyUpdateResult result) { 38 void RecordApplyUpdateResult(ApplyUpdateResult result) {
39 UMA_HISTOGRAM_ENUMERATION("SafeBrowsing.V4ApplyUpdateResult", result, 39 UMA_HISTOGRAM_ENUMERATION("SafeBrowsing.V4ApplyUpdateResult", result,
40 APPLY_UPDATE_RESULT_MAX); 40 APPLY_UPDATE_RESULT_MAX);
41 } 41 }
42 42
43 void RecordApplyUpdateResultWhenReadingFromDisk(ApplyUpdateResult result) {
44 UMA_HISTOGRAM_ENUMERATION(
45 "SafeBrowsing.V4ApplyUpdateResultWhenReadingFromDisk", result,
46 APPLY_UPDATE_RESULT_MAX);
47 }
48
43 // Returns the name of the temporary file used to buffer data for 49 // Returns the name of the temporary file used to buffer data for
44 // |filename|. Exported for unit tests. 50 // |filename|. Exported for unit tests.
45 const base::FilePath TemporaryFileForFilename(const base::FilePath& filename) { 51 const base::FilePath TemporaryFileForFilename(const base::FilePath& filename) {
46 return base::FilePath(filename.value() + FILE_PATH_LITERAL("_new")); 52 return base::FilePath(filename.value() + FILE_PATH_LITERAL("_new"));
47 } 53 }
48 54
49 } // namespace 55 } // namespace
50 56
51 std::ostream& operator<<(std::ostream& os, const V4Store& store) { 57 std::ostream& operator<<(std::ostream& os, const V4Store& store) {
52 os << store.DebugString(); 58 os << store.DebugString();
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 if (file_format.version_number() != kFileVersion) { 358 if (file_format.version_number() != kFileVersion) {
353 DVLOG(1) << "File version incompatible: " << file_format.version_number() 359 DVLOG(1) << "File version incompatible: " << file_format.version_number()
354 << "; expected: " << kFileVersion; 360 << "; expected: " << kFileVersion;
355 return FILE_VERSION_INCOMPATIBLE_FAILURE; 361 return FILE_VERSION_INCOMPATIBLE_FAILURE;
356 } 362 }
357 363
358 if (!file_format.has_list_update_response()) { 364 if (!file_format.has_list_update_response()) {
359 return HASH_PREFIX_INFO_MISSING_FAILURE; 365 return HASH_PREFIX_INFO_MISSING_FAILURE;
360 } 366 }
361 367
362 ListUpdateResponse list_update_response = file_format.list_update_response(); 368 const ListUpdateResponse& response = file_format.list_update_response();
363 state_ = list_update_response.new_client_state(); 369 ApplyUpdateResult apply_update_result = UpdateHashPrefixMapFromAdditions(
364 // TODO(vakh): Do more with what's read from the disk. 370 response.additions(), &hash_prefix_map_);
371 RecordApplyUpdateResultWhenReadingFromDisk(apply_update_result);
372 if (apply_update_result != APPLY_UPDATE_SUCCESS) {
373 hash_prefix_map_.clear();
374 return HASH_PREFIX_MAP_GENERATION_FAILURE;
375 }
365 376
377 state_ = response.new_client_state();
366 return READ_SUCCESS; 378 return READ_SUCCESS;
367 } 379 }
368 380
369 StoreWriteResult V4Store::WriteToDisk( 381 StoreWriteResult V4Store::WriteToDisk(
370 std::unique_ptr<ListUpdateResponse> response) const { 382 std::unique_ptr<ListUpdateResponse> response) const {
371 // Do not write partial updates to the disk. 383 // Do not write partial updates to the disk.
372 // After merging the updates, the ListUpdateResponse passed to this method 384 // After merging the updates, the ListUpdateResponse passed to this method
373 // should be a FULL_UPDATE. 385 // should be a FULL_UPDATE.
374 if (!response->has_response_type() || 386 if (!response->has_response_type() ||
375 response->response_type() != ListUpdateResponse::FULL_UPDATE) { 387 response->response_type() != ListUpdateResponse::FULL_UPDATE) {
(...skipping 20 matching lines...) Expand all
396 408
397 if (!base::Move(new_filename, store_path_)) { 409 if (!base::Move(new_filename, store_path_)) {
398 DVLOG(1) << "store_path_: " << store_path_.value(); 410 DVLOG(1) << "store_path_: " << store_path_.value();
399 return UNABLE_TO_RENAME_FAILURE; 411 return UNABLE_TO_RENAME_FAILURE;
400 } 412 }
401 413
402 return WRITE_SUCCESS; 414 return WRITE_SUCCESS;
403 } 415 }
404 416
405 } // namespace safe_browsing 417 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « components/safe_browsing_db/v4_store.h ('k') | components/safe_browsing_db/v4_store_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698