OLD | NEW |
| (Empty) |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "base/file_util.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" | |
8 | |
9 namespace extensions { | |
10 namespace image_writer { | |
11 | |
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 | |
14 // be wiped. See http://crbug.com/328246 for more information. | |
15 const int kPartitionTableSize = 1 * 1024; | |
16 | |
17 DestroyPartitionsOperation::DestroyPartitionsOperation( | |
18 base::WeakPtr<OperationManager> manager, | |
19 const ExtensionId& extension_id, | |
20 const std::string& storage_unit_id) | |
21 : Operation(manager, extension_id, storage_unit_id) { | |
22 verify_write_ = false; | |
23 } | |
24 | |
25 DestroyPartitionsOperation::~DestroyPartitionsOperation() {} | |
26 | |
27 void DestroyPartitionsOperation::Start() { | |
28 if (!temp_dir_.CreateUniqueTempDir()) { | |
29 Error(error::kTempDirError); | |
30 return; | |
31 } | |
32 | |
33 if (!base::CreateTemporaryFileInDir(temp_dir_.path(), &image_path_)) { | |
34 Error(error::kTempFileError); | |
35 return; | |
36 } | |
37 | |
38 scoped_ptr<char[]> buffer(new char[kPartitionTableSize]); | |
39 memset(buffer.get(), 0, kPartitionTableSize); | |
40 | |
41 if (file_util::WriteFile(image_path_, buffer.get(), kPartitionTableSize) != | |
42 kPartitionTableSize) { | |
43 Error(error::kTempFileError); | |
44 return; | |
45 } | |
46 | |
47 WriteStart(); | |
48 } | |
49 | |
50 } // namespace image_writer | |
51 } // namespace extensions | |
OLD | NEW |