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
3 // found in the LICENSE file.
5 #include "base/files/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 #include "content/public/browser/browser_thread.h"
10 namespace extensions
{
11 namespace image_writer
{
13 // Number of bytes for the maximum partition table size. GUID partition tables
14 // reside in the second sector of the disk. Disks can have up to 4k sectors.
15 // See http://crbug.com/328246 for more information.
16 const int kPartitionTableSize
= 2 * 4096;
18 DestroyPartitionsOperation::DestroyPartitionsOperation(
19 base::WeakPtr
<OperationManager
> manager
,
20 const ExtensionId
& extension_id
,
21 const std::string
& storage_unit_id
)
22 : Operation(manager
, extension_id
, storage_unit_id
) {}
24 DestroyPartitionsOperation::~DestroyPartitionsOperation() {}
26 void DestroyPartitionsOperation::StartImpl() {
27 if (!base::CreateTemporaryFileInDir(temp_dir_
.path(), &image_path_
)) {
28 Error(error::kTempFileError
);
32 scoped_ptr
<char[]> buffer(new char[kPartitionTableSize
]);
33 memset(buffer
.get(), 0, kPartitionTableSize
);
35 if (base::WriteFile(image_path_
, buffer
.get(), kPartitionTableSize
) !=
36 kPartitionTableSize
) {
37 Error(error::kTempFileError
);
41 content::BrowserThread::PostTask(
42 content::BrowserThread::FILE,
44 base::Bind(&DestroyPartitionsOperation::Write
,
46 base::Bind(&DestroyPartitionsOperation::Finish
, this)));
49 } // namespace image_writer
50 } // namespace extensions