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

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: Style fixes 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 kLibraryNotLoaded); 264 kLibraryNotLoaded);
266 return; 265 return;
267 } 266 }
268 RequestMountInfo(&MountLibraryImpl::RequestMountInfoCallback, 267 RequestMountInfo(&MountLibraryImpl::RequestMountInfoCallback,
269 this); 268 this);
270 } 269 }
271 270
272 const DiskMap& disks() const OVERRIDE { return disks_; } 271 const DiskMap& disks() const OVERRIDE { return disks_; }
273 const MountPointMap& mount_points() const OVERRIDE { return mount_points_; } 272 const MountPointMap& mount_points() const OVERRIDE { return mount_points_; }
274 273
275 private: 274 private:
tbarzic 2011/08/12 19:31:13 add comment // static.
sidor.dev 2011/08/12 20:27:09 no.
275 virtual std::string FilePathToDevicePath(std::string file_path) OVERRIDE {
276 for (MountLibrary::DiskMap::iterator it = disks_.begin();
277 it != disks_.end(); ++it) {
278 if (it->second->file_path().compare(file_path) == 0)
279 return it->second->device_path();
280 }
281 return NULL;
282 }
283
276 // Callback for MountComplete signal and MountSourcePath method. 284 // Callback for MountComplete signal and MountSourcePath method.
277 static void MountCompletedHandler(void* object, 285 static void MountCompletedHandler(void* object,
278 MountError error_code, 286 MountError error_code,
279 const char* source_path, 287 const char* source_path,
280 MountType type, 288 MountType type,
281 const char* mount_path) { 289 const char* mount_path) {
282 DCHECK(object); 290 DCHECK(object);
283 MountLibraryImpl* self = static_cast<MountLibraryImpl*>(object); 291 MountLibraryImpl* self = static_cast<MountLibraryImpl*>(object);
284 self->OnMountCompleted(static_cast<MountError>(error_code), 292 self->OnMountCompleted(static_cast<MountError>(error_code),
285 MountPointInfo(source_path, mount_path, type)); 293 MountPointInfo(source_path, mount_path, type));
286 } 294 }
287 295
288 // Callback for UnmountRemovableDevice method. 296 // Callback for UnmountRemovableDevice method.
289 static void UnmountMountPointCallback(void* object, 297 static void UnmountMountPointCallback(void* object,
290 const char* mount_path, 298 const char* mount_path,
291 MountMethodErrorType error, 299 MountMethodErrorType error,
292 const char* error_message) { 300 const char* error_message) {
293 DCHECK(object); 301 DCHECK(object);
294 MountLibraryImpl* self = static_cast<MountLibraryImpl*>(object); 302 MountLibraryImpl* self = static_cast<MountLibraryImpl*>(object);
295 self->OnUnmountPath(mount_path, error, error_message); 303 self->OnUnmountPath(mount_path, error, error_message);
296 } 304 }
297 305
298 // Callback for FormatRemovableDevice method. 306 // Callback for FormatRemovableDevice method.
299 static void FormatDeviceCallback(void* object, 307 static void FormatDeviceCallback(void* object,
300 const char* device_path, 308 const char* file_path,
301 bool success, 309 bool success,
302 MountMethodErrorType error, 310 MountMethodErrorType error,
303 const char* error_message) { 311 const char* error_message) {
304 DCHECK(object); 312 DCHECK(object);
305 MountLibraryImpl* self = static_cast<MountLibraryImpl*>(object); 313 MountLibraryImpl* self = static_cast<MountLibraryImpl*>(object);
314 const char* device_path = self->FilePathToDevicePath(file_path).c_str();
315 if (!device_path) {
316 LOG(ERROR) << "Error while handling disks metadata. Cannot find " <<
317 "device that is being formatted.";
318 return;
319 }
306 self->OnFormatDevice(device_path, success, error, error_message); 320 self->OnFormatDevice(device_path, success, error, error_message);
307 } 321 }
308 322
309 // Callback for UnmountDeviceRecursive. 323 // Callback for UnmountDeviceRecursive.
310 static void UnmountDeviceRecursiveCallback(void* object, 324 static void UnmountDeviceRecursiveCallback(void* object,
311 const char* mount_path, 325 const char* mount_path,
312 MountMethodErrorType error, 326 MountMethodErrorType error,
313 const char* error_message) { 327 const char* error_message) {
314 DCHECK(object); 328 DCHECK(object);
315 UnmountDeviceRecursiveCallbackData* cb_data = 329 UnmountDeviceRecursiveCallbackData* cb_data =
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 } 622 }
609 case DEVICE_REMOVED: { 623 case DEVICE_REMOVED: {
610 type = MOUNT_DEVICE_REMOVED; 624 type = MOUNT_DEVICE_REMOVED;
611 break; 625 break;
612 } 626 }
613 case DEVICE_SCANNED: { 627 case DEVICE_SCANNED: {
614 type = MOUNT_DEVICE_SCANNED; 628 type = MOUNT_DEVICE_SCANNED;
615 break; 629 break;
616 } 630 }
617 case FORMATTING_FINISHED: { 631 case FORMATTING_FINISHED: {
632 // FORMATTING_FINISHED actually returns file path instead of device
633 // path.
634 device_path = FilePathToDevicePath(device_path).c_str();
635 if (!device_path) {
636 LOG(ERROR) << "Error while handling disks metadata. Cannot find " <<
637 "device that is being formatted.";
638 return;
639 }
618 type = MOUNT_FORMATTING_FINISHED; 640 type = MOUNT_FORMATTING_FINISHED;
619 break; 641 break;
620 } 642 }
621 default: { 643 default: {
622 return; 644 return;
623 } 645 }
624 } 646 }
625 FireDeviceStatusUpdate(type, std::string(device_path)); 647 FireDeviceStatusUpdate(type, std::string(device_path));
626 } 648 }
627 649
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 virtual void MountPath(const char* source_path, MountType type, 715 virtual void MountPath(const char* source_path, MountType type,
694 const MountPathOptions& options) OVERRIDE {} 716 const MountPathOptions& options) OVERRIDE {}
695 virtual void UnmountPath(const char* mount_path) OVERRIDE {} 717 virtual void UnmountPath(const char* mount_path) OVERRIDE {}
696 virtual void FormatUnmountedDevice(const char* device_path) OVERRIDE {} 718 virtual void FormatUnmountedDevice(const char* device_path) OVERRIDE {}
697 virtual void FormatMountedDevice(const char* mount_path) OVERRIDE {} 719 virtual void FormatMountedDevice(const char* mount_path) OVERRIDE {}
698 virtual void UnmountDeviceRecursive(const char* device_path, 720 virtual void UnmountDeviceRecursive(const char* device_path,
699 UnmountDeviceRecursiveCallbackType callback, void* user_data) 721 UnmountDeviceRecursiveCallbackType callback, void* user_data)
700 OVERRIDE {} 722 OVERRIDE {}
701 723
702 private: 724 private:
725 virtual std::string FilePathToDevicePath(std::string file_path) OVERRIDE {
726 return "";
727 }
703 // The list of disks found. 728 // The list of disks found.
704 DiskMap disks_; 729 DiskMap disks_;
705 MountPointMap mount_points_; 730 MountPointMap mount_points_;
706 731
707 DISALLOW_COPY_AND_ASSIGN(MountLibraryStubImpl); 732 DISALLOW_COPY_AND_ASSIGN(MountLibraryStubImpl);
708 }; 733 };
709 734
710 // static 735 // static
711 MountLibrary* MountLibrary::GetImpl(bool stub) { 736 MountLibrary* MountLibrary::GetImpl(bool stub) {
712 if (stub) 737 if (stub)
713 return new MountLibraryStubImpl(); 738 return new MountLibraryStubImpl();
714 else 739 else
715 return new MountLibraryImpl(); 740 return new MountLibraryImpl();
716 } 741 }
717 742
718 } // namespace chromeos 743 } // namespace chromeos
719 744
720 // Allows InvokeLater without adding refcounting. This class is a Singleton and 745 // Allows InvokeLater without adding refcounting. This class is a Singleton and
721 // won't be deleted until it's last InvokeLater is run. 746 // won't be deleted until it's last InvokeLater is run.
722 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::MountLibraryImpl); 747 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::MountLibraryImpl);
723 748
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698