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

Side by Side Diff: chrome/browser/extensions/api/image_writer_private/destroy_partitions_operation.cc

Issue 170713007: Resubmit of 149313003: Significantly cleans up the ImageWriter Operation class and subclasses. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixes comments. Created 6 years, 10 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 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 "base/file_util.h" 5 #include "base/file_util.h"
6 #include "chrome/browser/extensions/api/image_writer_private/destroy_partitions_ operation.h" 6 #include "chrome/browser/extensions/api/image_writer_private/destroy_partitions_ operation.h"
7 #include "chrome/browser/extensions/api/image_writer_private/error_messages.h" 7 #include "chrome/browser/extensions/api/image_writer_private/error_messages.h"
8 8
9 namespace extensions { 9 namespace extensions {
10 namespace image_writer { 10 namespace image_writer {
11 11
12 // Number of bytes for the maximum partition table size. By wiping this many 12 // Number of bytes for the maximum partition table size. By wiping this many
13 // bytes we can essentially guarantee the header and associated information will 13 // bytes we can essentially guarantee the header and associated information will
14 // be wiped. See http://crbug.com/328246 for more information. 14 // be wiped. See http://crbug.com/328246 for more information.
15 const int kPartitionTableSize = 1 * 1024; 15 const int kPartitionTableSize = 1 * 1024;
16 16
17 DestroyPartitionsOperation::DestroyPartitionsOperation( 17 DestroyPartitionsOperation::DestroyPartitionsOperation(
18 base::WeakPtr<OperationManager> manager, 18 base::WeakPtr<OperationManager> manager,
19 const ExtensionId& extension_id, 19 const ExtensionId& extension_id,
20 const std::string& storage_unit_id) 20 const std::string& storage_unit_id)
21 : Operation(manager, extension_id, storage_unit_id) { 21 : Operation(manager, extension_id, storage_unit_id) {}
22 verify_write_ = false;
23 }
24 22
25 DestroyPartitionsOperation::~DestroyPartitionsOperation() {} 23 DestroyPartitionsOperation::~DestroyPartitionsOperation() {}
26 24
27 void DestroyPartitionsOperation::Start() { 25 void DestroyPartitionsOperation::StartImpl() {
28 if (!temp_dir_.CreateUniqueTempDir()) {
29 Error(error::kTempDirError);
30 return;
31 }
32
33 if (!base::CreateTemporaryFileInDir(temp_dir_.path(), &image_path_)) { 26 if (!base::CreateTemporaryFileInDir(temp_dir_.path(), &image_path_)) {
34 Error(error::kTempFileError); 27 Error(error::kTempFileError);
35 return; 28 return;
36 } 29 }
37 30
38 scoped_ptr<char[]> buffer(new char[kPartitionTableSize]); 31 scoped_ptr<char[]> buffer(new char[kPartitionTableSize]);
39 memset(buffer.get(), 0, kPartitionTableSize); 32 memset(buffer.get(), 0, kPartitionTableSize);
40 33
41 if (file_util::WriteFile(image_path_, buffer.get(), kPartitionTableSize) != 34 if (file_util::WriteFile(image_path_, buffer.get(), kPartitionTableSize) !=
42 kPartitionTableSize) { 35 kPartitionTableSize) {
43 Error(error::kTempFileError); 36 Error(error::kTempFileError);
44 return; 37 return;
45 } 38 }
46 39
47 WriteStart(); 40 Write(base::Bind(&DestroyPartitionsOperation::Finish, this));
48 } 41 }
49 42
50 } // namespace image_writer 43 } // namespace image_writer
51 } // namespace extensions 44 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698