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

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: Cleanup 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..a5f1b0fe7144a9af68e8a41d49495cad574eec98
--- /dev/null
+++ b/chrome/browser/extensions/api/image_writer_private/destroy_partitions_operation.cc
@@ -0,0 +1,60 @@
+// 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 = 32 * 1024;
+
+namespace {
+
+// Small wrapper to remove the temporary file and display an error if it fails.
tbarzic 2013/12/14 01:01:04 display error where? If you meant DLOG part, I don
Drew Haven 2013/12/16 20:15:33 Good point. It's such a trivial function, but I f
+void RemoveTempFile(const base::FilePath& path) {
+ if (!DeleteFile(path, false))
+ DLOG(ERROR) << "Unable to delete temporary file: " << path.value();
+}
+
+}
tbarzic 2013/12/14 01:01:04 // namespace
Drew Haven 2013/12/16 20:15:33 Done.
+
+DestroyPartitionsOperation::DestroyPartitionsOperation(
+ base::WeakPtr<OperationManager> manager,
+ const ExtensionId& extension_id,
+ const std::string& storage_unit_id)
+ : Operation(manager, extension_id, storage_unit_id) {
tbarzic 2013/12/14 01:01:04 indent+=2
Drew Haven 2013/12/16 20:15:33 Done.
+ // Turn off the verification step.
+ verify_write_ = false;
tbarzic 2013/12/14 01:01:04 I'd add this to initializer list
Drew Haven 2013/12/16 20:15:33 It's a protected variable of the superclass, so I
tbarzic 2013/12/16 20:33:45 ok. Though, it may make sense to pass verify_write
Drew Haven 2013/12/16 22:05:25 I think we'll set that up when/if we need it.
+}
+
+DestroyPartitionsOperation::~DestroyPartitionsOperation() {
+}
tbarzic 2013/12/14 01:01:04 no need for a nl here
Drew Haven 2013/12/16 20:15:33 Done.
+
+void DestroyPartitionsOperation::Start() {
+ if (!base::CreateTemporaryFile(&image_path_)) {
+ Error(error::kTempFile);
+ return;
+ }
+
+ AddCleanUpFunction(base::Bind(&RemoveTempFile, image_path_));
+
+ char buffer[kPartitionTableSize];
tbarzic 2013/12/14 01:01:04 I'd use scoped_array<char> here (32kB is not that
Drew Haven 2013/12/16 20:15:33 I'm not finding scoped_arrays in base. Though the
+ memset(buffer, 0, kPartitionTableSize);
+
+ if (file_util::WriteFile(image_path_, buffer, kPartitionTableSize) !=
+ kPartitionTableSize) {
+ Error(error::kTempFile);
+ return;
+ }
+
+ WriteStart();
+}
+
+} // namespace image_writer
+} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698