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

Side by Side 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 unified diff | Download patch
OLDNEW
(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 = 32 * 1024;
16
17 namespace {
18
19 // 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
20 void RemoveTempFile(const base::FilePath& path) {
21 if (!DeleteFile(path, false))
22 DLOG(ERROR) << "Unable to delete temporary file: " << path.value();
23 }
24
25 }
tbarzic 2013/12/14 01:01:04 // namespace
Drew Haven 2013/12/16 20:15:33 Done.
26
27 DestroyPartitionsOperation::DestroyPartitionsOperation(
28 base::WeakPtr<OperationManager> manager,
29 const ExtensionId& extension_id,
30 const std::string& storage_unit_id)
31 : 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.
32 // Turn off the verification step.
33 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.
34 }
35
36 DestroyPartitionsOperation::~DestroyPartitionsOperation() {
37 }
tbarzic 2013/12/14 01:01:04 no need for a nl here
Drew Haven 2013/12/16 20:15:33 Done.
38
39 void DestroyPartitionsOperation::Start() {
40 if (!base::CreateTemporaryFile(&image_path_)) {
41 Error(error::kTempFile);
42 return;
43 }
44
45 AddCleanUpFunction(base::Bind(&RemoveTempFile, image_path_));
46
47 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
48 memset(buffer, 0, kPartitionTableSize);
49
50 if (file_util::WriteFile(image_path_, buffer, kPartitionTableSize) !=
51 kPartitionTableSize) {
52 Error(error::kTempFile);
53 return;
54 }
55
56 WriteStart();
57 }
58
59 } // namespace image_writer
60 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698