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

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: fix 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 = self->FilePathToDevicePath(file_path);
306 if (!device_path) {
307 LOG(ERROR) << "Error while handling disks metadata. Cannot find "
308 << "device that is being formatted.";
309 return;
310 }
306 self->OnFormatDevice(device_path, success, error, error_message); 311 self->OnFormatDevice(device_path, success, error, error_message);
307 } 312 }
308 313
309 // Callback for UnmountDeviceRecursive. 314 // Callback for UnmountDeviceRecursive.
310 static void UnmountDeviceRecursiveCallback(void* object, 315 static void UnmountDeviceRecursiveCallback(void* object,
311 const char* mount_path, 316 const char* mount_path,
312 MountMethodErrorType error, 317 MountMethodErrorType error,
313 const char* error_message) { 318 const char* error_message) {
314 DCHECK(object); 319 DCHECK(object);
315 UnmountDeviceRecursiveCallbackData* cb_data = 320 UnmountDeviceRecursiveCallbackData* cb_data =
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 } 613 }
609 case DEVICE_REMOVED: { 614 case DEVICE_REMOVED: {
610 type = MOUNT_DEVICE_REMOVED; 615 type = MOUNT_DEVICE_REMOVED;
611 break; 616 break;
612 } 617 }
613 case DEVICE_SCANNED: { 618 case DEVICE_SCANNED: {
614 type = MOUNT_DEVICE_SCANNED; 619 type = MOUNT_DEVICE_SCANNED;
615 break; 620 break;
616 } 621 }
617 case FORMATTING_FINISHED: { 622 case FORMATTING_FINISHED: {
623 // FORMATTING_FINISHED actually returns file path instead of device
624 // path.
625 device_path = FilePathToDevicePath(device_path);
626 if (!device_path) {
627 LOG(ERROR) << "Error while handling disks metadata. Cannot find "
628 << "device that is being formatted.";
629 return;
630 }
618 type = MOUNT_FORMATTING_FINISHED; 631 type = MOUNT_FORMATTING_FINISHED;
619 break; 632 break;
620 } 633 }
621 default: { 634 default: {
622 return; 635 return;
623 } 636 }
624 } 637 }
625 FireDeviceStatusUpdate(type, std::string(device_path)); 638 FireDeviceStatusUpdate(type, std::string(device_path));
626 } 639 }
627 640
(...skipping 23 matching lines...) Expand all
651 MountError error_code, 664 MountError error_code,
652 const MountPointInfo& mount_info) { 665 const MountPointInfo& mount_info) {
653 // Make sure we run on UI thread. 666 // Make sure we run on UI thread.
654 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 667 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
655 FOR_EACH_OBSERVER( 668 FOR_EACH_OBSERVER(
656 Observer, observers_, MountCompleted(event_type, 669 Observer, observers_, MountCompleted(event_type,
657 error_code, 670 error_code,
658 mount_info)); 671 mount_info));
659 } 672 }
660 673
674 const char* FilePathToDevicePath(const char* file_path) {
675 for (MountLibrary::DiskMap::iterator it = disks_.begin();
676 it != disks_.end(); ++it) {
677 if (it->second->file_path().compare(file_path) == 0)
678 return it->second->device_path().c_str();
679 }
680 return NULL;
681 }
682
661 // Mount event change observers. 683 // Mount event change observers.
662 ObserverList<Observer> observers_; 684 ObserverList<Observer> observers_;
663 685
664 // A reference to the mount api, to allow callbacks when the mount 686 // A reference to the mount api, to allow callbacks when the mount
665 // status changes. 687 // status changes.
666 MountEventConnection mount_status_connection_; 688 MountEventConnection mount_status_connection_;
667 689
668 // The list of disks found. 690 // The list of disks found.
669 MountLibrary::DiskMap disks_; 691 MountLibrary::DiskMap disks_;
670 692
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
714 else 736 else
715 return new MountLibraryImpl(); 737 return new MountLibraryImpl();
716 } 738 }
717 739
718 } // namespace chromeos 740 } // namespace chromeos
719 741
720 // Allows InvokeLater without adding refcounting. This class is a Singleton and 742 // Allows InvokeLater without adding refcounting. This class is a Singleton and
721 // won't be deleted until it's last InvokeLater is run. 743 // won't be deleted until it's last InvokeLater is run.
722 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::MountLibraryImpl); 744 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::MountLibraryImpl);
723 745
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