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

Side by Side Diff: extensions/browser/computed_hashes.cc

Issue 1909773002: Convert //extensions/browser from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 8 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
« no previous file with comments | « extensions/browser/computed_hashes.h ('k') | extensions/browser/content_hash_fetcher.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/base64.h" 7 #include "base/base64.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/json/json_reader.h" 10 #include "base/json/json_reader.h"
(...skipping 19 matching lines...) Expand all
30 30
31 ComputedHashes::Reader::~Reader() { 31 ComputedHashes::Reader::~Reader() {
32 } 32 }
33 33
34 bool ComputedHashes::Reader::InitFromFile(const base::FilePath& path) { 34 bool ComputedHashes::Reader::InitFromFile(const base::FilePath& path) {
35 std::string contents; 35 std::string contents;
36 if (!base::ReadFileToString(path, &contents)) 36 if (!base::ReadFileToString(path, &contents))
37 return false; 37 return false;
38 38
39 base::DictionaryValue* top_dictionary = NULL; 39 base::DictionaryValue* top_dictionary = NULL;
40 scoped_ptr<base::Value> value(base::JSONReader::Read(contents)); 40 std::unique_ptr<base::Value> value(base::JSONReader::Read(contents));
41 if (!value.get() || !value->GetAsDictionary(&top_dictionary)) 41 if (!value.get() || !value->GetAsDictionary(&top_dictionary))
42 return false; 42 return false;
43 43
44 // For now we don't support forwards or backwards compatability in the 44 // For now we don't support forwards or backwards compatability in the
45 // format, so we return false on version mismatch. 45 // format, so we return false on version mismatch.
46 int version = 0; 46 int version = 0;
47 if (!top_dictionary->GetInteger(kVersionKey, &version) || version != kVersion) 47 if (!top_dictionary->GetInteger(kVersionKey, &version) || version != kVersion)
48 return false; 48 return false;
49 49
50 base::ListValue* all_hashes = NULL; 50 base::ListValue* all_hashes = NULL;
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 void ComputedHashes::ComputeHashesForContent(const std::string& contents, 170 void ComputedHashes::ComputeHashesForContent(const std::string& contents,
171 size_t block_size, 171 size_t block_size,
172 std::vector<std::string>* hashes) { 172 std::vector<std::string>* hashes) {
173 size_t offset = 0; 173 size_t offset = 0;
174 // Even when the contents is empty, we want to output at least one hash 174 // Even when the contents is empty, we want to output at least one hash
175 // block (the hash of the empty string). 175 // block (the hash of the empty string).
176 do { 176 do {
177 const char* block_start = contents.data() + offset; 177 const char* block_start = contents.data() + offset;
178 DCHECK(offset <= contents.size()); 178 DCHECK(offset <= contents.size());
179 size_t bytes_to_read = std::min(contents.size() - offset, block_size); 179 size_t bytes_to_read = std::min(contents.size() - offset, block_size);
180 scoped_ptr<crypto::SecureHash> hash( 180 std::unique_ptr<crypto::SecureHash> hash(
181 crypto::SecureHash::Create(crypto::SecureHash::SHA256)); 181 crypto::SecureHash::Create(crypto::SecureHash::SHA256));
182 hash->Update(block_start, bytes_to_read); 182 hash->Update(block_start, bytes_to_read);
183 183
184 hashes->push_back(std::string()); 184 hashes->push_back(std::string());
185 std::string* buffer = &(hashes->back()); 185 std::string* buffer = &(hashes->back());
186 buffer->resize(crypto::kSHA256Length); 186 buffer->resize(crypto::kSHA256Length);
187 hash->Finish(string_as_array(buffer), buffer->size()); 187 hash->Finish(string_as_array(buffer), buffer->size());
188 188
189 // If |contents| is empty, then we want to just exit here. 189 // If |contents| is empty, then we want to just exit here.
190 if (bytes_to_read == 0) 190 if (bytes_to_read == 0)
191 break; 191 break;
192 192
193 offset += bytes_to_read; 193 offset += bytes_to_read;
194 } while (offset < contents.size()); 194 } while (offset < contents.size());
195 } 195 }
196 196
197 } // namespace extensions 197 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/computed_hashes.h ('k') | extensions/browser/content_hash_fetcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698