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

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: Moves unmounting to the UI thread. 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
38 BrowserThread::PostTask( 40 BrowserThread::PostTask(
39 BrowserThread::UI, 41 BrowserThread::UI,
40 FROM_HERE, 42 FROM_HERE,
41 base::Bind(&Operation::StartWriteOnUIThread, this, continuation)); 43 base::Bind(&Operation::UnmountVolumes, this, continuation));
42
43 AddCleanUpFunction(base::Bind(&ClearImageBurner));
44 } 44 }
45 45
46 void Operation::VerifyWrite(const base::Closure& continuation) { 46 void Operation::VerifyWrite(const base::Closure& continuation) {
47 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 47 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
48 48
49 // No verification is available in Chrome OS currently. 49 // No verification is available in Chrome OS currently.
50 continuation.Run(); 50 continuation.Run();
51 } 51 }
52 52
53 void Operation::StartWriteOnUIThread(const base::Closure& continuation) { 53 void Operation::UnmountVolumes(const base::Closure& continuation) {
54 DCHECK_CURRENTLY_ON(BrowserThread::UI);
55 DiskMountManager::GetInstance()->UnmountDeviceRecursively(
56 device_path_.value(),
57 base::Bind(&Operation::UnmountVolumesCallback, this, continuation));
58 }
59
60 void Operation::UnmountVolumesCallback(const base::Closure& continuation,
61 bool success) {
62 DCHECK_CURRENTLY_ON(BrowserThread::UI);
63
64 if (!success) {
65 LOG(ERROR) << "Volume unmounting failed.";
66 Error(error::kUnmountVolumesError);
67 return;
68 }
69
70 const DiskMountManager::DiskMap& disks =
71 DiskMountManager::GetInstance()->disks();
72 DiskMountManager::DiskMap::const_iterator iter =
73 disks.find(device_path_.value());
74
75 if (iter == disks.end()) {
76 LOG(ERROR) << "Disk not found in disk list after unmounting volumes.";
77 Error(error::kUnmountVolumesError);
78 return;
79 }
80
81 StartWriteOnUIThread(iter->second->file_path(), continuation);
82 }
83
84 void Operation::StartWriteOnUIThread(const std::string& target_path,
85 const base::Closure& continuation) {
54 DCHECK_CURRENTLY_ON(BrowserThread::UI); 86 DCHECK_CURRENTLY_ON(BrowserThread::UI);
55 87
56 ImageBurnerClient* burner = 88 ImageBurnerClient* burner =
57 chromeos::DBusThreadManager::Get()->GetImageBurnerClient(); 89 chromeos::DBusThreadManager::Get()->GetImageBurnerClient();
58 90
91 AddCleanUpFunction(base::Bind(&ClearImageBurner));
tbarzic 2014/05/15 00:58:58 AddCleanupFunction has DCHECK that it's on file th
Drew Haven 2014/05/15 02:00:28 Oh, I built release mode when I tested, so I didn'
59 burner->SetEventHandlers( 92 burner->SetEventHandlers(
60 base::Bind(&Operation::OnBurnFinished, this, continuation), 93 base::Bind(&Operation::OnBurnFinished, this, continuation),
61 base::Bind(&Operation::OnBurnProgress, this)); 94 base::Bind(&Operation::OnBurnProgress, this));
62 95
63 burner->BurnImage(image_path_.value(), 96 burner->BurnImage(image_path_.value(),
64 device_path_.value(), 97 target_path,
65 base::Bind(&Operation::OnBurnError, this)); 98 base::Bind(&Operation::OnBurnError, this));
66 } 99 }
67 100
68 void Operation::OnBurnFinished(const base::Closure& continuation, 101 void Operation::OnBurnFinished(const base::Closure& continuation,
69 const std::string& target_path, 102 const std::string& target_path,
70 bool success, 103 bool success,
71 const std::string& error) { 104 const std::string& error) {
72 if (success) { 105 if (success) {
73 SetProgress(kProgressComplete); 106 SetProgress(kProgressComplete);
74 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, continuation); 107 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, continuation);
75 } else { 108 } else {
76 DLOG(ERROR) << "Error encountered while burning: " << error; 109 DLOG(ERROR) << "Error encountered while burning: " << error;
77 Error(error::kChromeOSImageBurnerError); 110 Error(error::kChromeOSImageBurnerError);
78 } 111 }
79 } 112 }
80 113
81 void Operation::OnBurnProgress(const std::string& target_path, 114 void Operation::OnBurnProgress(const std::string& target_path,
82 int64 num_bytes_burnt, 115 int64 num_bytes_burnt,
83 int64 total_size) { 116 int64 total_size) {
84 int progress = kProgressComplete * num_bytes_burnt / total_size; 117 int progress = kProgressComplete * num_bytes_burnt / total_size;
85 SetProgress(progress); 118 SetProgress(progress);
86 } 119 }
87 120
88 void Operation::OnBurnError() { 121 void Operation::OnBurnError() {
89 Error(error::kChromeOSImageBurnerError); 122 Error(error::kChromeOSImageBurnerError);
90 } 123 }
91 124
92 } // namespace image_writer 125 } // namespace image_writer
93 } // namespace extensions 126 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698