OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/common/safe_browsing/binary_feature_extractor.h" | 5 #include "chrome/common/safe_browsing/binary_feature_extractor.h" |
6 | 6 |
| 7 #include <utility> |
| 8 |
7 #include "base/files/file.h" | 9 #include "base/files/file.h" |
8 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
9 #include "base/files/memory_mapped_file.h" | 11 #include "base/files/memory_mapped_file.h" |
10 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
11 #include "chrome/common/safe_browsing/csd.pb.h" | 13 #include "chrome/common/safe_browsing/csd.pb.h" |
12 #include "crypto/secure_hash.h" | 14 #include "crypto/secure_hash.h" |
13 #include "crypto/sha2.h" | 15 #include "crypto/sha2.h" |
14 | 16 |
15 namespace safe_browsing { | 17 namespace safe_browsing { |
16 | 18 |
(...skipping 12 matching lines...) Expand all Loading... |
29 return ExtractImageFeaturesFromData(mapped_file.data(), mapped_file.length(), | 31 return ExtractImageFeaturesFromData(mapped_file.data(), mapped_file.length(), |
30 options, image_headers, signed_data); | 32 options, image_headers, signed_data); |
31 } | 33 } |
32 | 34 |
33 bool BinaryFeatureExtractor::ExtractImageFeaturesFromFile( | 35 bool BinaryFeatureExtractor::ExtractImageFeaturesFromFile( |
34 base::File file, | 36 base::File file, |
35 ExtractHeadersOption options, | 37 ExtractHeadersOption options, |
36 ClientDownloadRequest_ImageHeaders* image_headers, | 38 ClientDownloadRequest_ImageHeaders* image_headers, |
37 google::protobuf::RepeatedPtrField<std::string>* signed_data) { | 39 google::protobuf::RepeatedPtrField<std::string>* signed_data) { |
38 base::MemoryMappedFile mapped_file; | 40 base::MemoryMappedFile mapped_file; |
39 if (!mapped_file.Initialize(file.Pass())) | 41 if (!mapped_file.Initialize(std::move(file))) |
40 return false; | 42 return false; |
41 return ExtractImageFeaturesFromData(mapped_file.data(), mapped_file.length(), | 43 return ExtractImageFeaturesFromData(mapped_file.data(), mapped_file.length(), |
42 options, image_headers, signed_data); | 44 options, image_headers, signed_data); |
43 } | 45 } |
44 | 46 |
45 void BinaryFeatureExtractor::ExtractDigest( | 47 void BinaryFeatureExtractor::ExtractDigest( |
46 const base::FilePath& file_path, | 48 const base::FilePath& file_path, |
47 ClientDownloadRequest_Digests* digests) { | 49 ClientDownloadRequest_Digests* digests) { |
48 base::File file(file_path, base::File::FLAG_OPEN | base::File::FLAG_READ); | 50 base::File file(file_path, base::File::FLAG_OPEN | base::File::FLAG_READ); |
49 if (file.IsValid()) { | 51 if (file.IsValid()) { |
(...skipping 10 matching lines...) Expand all Loading... |
60 } | 62 } |
61 if (!len) { | 63 if (!len) { |
62 uint8_t hash[crypto::kSHA256Length]; | 64 uint8_t hash[crypto::kSHA256Length]; |
63 ctx->Finish(hash, sizeof(hash)); | 65 ctx->Finish(hash, sizeof(hash)); |
64 digests->set_sha256(hash, sizeof(hash)); | 66 digests->set_sha256(hash, sizeof(hash)); |
65 } | 67 } |
66 } | 68 } |
67 } | 69 } |
68 | 70 |
69 } // namespace safe_browsing | 71 } // namespace safe_browsing |
OLD | NEW |