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

Side by Side Diff: chrome/utility/safe_browsing/mac/udif.cc

Issue 1899083002: Convert //chrome 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/utility/safe_browsing/mac/udif.h" 5 #include "chrome/utility/safe_browsing/mac/udif.h"
6 6
7 #include <CoreFoundation/CoreFoundation.h> 7 #include <CoreFoundation/CoreFoundation.h>
8 #include <bzlib.h> 8 #include <bzlib.h>
9 #include <libkern/OSByteOrder.h> 9 #include <libkern/OSByteOrder.h>
10 #include <uuid/uuid.h> 10 #include <uuid/uuid.h>
11 11
12 #include <algorithm> 12 #include <algorithm>
13 #include <utility> 13 #include <utility>
14 14
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/mac/foundation_util.h" 16 #include "base/mac/foundation_util.h"
17 #include "base/mac/scoped_cftyperef.h" 17 #include "base/mac/scoped_cftyperef.h"
18 #include "base/macros.h" 18 #include "base/macros.h"
19 #include "base/memory/ptr_util.h"
19 #include "base/numerics/safe_math.h" 20 #include "base/numerics/safe_math.h"
20 #include "base/strings/sys_string_conversions.h" 21 #include "base/strings/sys_string_conversions.h"
21 #include "chrome/utility/safe_browsing/mac/convert_big_endian.h" 22 #include "chrome/utility/safe_browsing/mac/convert_big_endian.h"
22 #include "chrome/utility/safe_browsing/mac/read_stream.h" 23 #include "chrome/utility/safe_browsing/mac/read_stream.h"
23 #include "third_party/zlib/zlib.h" 24 #include "third_party/zlib/zlib.h"
24 25
25 namespace safe_browsing { 26 namespace safe_browsing {
26 namespace dmg { 27 namespace dmg {
27 28
28 #pragma pack(push, 1) 29 #pragma pack(push, 1)
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 bool Read(uint8_t* buffer, size_t buffer_size, size_t* bytes_read) override; 228 bool Read(uint8_t* buffer, size_t buffer_size, size_t* bytes_read) override;
228 // Seek only supports SEEK_SET and SEEK_CUR. 229 // Seek only supports SEEK_SET and SEEK_CUR.
229 off_t Seek(off_t offset, int whence) override; 230 off_t Seek(off_t offset, int whence) override;
230 231
231 private: 232 private:
232 ReadStream* const stream_; // The UDIF stream. 233 ReadStream* const stream_; // The UDIF stream.
233 const uint16_t block_size_; // The UDIF block size. 234 const uint16_t block_size_; // The UDIF block size.
234 const UDIFBlock* const block_; // The block for this partition. 235 const UDIFBlock* const block_; // The block for this partition.
235 uint64_t current_chunk_; // The current chunk number. 236 uint64_t current_chunk_; // The current chunk number.
236 // The current chunk stream. 237 // The current chunk stream.
237 scoped_ptr<UDIFBlockChunkReadStream> chunk_stream_; 238 std::unique_ptr<UDIFBlockChunkReadStream> chunk_stream_;
238 239
239 DISALLOW_COPY_AND_ASSIGN(UDIFPartitionReadStream); 240 DISALLOW_COPY_AND_ASSIGN(UDIFPartitionReadStream);
240 }; 241 };
241 242
242 // A ReadStream for a single block chunk, which transparently handles 243 // A ReadStream for a single block chunk, which transparently handles
243 // decompression. 244 // decompression.
244 class UDIFBlockChunkReadStream : public ReadStream { 245 class UDIFBlockChunkReadStream : public ReadStream {
245 public: 246 public:
246 UDIFBlockChunkReadStream(ReadStream* stream, 247 UDIFBlockChunkReadStream(ReadStream* stream,
247 uint16_t block_size, 248 uint16_t block_size,
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 } 332 }
332 333
333 size_t UDIFParser::GetPartitionSize(size_t part_number) { 334 size_t UDIFParser::GetPartitionSize(size_t part_number) {
334 DCHECK_LT(part_number, blocks_.size()); 335 DCHECK_LT(part_number, blocks_.size());
335 auto size = 336 auto size =
336 base::CheckedNumeric<size_t>(blocks_[part_number]->sector_count()) * 337 base::CheckedNumeric<size_t>(blocks_[part_number]->sector_count()) *
337 block_size_; 338 block_size_;
338 return size.ValueOrDie(); 339 return size.ValueOrDie();
339 } 340 }
340 341
341 scoped_ptr<ReadStream> UDIFParser::GetPartitionReadStream(size_t part_number) { 342 std::unique_ptr<ReadStream> UDIFParser::GetPartitionReadStream(
343 size_t part_number) {
342 DCHECK_LT(part_number, blocks_.size()); 344 DCHECK_LT(part_number, blocks_.size());
343 return make_scoped_ptr( 345 return base::WrapUnique(
344 new UDIFPartitionReadStream(stream_, block_size_, blocks_[part_number])); 346 new UDIFPartitionReadStream(stream_, block_size_, blocks_[part_number]));
345 } 347 }
346 348
347 bool UDIFParser::ParseBlkx() { 349 bool UDIFParser::ParseBlkx() {
348 UDIFResourceFile trailer; 350 UDIFResourceFile trailer;
349 if (stream_->Seek(-sizeof(trailer), SEEK_END) == -1) 351 if (stream_->Seek(-sizeof(trailer), SEEK_END) == -1)
350 return false; 352 return false;
351 353
352 if (!stream_->ReadType(&trailer)) { 354 if (!stream_->ReadType(&trailer)) {
353 DLOG(ERROR) << "Failed to read UDIFResourceFile"; 355 DLOG(ERROR) << "Failed to read UDIFResourceFile";
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 CFSTR("Data")); 429 CFSTR("Data"));
428 if (!data) { 430 if (!data) {
429 DLOG(ERROR) << "Skipping block " << i 431 DLOG(ERROR) << "Skipping block " << i
430 << " because it has no Data section"; 432 << " because it has no Data section";
431 continue; 433 continue;
432 } 434 }
433 435
434 // Copy the block table out of the plist. 436 // Copy the block table out of the plist.
435 auto block_data = 437 auto block_data =
436 reinterpret_cast<const UDIFBlockData*>(CFDataGetBytePtr(data)); 438 reinterpret_cast<const UDIFBlockData*>(CFDataGetBytePtr(data));
437 scoped_ptr<UDIFBlock> block(new UDIFBlock(block_data)); 439 std::unique_ptr<UDIFBlock> block(new UDIFBlock(block_data));
438 440
439 if (block->signature() != UDIFBlockData::kSignature) { 441 if (block->signature() != UDIFBlockData::kSignature) {
440 DLOG(ERROR) << "Skipping block " << i << " because its signature does not" 442 DLOG(ERROR) << "Skipping block " << i << " because its signature does not"
441 << " match, is 0x" << std::hex << block->signature(); 443 << " match, is 0x" << std::hex << block->signature();
442 continue; 444 continue;
443 } 445 }
444 if (block->version() != UDIFBlockData::kVersion) { 446 if (block->version() != UDIFBlockData::kVersion) {
445 DLOG(ERROR) << "Skipping block " << i << "because its version does not " 447 DLOG(ERROR) << "Skipping block " << i << "because its version does not "
446 << "match, is " << block->version(); 448 << "match, is " << block->version();
447 continue; 449 continue;
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
787 << chunk_->compressed_offset; 789 << chunk_->compressed_offset;
788 return false; 790 return false;
789 } 791 }
790 return true; 792 return true;
791 } 793 }
792 794
793 } // namespace 795 } // namespace
794 796
795 } // namespace dmg 797 } // namespace dmg
796 } // namespace safe_browsing 798 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « chrome/utility/safe_browsing/mac/udif.h ('k') | chrome/utility/safe_browsing/mac/udif_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698