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

Side by Side Diff: chrome/browser/chromeos/cros/mount_library.cc

Issue 7583041: Adding a format device button to UI. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Fixed UI refresing. Created 9 years, 4 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/chromeos/cros/mount_library.h" 5 #include "chrome/browser/chromeos/cros/mount_library.h"
6 6
7 #include <set> 7 #include <set>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 virtual void FormatMountedDevice(const char* mount_path) OVERRIDE { 173 virtual void FormatMountedDevice(const char* mount_path) OVERRIDE {
174 DCHECK(mount_path); 174 DCHECK(mount_path);
175 Disk* disk = NULL; 175 Disk* disk = NULL;
176 for (MountLibrary::DiskMap::iterator it = disks_.begin(); 176 for (MountLibrary::DiskMap::iterator it = disks_.begin();
177 it != disks_.end(); ++it) { 177 it != disks_.end(); ++it) {
178 if (it->second->mount_path().compare(mount_path) == 0) { 178 if (it->second->mount_path().compare(mount_path) == 0) {
179 disk = it->second; 179 disk = it->second;
180 break; 180 break;
181 } 181 }
182 } 182 }
183
184 if (!disk) { 183 if (!disk) {
185 OnFormatDevice(disk->device_path().c_str(), 184 OnFormatDevice(mount_path,
186 false, 185 false,
187 MOUNT_METHOD_ERROR_LOCAL, 186 MOUNT_METHOD_ERROR_LOCAL,
188 "Device with this mount path not found."); 187 "Device with this mount path not found.");
189 return; 188 return;
190 } 189 }
191 if (formatting_pending_.find(disk->device_path()) != 190 if (formatting_pending_.find(disk->device_path()) !=
192 formatting_pending_.end()) { 191 formatting_pending_.end()) {
193 OnFormatDevice(disk->device_path().c_str(), 192 OnFormatDevice(mount_path,
194 false, 193 false,
195 MOUNT_METHOD_ERROR_LOCAL, 194 MOUNT_METHOD_ERROR_LOCAL,
196 "Formatting is already pending."); 195 "Formatting is already pending.");
197 return; 196 return;
198 } 197 }
199 // Formatting process continues, after unmounting. 198 // Formatting process continues, after unmounting.
200 formatting_pending_[disk->device_path()] = disk->file_path(); 199 formatting_pending_[disk->device_path()] = disk->file_path();
201 UnmountPath(disk->mount_path().c_str()); 200 UnmountPath(disk->mount_path().c_str());
202 } 201 }
203 202
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 const char* mount_path, 289 const char* mount_path,
291 MountMethodErrorType error, 290 MountMethodErrorType error,
292 const char* error_message) { 291 const char* error_message) {
293 DCHECK(object); 292 DCHECK(object);
294 MountLibraryImpl* self = static_cast<MountLibraryImpl*>(object); 293 MountLibraryImpl* self = static_cast<MountLibraryImpl*>(object);
295 self->OnUnmountPath(mount_path, error, error_message); 294 self->OnUnmountPath(mount_path, error, error_message);
296 } 295 }
297 296
298 // Callback for FormatRemovableDevice method. 297 // Callback for FormatRemovableDevice method.
299 static void FormatDeviceCallback(void* object, 298 static void FormatDeviceCallback(void* object,
300 const char* device_path, 299 const char* file_path,
301 bool success, 300 bool success,
302 MountMethodErrorType error, 301 MountMethodErrorType error,
303 const char* error_message) { 302 const char* error_message) {
304 DCHECK(object); 303 DCHECK(object);
305 MountLibraryImpl* self = static_cast<MountLibraryImpl*>(object); 304 MountLibraryImpl* self = static_cast<MountLibraryImpl*>(object);
305 const char* device_path = NULL;
306 for (MountLibrary::DiskMap::iterator it = self->disks_.begin();
307 it != self->disks_.end(); ++it) {
tbarzic 2011/08/12 18:29:35 You should encapsulate path conversion into separa
sidor.dev 2011/08/12 19:14:20 Done.
308 if (it->second->file_path().compare(file_path) == 0) {
309 device_path = it->second->device_path().c_str();
310 break;
311 }
312 }
313 if (!device_path) {
314 LOG(ERROR) << "Error while handling disks metadata. Cannot find "
315 << "device that is being formatted.";
316 return;
317 }
306 self->OnFormatDevice(device_path, success, error, error_message); 318 self->OnFormatDevice(device_path, success, error, error_message);
307 } 319 }
308 320
309 // Callback for UnmountDeviceRecursive. 321 // Callback for UnmountDeviceRecursive.
310 static void UnmountDeviceRecursiveCallback(void* object, 322 static void UnmountDeviceRecursiveCallback(void* object,
311 const char* mount_path, 323 const char* mount_path,
312 MountMethodErrorType error, 324 MountMethodErrorType error,
313 const char* error_message) { 325 const char* error_message) {
314 DCHECK(object); 326 DCHECK(object);
315 UnmountDeviceRecursiveCallbackData* cb_data = 327 UnmountDeviceRecursiveCallbackData* cb_data =
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 << mount_path << ", with error: " 452 << mount_path << ", with error: "
441 << (error_message ? error_message : "Unknown"); 453 << (error_message ? error_message : "Unknown");
442 } 454 }
443 } 455 }
444 456
445 void OnFormatDevice(const char* device_path, 457 void OnFormatDevice(const char* device_path,
446 bool success, 458 bool success,
447 MountMethodErrorType error, 459 MountMethodErrorType error,
448 const char* error_message) { 460 const char* error_message) {
449 DCHECK(device_path); 461 DCHECK(device_path);
462 // In mount library we use device path to identify device.
tbarzic 2011/08/12 18:29:35 I don't think this comment is needed
sidor.dev 2011/08/12 19:14:20 Sorry, forgot to delete it.
450 if (error == MOUNT_METHOD_ERROR_NONE && device_path && success) { 463 if (error == MOUNT_METHOD_ERROR_NONE && device_path && success) {
451 FireDeviceStatusUpdate(MOUNT_FORMATTING_STARTED, device_path); 464 FireDeviceStatusUpdate(MOUNT_FORMATTING_STARTED, device_path);
452 } else { 465 } else {
453 FireDeviceStatusUpdate(MOUNT_FORMATTING_STARTED, 466 FireDeviceStatusUpdate(MOUNT_FORMATTING_STARTED,
454 std::string("!") + device_path); 467 std::string("!") + device_path);
455 LOG(WARNING) << "Format request failed for device " 468 LOG(WARNING) << "Format request failed for device "
456 << device_path << ", with error: " 469 << device_path << ", with error: "
457 << (error_message ? error_message : "Unknown"); 470 << (error_message ? error_message : "Unknown");
458 } 471 }
459 } 472 }
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 } 621 }
609 case DEVICE_REMOVED: { 622 case DEVICE_REMOVED: {
610 type = MOUNT_DEVICE_REMOVED; 623 type = MOUNT_DEVICE_REMOVED;
611 break; 624 break;
612 } 625 }
613 case DEVICE_SCANNED: { 626 case DEVICE_SCANNED: {
614 type = MOUNT_DEVICE_SCANNED; 627 type = MOUNT_DEVICE_SCANNED;
615 break; 628 break;
616 } 629 }
617 case FORMATTING_FINISHED: { 630 case FORMATTING_FINISHED: {
631 // FORMATTING_FINISHED actually returns file path instead of device
632 // path.
633 const char* path = NULL;
634 for (MountLibrary::DiskMap::iterator it = disks_.begin();
635 it != disks_.end(); ++it) {
tbarzic 2011/08/12 18:29:35 use 5 space indent here
sidor.dev 2011/08/12 19:14:20 Done.
636 if (it->second->file_path().compare(device_path) == 0) {
637 path = it->second->device_path().c_str();
tbarzic 2011/08/12 18:29:35 Why don't you loose path and use device_path direc
sidor.dev 2011/08/12 19:14:20 Done.
638 break;
639 }
640 }
641 if (!path) {
642 LOG(ERROR) << "Error while handling disks metadata. Cannot find "
643 << "device that is being formatted.";
tbarzic 2011/08/12 18:29:35 align << with << in the previous row.
sidor.dev 2011/08/12 19:14:20 Done.
644 return;
645 }
646 device_path = path;
618 type = MOUNT_FORMATTING_FINISHED; 647 type = MOUNT_FORMATTING_FINISHED;
619 break; 648 break;
620 } 649 }
621 default: { 650 default: {
622 return; 651 return;
623 } 652 }
624 } 653 }
625 FireDeviceStatusUpdate(type, std::string(device_path)); 654 FireDeviceStatusUpdate(type, std::string(device_path));
626 } 655 }
627 656
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
714 else 743 else
715 return new MountLibraryImpl(); 744 return new MountLibraryImpl();
716 } 745 }
717 746
718 } // namespace chromeos 747 } // namespace chromeos
719 748
720 // Allows InvokeLater without adding refcounting. This class is a Singleton and 749 // Allows InvokeLater without adding refcounting. This class is a Singleton and
721 // won't be deleted until it's last InvokeLater is run. 750 // won't be deleted until it's last InvokeLater is run.
722 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::MountLibraryImpl); 751 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::MountLibraryImpl);
723 752
OLDNEW
« no previous file with comments | « chrome/app/generated_resources.grd ('k') | chrome/browser/extensions/extension_file_browser_private_api.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698