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

Side by Side Diff: chrome/browser/safe_browsing/safe_browsing_store_file.cc

Issue 7466003: MD5Update function uses StringPiece instead of raw buffer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove line from license. Created 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/safe_browsing/safe_browsing_store_file.h" 5 #include "chrome/browser/safe_browsing/safe_browsing_store_file.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/md5.h" 8 #include "base/md5.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 10
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 51
52 // Read an array of |nmemb| items from |fp| into |ptr|, and fold the 52 // Read an array of |nmemb| items from |fp| into |ptr|, and fold the
53 // input data into the checksum in |context|, if non-NULL. Return 53 // input data into the checksum in |context|, if non-NULL. Return
54 // true on success. 54 // true on success.
55 template <class T> 55 template <class T>
56 bool ReadArray(T* ptr, size_t nmemb, FILE* fp, base::MD5Context* context) { 56 bool ReadArray(T* ptr, size_t nmemb, FILE* fp, base::MD5Context* context) {
57 const size_t ret = fread(ptr, sizeof(T), nmemb, fp); 57 const size_t ret = fread(ptr, sizeof(T), nmemb, fp);
58 if (ret != nmemb) 58 if (ret != nmemb)
59 return false; 59 return false;
60 60
61 if (context) 61 if (context) {
62 base::MD5Update(context, ptr, sizeof(T) * nmemb); 62 base::MD5Update(context,
63 base::StringPiece(reinterpret_cast<char*>(ptr),
64 sizeof(T) * nmemb));
65 }
63 return true; 66 return true;
64 } 67 }
65 68
66 // Write an array of |nmemb| items from |ptr| to |fp|, and fold the 69 // Write an array of |nmemb| items from |ptr| to |fp|, and fold the
67 // output data into the checksum in |context|, if non-NULL. Return 70 // output data into the checksum in |context|, if non-NULL. Return
68 // true on success. 71 // true on success.
69 template <class T> 72 template <class T>
70 bool WriteArray(const T* ptr, size_t nmemb, FILE* fp, 73 bool WriteArray(const T* ptr, size_t nmemb, FILE* fp,
71 base::MD5Context* context) { 74 base::MD5Context* context) {
72 const size_t ret = fwrite(ptr, sizeof(T), nmemb, fp); 75 const size_t ret = fwrite(ptr, sizeof(T), nmemb, fp);
73 if (ret != nmemb) 76 if (ret != nmemb)
74 return false; 77 return false;
75 78
76 if (context) 79 if (context) {
77 base::MD5Update(context, ptr, sizeof(T) * nmemb); 80 base::MD5Update(context,
81 base::StringPiece(reinterpret_cast<const char*>(ptr),
82 sizeof(T) * nmemb));
83 }
78 84
79 return true; 85 return true;
80 } 86 }
81 87
82 // Expand |values| to fit |count| new items, read those items from 88 // Expand |values| to fit |count| new items, read those items from
83 // |fp| and fold them into the checksum in |context|. Returns true on 89 // |fp| and fold them into the checksum in |context|. Returns true on
84 // success. 90 // success.
85 template <class T> 91 template <class T>
86 bool ReadToVector(std::vector<T>* values, size_t count, FILE* fp, 92 bool ReadToVector(std::vector<T>* values, size_t count, FILE* fp,
87 base::MD5Context* context) { 93 base::MD5Context* context) {
(...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after
722 out->insert(out->end(), sub_chunks_cache_.begin(), sub_chunks_cache_.end()); 728 out->insert(out->end(), sub_chunks_cache_.begin(), sub_chunks_cache_.end());
723 } 729 }
724 730
725 void SafeBrowsingStoreFile::DeleteAddChunk(int32 chunk_id) { 731 void SafeBrowsingStoreFile::DeleteAddChunk(int32 chunk_id) {
726 add_del_cache_.insert(chunk_id); 732 add_del_cache_.insert(chunk_id);
727 } 733 }
728 734
729 void SafeBrowsingStoreFile::DeleteSubChunk(int32 chunk_id) { 735 void SafeBrowsingStoreFile::DeleteSubChunk(int32 chunk_id) {
730 sub_del_cache_.insert(chunk_id); 736 sub_del_cache_.insert(chunk_id);
731 } 737 }
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/prefix_set_unittest.cc ('k') | chrome/browser/sync/util/user_settings.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698