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

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

Issue 7457001: Adding support for mount point different from removable devices to MountLibrary (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 5 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 8
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 83
84 // MountLibrary overrides. 84 // MountLibrary overrides.
85 virtual void AddObserver(Observer* observer) OVERRIDE { 85 virtual void AddObserver(Observer* observer) OVERRIDE {
86 observers_.AddObserver(observer); 86 observers_.AddObserver(observer);
87 } 87 }
88 88
89 virtual void RemoveObserver(Observer* observer) OVERRIDE { 89 virtual void RemoveObserver(Observer* observer) OVERRIDE {
90 observers_.RemoveObserver(observer); 90 observers_.RemoveObserver(observer);
91 } 91 }
92 92
93 virtual void MountPath(const char* device_path) OVERRIDE { 93 virtual void MountPath(const char* source_path,
94 MountType type,
95 const MountPathOptions& options) OVERRIDE {
94 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 96 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
95 if (!CrosLibrary::Get()->EnsureLoaded()) { 97 if (!CrosLibrary::Get()->EnsureLoaded()) {
96 OnMountRemovableDevice(device_path, 98 OnMountCompleted(MOUNT_ERROR_LIBRARY_NOT_LOADED,
97 NULL, 99 source_path,
98 MOUNT_METHOD_ERROR_LOCAL, 100 type,
99 kLibraryNotLoaded); 101 NULL);
100 return; 102 return;
101 } 103 }
102 MountRemovableDevice(device_path, 104 MountSourcePath(source_path, type, options, &MountCompletedHandler, this);
103 &MountLibraryImpl::MountRemovableDeviceCallback,
104 this);
105 } 105 }
106 106
107 virtual void UnmountPath(const char* device_path) OVERRIDE { 107 virtual void UnmountPath(const char* path) OVERRIDE {
108 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 108 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
109 if (!CrosLibrary::Get()->EnsureLoaded()) { 109 if (!CrosLibrary::Get()->EnsureLoaded()) {
110 OnUnmountRemovableDevice(device_path, 110 OnUnmountRemovableDevice(path,
111 MOUNT_METHOD_ERROR_LOCAL, 111 MOUNT_METHOD_ERROR_LOCAL,
112 kLibraryNotLoaded); 112 kLibraryNotLoaded);
113 return; 113 return;
114 } 114 }
115 UnmountRemovableDevice(device_path, 115 UnmountMountPoint(path, &MountLibraryImpl::UnmountMountPointCallback, this);
116 &MountLibraryImpl::UnmountRemovableDeviceCallback,
117 this);
118 } 116 }
119 117
120 virtual void UnmountDeviceRecursive(const char* device_path, 118 virtual void UnmountDeviceRecursive(const char* device_path,
121 UnmountDeviceRecursiveCallbackType callback, void* user_data) 119 UnmountDeviceRecursiveCallbackType callback, void* user_data)
122 OVERRIDE { 120 OVERRIDE {
123 bool success = true; 121 bool success = true;
124 const char* error_message = NULL; 122 const char* error_message = NULL;
125 std::vector<const char*> devices_to_unmount; 123 std::vector<const char*> devices_to_unmount;
126 124
127 if (!CrosLibrary::Get()->EnsureLoaded()) { 125 if (!CrosLibrary::Get()->EnsureLoaded()) {
(...skipping 16 matching lines...) Expand all
144 } 142 }
145 } 143 }
146 144
147 if (success) { 145 if (success) {
148 // We will send the same callback data object to all Unmount calls and use 146 // We will send the same callback data object to all Unmount calls and use
149 // it to syncronize callbacks. 147 // it to syncronize callbacks.
150 UnmountDeviceRecursiveCallbackData* 148 UnmountDeviceRecursiveCallbackData*
151 cb_data = new UnmountDeviceRecursiveCallbackData(this, user_data, 149 cb_data = new UnmountDeviceRecursiveCallbackData(this, user_data,
152 callback, devices_to_unmount.size()); 150 callback, devices_to_unmount.size());
153 for (std::vector<const char*>::iterator it = devices_to_unmount.begin(); 151 for (std::vector<const char*>::iterator it = devices_to_unmount.begin();
154 it != devices_to_unmount.end(); 152 it != devices_to_unmount.end();
155 ++it) { 153 ++it) {
156 UnmountRemovableDevice(*it, 154 UnmountRemovableDevice(
155 *it,
157 &MountLibraryImpl::UnmountDeviceRecursiveCallback, 156 &MountLibraryImpl::UnmountDeviceRecursiveCallback,
158 cb_data); 157 cb_data);
159 } 158 }
160 } else { 159 } else {
161 LOG(WARNING) << "Unmount recursive request failed for device " 160 LOG(WARNING) << "Unmount recursive request failed for device "
162 << device_path << ", with error: " << error_message; 161 << device_path << ", with error: " << error_message;
163 callback(user_data, false); 162 callback(user_data, false);
164 } 163 }
165 } 164 }
166 165
167 virtual void RequestMountInfoRefresh() OVERRIDE { 166 virtual void RequestMountInfoRefresh() OVERRIDE {
168 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 167 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
169 if (!CrosLibrary::Get()->EnsureLoaded()) { 168 if (!CrosLibrary::Get()->EnsureLoaded()) {
170 OnRequestMountInfo(NULL, 169 OnRequestMountInfo(NULL,
171 0, 170 0,
172 MOUNT_METHOD_ERROR_LOCAL, 171 MOUNT_METHOD_ERROR_LOCAL,
173 kLibraryNotLoaded); 172 kLibraryNotLoaded);
174 return; 173 return;
175 } 174 }
176 RequestMountInfo(&MountLibraryImpl::RequestMountInfoCallback, 175 RequestMountInfo(&MountLibraryImpl::RequestMountInfoCallback,
177 this); 176 this);
178 } 177 }
179 178
180 const DiskMap& disks() const OVERRIDE { return disks_; } 179 const DiskMap& disks() const OVERRIDE { return disks_; }
180 const MountPointSet& mount_points() const OVERRIDE { return mount_points_; }
181 181
182 private: 182 private:
183 // Callback for MountRemovableDevice method. 183 // Callback for MountComplete signal and MountSourcePath method.
184 static void MountRemovableDeviceCallback(void* object, 184 static void MountCompletedHandler(void* object,
185 const char* device_path, 185 MountError error_code,
186 const char* mount_path, 186 const char* source_path,
187 MountMethodErrorType error, 187 MountType type,
188 const char* error_message) { 188 const char* mount_path) {
189 LOG(WARNING) <<"MountCompleted" <<error_code<<source_path<<mount_path;
tbarzic 2011/07/22 03:13:24 to be removed before landing
189 DCHECK(object); 190 DCHECK(object);
190 MountLibraryImpl* self = static_cast<MountLibraryImpl*>(object); 191 MountLibraryImpl* self = static_cast<MountLibraryImpl*>(object);
191 self->OnMountRemovableDevice(device_path, 192 self->OnMountCompleted(static_cast<MountError>(error_code),
192 mount_path, 193 source_path,
193 error, 194 static_cast<MountType>(type),
194 error_message); 195 mount_path);
195 } 196 }
196 197
197 // Callback for UnmountRemovableDevice method. 198 // Callback for UnmountRemovableDevice method.
198 static void UnmountRemovableDeviceCallback(void* object, 199 static void UnmountMountPointCallback(void* object,
199 const char* device_path, 200 const char* device_path,
200 const char* mount_path, 201 MountMethodErrorType error,
201 MountMethodErrorType error, 202 const char* error_message) {
202 const char* error_message) {
203 DCHECK(object); 203 DCHECK(object);
204 MountLibraryImpl* self = static_cast<MountLibraryImpl*>(object); 204 MountLibraryImpl* self = static_cast<MountLibraryImpl*>(object);
205 self->OnUnmountRemovableDevice(device_path, 205 self->OnUnmountRemovableDevice(device_path,
206 error, 206 error,
207 error_message); 207 error_message);
208 } 208 }
209 209
210 // Callback for UnmountDeviceRecursive. 210 // Callback for UnmountDeviceRecursive.
211 static void UnmountDeviceRecursiveCallback(void* object, 211 static void UnmountDeviceRecursiveCallback(void* object,
212 const char* device_path, 212 const char* device_path,
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 // This method will receive events that are caused by drive status changes. 268 // This method will receive events that are caused by drive status changes.
269 static void MonitorMountEventsHandler(void* object, 269 static void MonitorMountEventsHandler(void* object,
270 MountEventType evt, 270 MountEventType evt,
271 const char* device_path) { 271 const char* device_path) {
272 DCHECK(object); 272 DCHECK(object);
273 MountLibraryImpl* self = static_cast<MountLibraryImpl*>(object); 273 MountLibraryImpl* self = static_cast<MountLibraryImpl*>(object);
274 self->OnMountEvent(evt, device_path); 274 self->OnMountEvent(evt, device_path);
275 } 275 }
276 276
277 277
278 void OnMountRemovableDevice(const char* device_path, 278 void OnMountCompleted(MountError error_code,
279 const char* mount_path, 279 const char* source_path,
280 MountMethodErrorType error, 280 MountType type,
281 const char* error_message) { 281 const char* mount_path) {
282 DCHECK(device_path); 282 DCHECK(source_path);
283 283
284 if (error == MOUNT_METHOD_ERROR_NONE && device_path && mount_path) { 284 LOG(WARNING) <<"MountCompleted fired" <<error_code<<source_path<<mount_path;
tbarzic 2011/07/22 03:13:24 to be removed before landing
285 std::string path(device_path); 285 FireMountCompleted(error_code, source_path, type, mount_path);
286
287 if (error_code == MOUNT_ERROR_NONE)
288 mount_points_.insert(mount_path);
zel 2011/07/22 04:47:17 see my comments about this data not being enough,
tbarzic 2011/07/22 06:21:51 Done.
289
290 if (error_code == MOUNT_ERROR_NONE && type == MOUNT_TYPE_DEVICE &&
291 source_path && mount_path) {
292 std::string path(source_path);
286 DiskMap::iterator iter = disks_.find(path); 293 DiskMap::iterator iter = disks_.find(path);
287 if (iter == disks_.end()) { 294 if (iter == disks_.end()) {
288 // disk might have been removed by now? 295 // disk might have been removed by now?
289 return; 296 return;
290 } 297 }
291 Disk* disk = iter->second; 298 Disk* disk = iter->second;
292 DCHECK(disk); 299 DCHECK(disk);
293 disk->set_mount_path(mount_path); 300 disk->set_mount_path(mount_path);
294 FireDiskStatusUpdate(MOUNT_DISK_MOUNTED, disk); 301 FireDiskStatusUpdate(MOUNT_DISK_MOUNTED, disk);
295 } else {
296 LOG(WARNING) << "Mount request failed for device "
297 << device_path << ", with error: "
298 << (error_message ? error_message : "Unknown");
299 } 302 }
300 } 303 }
301 304
302 void OnUnmountRemovableDevice(const char* device_path, 305 void OnUnmountRemovableDevice(const char* device_path,
303 MountMethodErrorType error, 306 MountMethodErrorType error,
304 const char* error_message) { 307 const char* error_message) {
305 DCHECK(device_path); 308 DCHECK(device_path);
306 if (error == MOUNT_METHOD_ERROR_NONE && device_path) { 309 if (error == MOUNT_METHOD_ERROR_NONE && device_path) {
307 std::string path(device_path); 310 std::string path(device_path);
308 DiskMap::iterator iter = disks_.find(path); 311 DiskMap::iterator iter = disks_.find(path);
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 break; 472 break;
470 } 473 }
471 case DEVICE_REMOVED: { 474 case DEVICE_REMOVED: {
472 type = MOUNT_DEVICE_REMOVED; 475 type = MOUNT_DEVICE_REMOVED;
473 break; 476 break;
474 } 477 }
475 case DEVICE_SCANNED: { 478 case DEVICE_SCANNED: {
476 type = MOUNT_DEVICE_SCANNED; 479 type = MOUNT_DEVICE_SCANNED;
477 break; 480 break;
478 } 481 }
482 default: {
483 return;
484 }
479 } 485 }
480 FireDeviceStatusUpdate(type, std::string(device_path)); 486 FireDeviceStatusUpdate(type, std::string(device_path));
481 } 487 }
482 488
483 void Init() { 489 void Init() {
484 // Getting the monitor status so that the daemon starts up. 490 // Getting the monitor status so that the daemon starts up.
485 mount_status_connection_ = MonitorMountEvents( 491 mount_status_connection_ = MonitorAllMountEvents(
486 &MonitorMountEventsHandler, this); 492 &MonitorMountEventsHandler, &MountCompletedHandler, this);
487 } 493 }
488 494
489 void FireDiskStatusUpdate(MountLibraryEventType evt, 495 void FireDiskStatusUpdate(MountLibraryEventType evt,
490 const Disk* disk) { 496 const Disk* disk) {
491 // Make sure we run on UI thread. 497 // Make sure we run on UI thread.
492 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 498 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
493 FOR_EACH_OBSERVER( 499 FOR_EACH_OBSERVER(
494 Observer, observers_, DiskChanged(evt, disk)); 500 Observer, observers_, DiskChanged(evt, disk));
495 } 501 }
496 502
497 void FireDeviceStatusUpdate(MountLibraryEventType evt, 503 void FireDeviceStatusUpdate(MountLibraryEventType evt,
498 const std::string& device_path) { 504 const std::string& device_path) {
499 // Make sure we run on UI thread. 505 // Make sure we run on UI thread.
500 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 506 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
501 FOR_EACH_OBSERVER( 507 FOR_EACH_OBSERVER(
502 Observer, observers_, DeviceChanged(evt, device_path)); 508 Observer, observers_, DeviceChanged(evt, device_path));
503 } 509 }
504 510
511 void FireMountCompleted(MountError error_code,
512 const char* source_path,
513 MountType mount_type,
514 const char* mount_path) {
515 // Make sure we run on UI thread.
516 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
517 FOR_EACH_OBSERVER(
518 Observer, observers_, MountCompleted(error_code,
519 source_path,
520 mount_type,
521 mount_path));
522 }
523
505 // Mount event change observers. 524 // Mount event change observers.
506 ObserverList<Observer> observers_; 525 ObserverList<Observer> observers_;
507 526
508 // A reference to the mount api, to allow callbacks when the mount 527 // A reference to the mount api, to allow callbacks when the mount
509 // status changes. 528 // status changes.
510 MountEventConnection mount_status_connection_; 529 MountEventConnection mount_status_connection_;
511 530
512 // The list of disks found. 531 // The list of disks found.
513 MountLibrary::DiskMap disks_; 532 MountLibrary::DiskMap disks_;
514 533
534 MountLibrary::MountPointSet mount_points_;
535
515 DISALLOW_COPY_AND_ASSIGN(MountLibraryImpl); 536 DISALLOW_COPY_AND_ASSIGN(MountLibraryImpl);
516 }; 537 };
517 538
518 class MountLibraryStubImpl : public MountLibrary { 539 class MountLibraryStubImpl : public MountLibrary {
519 public: 540 public:
520 MountLibraryStubImpl() {} 541 MountLibraryStubImpl() {}
521 virtual ~MountLibraryStubImpl() {} 542 virtual ~MountLibraryStubImpl() {}
522 543
523 // MountLibrary overrides. 544 // MountLibrary overrides.
524 virtual void AddObserver(Observer* observer) OVERRIDE {} 545 virtual void AddObserver(Observer* observer) OVERRIDE {}
525 virtual void RemoveObserver(Observer* observer) OVERRIDE {} 546 virtual void RemoveObserver(Observer* observer) OVERRIDE {}
526 virtual const DiskMap& disks() const OVERRIDE { return disks_; } 547 virtual const DiskMap& disks() const OVERRIDE { return disks_; }
548 virtual const MountPointSet& mount_points() const OVERRIDE {
549 return mount_points_;
550 }
527 virtual void RequestMountInfoRefresh() OVERRIDE {} 551 virtual void RequestMountInfoRefresh() OVERRIDE {}
528 virtual void MountPath(const char* device_path) OVERRIDE {} 552 virtual void MountPath(const char* source_path, MountType type,
529 virtual void UnmountPath(const char* device_path) OVERRIDE {} 553 const MountPathOptions& options) OVERRIDE {}
554 virtual void UnmountPath(const char* path) OVERRIDE {}
530 virtual void UnmountDeviceRecursive(const char* device_path, 555 virtual void UnmountDeviceRecursive(const char* device_path,
531 UnmountDeviceRecursiveCallbackType callback, void* user_data) 556 UnmountDeviceRecursiveCallbackType callback, void* user_data)
532 OVERRIDE {} 557 OVERRIDE {}
533 558
534 private: 559 private:
535 // The list of disks found. 560 // The list of disks found.
536 DiskMap disks_; 561 DiskMap disks_;
562 MountPointSet mount_points_;
537 563
538 DISALLOW_COPY_AND_ASSIGN(MountLibraryStubImpl); 564 DISALLOW_COPY_AND_ASSIGN(MountLibraryStubImpl);
539 }; 565 };
540 566
541 // static 567 // static
542 MountLibrary* MountLibrary::GetImpl(bool stub) { 568 MountLibrary* MountLibrary::GetImpl(bool stub) {
543 if (stub) 569 if (stub)
544 return new MountLibraryStubImpl(); 570 return new MountLibraryStubImpl();
545 else 571 else
546 return new MountLibraryImpl(); 572 return new MountLibraryImpl();
547 } 573 }
548 574
549 } // namespace chromeos 575 } // namespace chromeos
550 576
551 // Allows InvokeLater without adding refcounting. This class is a Singleton and 577 // Allows InvokeLater without adding refcounting. This class is a Singleton and
552 // won't be deleted until it's last InvokeLater is run. 578 // won't be deleted until it's last InvokeLater is run.
553 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::MountLibraryImpl); 579 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::MountLibraryImpl);
554 580
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698