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

Unified Diff: chrome/browser/extensions/api/image_writer_private/destroy_partitions_operation.cc

Issue 109793006: Adds ImageWriterPrivate.destroyPartitions operation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixes up DBusThreadManager initialization. Created 7 years 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/image_writer_private/destroy_partitions_operation.cc
diff --git a/chrome/browser/extensions/api/image_writer_private/destroy_partitions_operation.cc b/chrome/browser/extensions/api/image_writer_private/destroy_partitions_operation.cc
new file mode 100644
index 0000000000000000000000000000000000000000..127b3b0871af6bc4888b0c4db925b447a860d616
--- /dev/null
+++ b/chrome/browser/extensions/api/image_writer_private/destroy_partitions_operation.cc
@@ -0,0 +1,51 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/file_util.h"
+#include "chrome/browser/extensions/api/image_writer_private/destroy_partitions_operation.h"
+#include "chrome/browser/extensions/api/image_writer_private/error_messages.h"
+
+namespace extensions {
+namespace image_writer {
+
+// Number of bytes for the maximum partition table size. By wiping this many
+// bytes we can essentially guarantee the header and associated information will
+// be wiped. See http://crbug.com/328246 for more information.
+const int kPartitionTableSize = 1 * 1024;
+
+DestroyPartitionsOperation::DestroyPartitionsOperation(
+ base::WeakPtr<OperationManager> manager,
+ const ExtensionId& extension_id,
+ const std::string& storage_unit_id)
+ : Operation(manager, extension_id, storage_unit_id) {
+ verify_write_ = false;
+}
+
+DestroyPartitionsOperation::~DestroyPartitionsOperation() {}
+
+void DestroyPartitionsOperation::Start() {
+ if (!temp_dir_.CreateUniqueTempDir()) {
+ Error(error::kTempDirError);
+ return;
+ }
+
+ if (!base::CreateTemporaryFileInDir(temp_dir_.path(), &image_path_)) {
+ Error(error::kTempFileError);
+ return;
+ }
+
+ scoped_ptr<char[]> buffer(new char[kPartitionTableSize]);
+ memset(buffer.get(), 0, kPartitionTableSize);
+
+ if (file_util::WriteFile(image_path_, buffer.get(), kPartitionTableSize) !=
+ kPartitionTableSize) {
+ Error(error::kTempFileError);
+ return;
+ }
+
+ WriteStart();
+}
+
+} // namespace image_writer
+} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698