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 "extensions/browser/computed_hashes.h" | 5 #include "extensions/browser/computed_hashes.h" |
6 | 6 |
| 7 #include <memory> |
| 8 #include <utility> |
| 9 |
7 #include "base/base64.h" | 10 #include "base/base64.h" |
8 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
9 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
10 #include "base/json/json_reader.h" | 13 #include "base/json/json_reader.h" |
11 #include "base/json/json_writer.h" | 14 #include "base/json/json_writer.h" |
12 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
13 #include "base/values.h" | 16 #include "base/values.h" |
14 #include "crypto/secure_hash.h" | 17 #include "crypto/secure_hash.h" |
15 #include "crypto/sha2.h" | 18 #include "crypto/sha2.h" |
16 | 19 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 | 129 |
127 ComputedHashes::Writer::Writer() : file_list_(new base::ListValue) { | 130 ComputedHashes::Writer::Writer() : file_list_(new base::ListValue) { |
128 } | 131 } |
129 | 132 |
130 ComputedHashes::Writer::~Writer() { | 133 ComputedHashes::Writer::~Writer() { |
131 } | 134 } |
132 | 135 |
133 void ComputedHashes::Writer::AddHashes(const base::FilePath& relative_path, | 136 void ComputedHashes::Writer::AddHashes(const base::FilePath& relative_path, |
134 int block_size, | 137 int block_size, |
135 const std::vector<std::string>& hashes) { | 138 const std::vector<std::string>& hashes) { |
136 base::DictionaryValue* dict = new base::DictionaryValue(); | 139 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
137 base::ListValue* block_hashes = new base::ListValue(); | 140 base::ListValue* block_hashes = new base::ListValue(); |
138 file_list_->Append(dict); | |
139 dict->SetString(kPathKey, | 141 dict->SetString(kPathKey, |
140 relative_path.NormalizePathSeparatorsTo('/').AsUTF8Unsafe()); | 142 relative_path.NormalizePathSeparatorsTo('/').AsUTF8Unsafe()); |
141 dict->SetInteger(kBlockSizeKey, block_size); | 143 dict->SetInteger(kBlockSizeKey, block_size); |
142 dict->Set(kBlockHashesKey, block_hashes); | 144 dict->Set(kBlockHashesKey, block_hashes); |
| 145 file_list_->Append(std::move(dict)); |
143 | 146 |
144 for (std::vector<std::string>::const_iterator i = hashes.begin(); | 147 for (std::vector<std::string>::const_iterator i = hashes.begin(); |
145 i != hashes.end(); | 148 i != hashes.end(); |
146 ++i) { | 149 ++i) { |
147 std::string encoded; | 150 std::string encoded; |
148 base::Base64Encode(*i, &encoded); | 151 base::Base64Encode(*i, &encoded); |
149 block_hashes->AppendString(encoded); | 152 block_hashes->AppendString(encoded); |
150 } | 153 } |
151 } | 154 } |
152 | 155 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 | 191 |
189 // If |contents| is empty, then we want to just exit here. | 192 // If |contents| is empty, then we want to just exit here. |
190 if (bytes_to_read == 0) | 193 if (bytes_to_read == 0) |
191 break; | 194 break; |
192 | 195 |
193 offset += bytes_to_read; | 196 offset += bytes_to_read; |
194 } while (offset < contents.size()); | 197 } while (offset < contents.size()); |
195 } | 198 } |
196 | 199 |
197 } // namespace extensions | 200 } // namespace extensions |
OLD | NEW |