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

Side by Side Diff: chrome/browser/extensions/api/image_writer_private/operation_chromeos.cc

Issue 282853003: Unmounts volumes before writing to a drive. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adds compile guard to Chrome OS includes in test_utils.h Created 6 years, 7 months 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
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/api/image_writer_private/error_messages.h" 5 #include "chrome/browser/extensions/api/image_writer_private/error_messages.h"
6 #include "chrome/browser/extensions/api/image_writer_private/operation.h" 6 #include "chrome/browser/extensions/api/image_writer_private/operation.h"
7 #include "chromeos/dbus/dbus_thread_manager.h" 7 #include "chromeos/dbus/dbus_thread_manager.h"
8 #include "chromeos/dbus/image_burner_client.h" 8 #include "chromeos/dbus/image_burner_client.h"
9 #include "chromeos/disks/disk_mount_manager.h"
9 #include "content/public/browser/browser_thread.h" 10 #include "content/public/browser/browser_thread.h"
10 11
11 namespace extensions { 12 namespace extensions {
12 namespace image_writer { 13 namespace image_writer {
13 14
15 using chromeos::disks::DiskMountManager;
14 using chromeos::ImageBurnerClient; 16 using chromeos::ImageBurnerClient;
15 using content::BrowserThread; 17 using content::BrowserThread;
16 18
17 namespace { 19 namespace {
18 20
19 void ClearImageBurner() { 21 void ClearImageBurner() {
20 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { 22 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
21 BrowserThread::PostTask(BrowserThread::UI, 23 BrowserThread::PostTask(BrowserThread::UI,
22 FROM_HERE, 24 FROM_HERE,
23 base::Bind(&ClearImageBurner)); 25 base::Bind(&ClearImageBurner));
24 return; 26 return;
25 } 27 }
26 28
27 chromeos::DBusThreadManager::Get()-> 29 chromeos::DBusThreadManager::Get()->
28 GetImageBurnerClient()-> 30 GetImageBurnerClient()->
29 ResetEventHandlers(); 31 ResetEventHandlers();
30 } 32 }
31 33
32 } // namespace 34 } // namespace
33 35
34 void Operation::Write(const base::Closure& continuation) { 36 void Operation::Write(const base::Closure& continuation) {
35 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 37 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
36 SetStage(image_writer_api::STAGE_WRITE); 38 SetStage(image_writer_api::STAGE_WRITE);
37 39
40 // Note this has to be run on the FILE thread to avoid concurrent access.
41 AddCleanUpFunction(base::Bind(&ClearImageBurner));
42
38 BrowserThread::PostTask( 43 BrowserThread::PostTask(
39 BrowserThread::UI, 44 BrowserThread::UI,
40 FROM_HERE, 45 FROM_HERE,
41 base::Bind(&Operation::StartWriteOnUIThread, this, continuation)); 46 base::Bind(&Operation::UnmountVolumes, this, continuation));
42
43 AddCleanUpFunction(base::Bind(&ClearImageBurner));
44 } 47 }
45 48
46 void Operation::VerifyWrite(const base::Closure& continuation) { 49 void Operation::VerifyWrite(const base::Closure& continuation) {
47 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 50 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
48 51
49 // No verification is available in Chrome OS currently. 52 // No verification is available in Chrome OS currently.
50 continuation.Run(); 53 continuation.Run();
51 } 54 }
52 55
53 void Operation::StartWriteOnUIThread(const base::Closure& continuation) { 56 void Operation::UnmountVolumes(const base::Closure& continuation) {
57 DCHECK_CURRENTLY_ON(BrowserThread::UI);
58 DiskMountManager::GetInstance()->UnmountDeviceRecursively(
59 device_path_.value(),
60 base::Bind(&Operation::UnmountVolumesCallback, this, continuation));
61 }
62
63 void Operation::UnmountVolumesCallback(const base::Closure& continuation,
64 bool success) {
54 DCHECK_CURRENTLY_ON(BrowserThread::UI); 65 DCHECK_CURRENTLY_ON(BrowserThread::UI);
55 66
67 if (!success) {
68 LOG(ERROR) << "Volume unmounting failed.";
69 Error(error::kUnmountVolumesError);
70 return;
71 }
72
73 const DiskMountManager::DiskMap& disks =
74 DiskMountManager::GetInstance()->disks();
75 DiskMountManager::DiskMap::const_iterator iter =
76 disks.find(device_path_.value());
77
78 if (iter == disks.end()) {
79 LOG(ERROR) << "Disk not found in disk list after unmounting volumes.";
80 Error(error::kUnmountVolumesError);
81 return;
82 }
83
84 StartWriteOnUIThread(iter->second->file_path(), continuation);
85 }
86
87 void Operation::StartWriteOnUIThread(const std::string& target_path,
88 const base::Closure& continuation) {
89 DCHECK_CURRENTLY_ON(BrowserThread::UI);
90
91 // TODO(haven): Image Burner cannot handle multiple burns. crbug.com/373575
56 ImageBurnerClient* burner = 92 ImageBurnerClient* burner =
57 chromeos::DBusThreadManager::Get()->GetImageBurnerClient(); 93 chromeos::DBusThreadManager::Get()->GetImageBurnerClient();
58 94
59 burner->SetEventHandlers( 95 burner->SetEventHandlers(
60 base::Bind(&Operation::OnBurnFinished, this, continuation), 96 base::Bind(&Operation::OnBurnFinished, this, continuation),
61 base::Bind(&Operation::OnBurnProgress, this)); 97 base::Bind(&Operation::OnBurnProgress, this));
62 98
63 burner->BurnImage(image_path_.value(), 99 burner->BurnImage(image_path_.value(),
64 device_path_.value(), 100 target_path,
65 base::Bind(&Operation::OnBurnError, this)); 101 base::Bind(&Operation::OnBurnError, this));
66 } 102 }
67 103
68 void Operation::OnBurnFinished(const base::Closure& continuation, 104 void Operation::OnBurnFinished(const base::Closure& continuation,
69 const std::string& target_path, 105 const std::string& target_path,
70 bool success, 106 bool success,
71 const std::string& error) { 107 const std::string& error) {
72 if (success) { 108 if (success) {
73 SetProgress(kProgressComplete); 109 SetProgress(kProgressComplete);
74 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, continuation); 110 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, continuation);
75 } else { 111 } else {
76 DLOG(ERROR) << "Error encountered while burning: " << error; 112 DLOG(ERROR) << "Error encountered while burning: " << error;
77 Error(error::kChromeOSImageBurnerError); 113 Error(error::kChromeOSImageBurnerError);
78 } 114 }
79 } 115 }
80 116
81 void Operation::OnBurnProgress(const std::string& target_path, 117 void Operation::OnBurnProgress(const std::string& target_path,
82 int64 num_bytes_burnt, 118 int64 num_bytes_burnt,
83 int64 total_size) { 119 int64 total_size) {
84 int progress = kProgressComplete * num_bytes_burnt / total_size; 120 int progress = kProgressComplete * num_bytes_burnt / total_size;
85 SetProgress(progress); 121 SetProgress(progress);
86 } 122 }
87 123
88 void Operation::OnBurnError() { 124 void Operation::OnBurnError() {
89 Error(error::kChromeOSImageBurnerError); 125 Error(error::kChromeOSImageBurnerError);
90 } 126 }
91 127
92 } // namespace image_writer 128 } // namespace image_writer
93 } // namespace extensions 129 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698