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

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 OnUnmountPath(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 UnmountMountPoint(
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 MountPointMap& 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;
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->OnUnmountPath(device_path, error, error_message);
206 error,
207 error_message);
208 } 206 }
209 207
210 // Callback for UnmountDeviceRecursive. 208 // Callback for UnmountDeviceRecursive.
211 static void UnmountDeviceRecursiveCallback(void* object, 209 static void UnmountDeviceRecursiveCallback(void* object,
212 const char* device_path, 210 const char* device_path,
213 const char* mount_path,
214 MountMethodErrorType error, 211 MountMethodErrorType error,
215 const char* error_message) { 212 const char* error_message) {
216 DCHECK(object); 213 DCHECK(object);
217 UnmountDeviceRecursiveCallbackData* cb_data = 214 UnmountDeviceRecursiveCallbackData* cb_data =
218 static_cast<UnmountDeviceRecursiveCallbackData*>(object); 215 static_cast<UnmountDeviceRecursiveCallbackData*>(object);
219 216
220 // Do standard processing for Unmount event. 217 // Do standard processing for Unmount event.
221 cb_data->object->OnUnmountRemovableDevice(device_path, 218 cb_data->object->OnUnmountPath(device_path,
222 error, 219 error,
223 error_message); 220 error_message);
224 if (error == MOUNT_METHOD_ERROR_LOCAL) { 221 if (error == MOUNT_METHOD_ERROR_LOCAL) {
225 cb_data->success = false; 222 cb_data->success = false;
226 } else if (error == MOUNT_METHOD_ERROR_NONE) { 223 } else if (error == MOUNT_METHOD_ERROR_NONE) {
227 LOG(WARNING) << device_path << " unmounted."; 224 LOG(WARNING) << device_path << " unmounted.";
228 } 225 }
229 226
230 // This is safe as long as all callbacks are called on the same thread as 227 // This is safe as long as all callbacks are called on the same thread as
231 // UnmountDeviceRecursive. 228 // UnmountDeviceRecursive.
232 cb_data->pending_callbacks_count--; 229 cb_data->pending_callbacks_count--;
233 230
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 // This method will receive events that are caused by drive status changes. 265 // This method will receive events that are caused by drive status changes.
269 static void MonitorMountEventsHandler(void* object, 266 static void MonitorMountEventsHandler(void* object,
270 MountEventType evt, 267 MountEventType evt,
271 const char* device_path) { 268 const char* device_path) {
272 DCHECK(object); 269 DCHECK(object);
273 MountLibraryImpl* self = static_cast<MountLibraryImpl*>(object); 270 MountLibraryImpl* self = static_cast<MountLibraryImpl*>(object);
274 self->OnMountEvent(evt, device_path); 271 self->OnMountEvent(evt, device_path);
275 } 272 }
276 273
277 274
278 void OnMountRemovableDevice(const char* device_path, 275 void OnMountCompleted(MountError error_code,
279 const char* mount_path, 276 const char* source_path,
280 MountMethodErrorType error, 277 MountType type,
281 const char* error_message) { 278 const char* mount_path) {
282 DCHECK(device_path); 279 DCHECK(source_path);
283 280
284 if (error == MOUNT_METHOD_ERROR_NONE && device_path && mount_path) { 281 FireMountCompleted(error_code, source_path, type, mount_path);
285 std::string path(device_path); 282
283 if (error_code == MOUNT_ERROR_NONE &&
284 mount_points_.find(source_path) == mount_points_.end()) {
285 mount_points_.insert(MountPointMap::value_type(source_path,
286 MountPointInfo(mount_path, type)));
287 }
288
289 if (error_code == MOUNT_ERROR_NONE && type == MOUNT_TYPE_DEVICE &&
290 source_path && mount_path) {
291 std::string path(source_path);
286 DiskMap::iterator iter = disks_.find(path); 292 DiskMap::iterator iter = disks_.find(path);
287 if (iter == disks_.end()) { 293 if (iter == disks_.end()) {
288 // disk might have been removed by now? 294 // disk might have been removed by now?
289 return; 295 return;
290 } 296 }
291 Disk* disk = iter->second; 297 Disk* disk = iter->second;
292 DCHECK(disk); 298 DCHECK(disk);
293 disk->set_mount_path(mount_path); 299 disk->set_mount_path(mount_path);
294 FireDiskStatusUpdate(MOUNT_DISK_MOUNTED, disk); 300 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 } 301 }
300 } 302 }
301 303
302 void OnUnmountRemovableDevice(const char* device_path, 304 void OnUnmountPath(const char* source_path,
Oleg Eterevsky 2011/07/22 13:34:53 Can we throw an event here also? Probably the same
tbarzic 2011/07/22 17:21:29 Done.
303 MountMethodErrorType error, 305 MountMethodErrorType error,
304 const char* error_message) { 306 const char* error_message) {
305 DCHECK(device_path); 307 DCHECK(source_path);
306 if (error == MOUNT_METHOD_ERROR_NONE && device_path) { 308
307 std::string path(device_path); 309 mount_points_.erase(source_path);
tbarzic 2011/07/22 08:01:29 this should go into if bellow
tbarzic 2011/07/22 17:21:29 Done.
310
311 if (error == MOUNT_METHOD_ERROR_NONE && source_path) {
312 std::string path(source_path);
308 DiskMap::iterator iter = disks_.find(path); 313 DiskMap::iterator iter = disks_.find(path);
309 if (iter == disks_.end()) { 314 if (iter == disks_.end()) {
310 // disk might have been removed by now? 315 // disk might have been removed by now?
311 return; 316 return;
312 } 317 }
313 Disk* disk = iter->second; 318 Disk* disk = iter->second;
314 DCHECK(disk); 319 DCHECK(disk);
315 disk->clear_mount_path(); 320 disk->clear_mount_path();
316 FireDiskStatusUpdate(MOUNT_DISK_UNMOUNTED, disk); 321 FireDiskStatusUpdate(MOUNT_DISK_UNMOUNTED, disk);
317 } else { 322 } else {
318 LOG(WARNING) << "Unmount request failed for device " 323 LOG(WARNING) << "Unmount request failed for device "
319 << device_path << ", with error: " 324 << source_path << ", with error: "
320 << (error_message ? error_message : "Unknown"); 325 << (error_message ? error_message : "Unknown");
321 } 326 }
322 } 327 }
323 328
324 void OnGetDiskProperties(const char* device_path, 329 void OnGetDiskProperties(const char* device_path,
325 const DiskInfo* disk1, 330 const DiskInfo* disk1,
326 MountMethodErrorType error, 331 MountMethodErrorType error,
327 const char* error_message) { 332 const char* error_message) {
328 DCHECK(device_path); 333 DCHECK(device_path);
329 if (error == MOUNT_METHOD_ERROR_NONE && device_path) { 334 if (error == MOUNT_METHOD_ERROR_NONE && device_path) {
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 break; 474 break;
470 } 475 }
471 case DEVICE_REMOVED: { 476 case DEVICE_REMOVED: {
472 type = MOUNT_DEVICE_REMOVED; 477 type = MOUNT_DEVICE_REMOVED;
473 break; 478 break;
474 } 479 }
475 case DEVICE_SCANNED: { 480 case DEVICE_SCANNED: {
476 type = MOUNT_DEVICE_SCANNED; 481 type = MOUNT_DEVICE_SCANNED;
477 break; 482 break;
478 } 483 }
484 default: {
485 return;
486 }
479 } 487 }
480 FireDeviceStatusUpdate(type, std::string(device_path)); 488 FireDeviceStatusUpdate(type, std::string(device_path));
481 } 489 }
482 490
483 void Init() { 491 void Init() {
484 // Getting the monitor status so that the daemon starts up. 492 // Getting the monitor status so that the daemon starts up.
485 mount_status_connection_ = MonitorMountEvents( 493 mount_status_connection_ = MonitorAllMountEvents(
486 &MonitorMountEventsHandler, this); 494 &MonitorMountEventsHandler, &MountCompletedHandler, this);
487 } 495 }
488 496
489 void FireDiskStatusUpdate(MountLibraryEventType evt, 497 void FireDiskStatusUpdate(MountLibraryEventType evt,
490 const Disk* disk) { 498 const Disk* disk) {
491 // Make sure we run on UI thread. 499 // Make sure we run on UI thread.
492 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 500 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
493 FOR_EACH_OBSERVER( 501 FOR_EACH_OBSERVER(
494 Observer, observers_, DiskChanged(evt, disk)); 502 Observer, observers_, DiskChanged(evt, disk));
495 } 503 }
496 504
497 void FireDeviceStatusUpdate(MountLibraryEventType evt, 505 void FireDeviceStatusUpdate(MountLibraryEventType evt,
498 const std::string& device_path) { 506 const std::string& device_path) {
499 // Make sure we run on UI thread. 507 // Make sure we run on UI thread.
500 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 508 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
501 FOR_EACH_OBSERVER( 509 FOR_EACH_OBSERVER(
502 Observer, observers_, DeviceChanged(evt, device_path)); 510 Observer, observers_, DeviceChanged(evt, device_path));
503 } 511 }
504 512
513 void FireMountCompleted(MountError error_code,
514 const char* source_path,
515 MountType mount_type,
516 const char* mount_path) {
517 // Make sure we run on UI thread.
518 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
519 FOR_EACH_OBSERVER(
520 Observer, observers_, MountCompleted(error_code,
521 source_path,
522 mount_type,
523 mount_path));
524 }
525
505 // Mount event change observers. 526 // Mount event change observers.
506 ObserverList<Observer> observers_; 527 ObserverList<Observer> observers_;
507 528
508 // A reference to the mount api, to allow callbacks when the mount 529 // A reference to the mount api, to allow callbacks when the mount
509 // status changes. 530 // status changes.
510 MountEventConnection mount_status_connection_; 531 MountEventConnection mount_status_connection_;
511 532
512 // The list of disks found. 533 // The list of disks found.
513 MountLibrary::DiskMap disks_; 534 MountLibrary::DiskMap disks_;
514 535
536 MountLibrary::MountPointMap mount_points_;
537
515 DISALLOW_COPY_AND_ASSIGN(MountLibraryImpl); 538 DISALLOW_COPY_AND_ASSIGN(MountLibraryImpl);
516 }; 539 };
517 540
518 class MountLibraryStubImpl : public MountLibrary { 541 class MountLibraryStubImpl : public MountLibrary {
519 public: 542 public:
520 MountLibraryStubImpl() {} 543 MountLibraryStubImpl() {}
521 virtual ~MountLibraryStubImpl() {} 544 virtual ~MountLibraryStubImpl() {}
522 545
523 // MountLibrary overrides. 546 // MountLibrary overrides.
524 virtual void AddObserver(Observer* observer) OVERRIDE {} 547 virtual void AddObserver(Observer* observer) OVERRIDE {}
525 virtual void RemoveObserver(Observer* observer) OVERRIDE {} 548 virtual void RemoveObserver(Observer* observer) OVERRIDE {}
526 virtual const DiskMap& disks() const OVERRIDE { return disks_; } 549 virtual const DiskMap& disks() const OVERRIDE { return disks_; }
550 virtual const MountPointMap& mount_points() const OVERRIDE {
551 return mount_points_;
552 }
527 virtual void RequestMountInfoRefresh() OVERRIDE {} 553 virtual void RequestMountInfoRefresh() OVERRIDE {}
528 virtual void MountPath(const char* device_path) OVERRIDE {} 554 virtual void MountPath(const char* source_path, MountType type,
529 virtual void UnmountPath(const char* device_path) OVERRIDE {} 555 const MountPathOptions& options) OVERRIDE {}
556 virtual void UnmountPath(const char* path) OVERRIDE {}
530 virtual void UnmountDeviceRecursive(const char* device_path, 557 virtual void UnmountDeviceRecursive(const char* device_path,
531 UnmountDeviceRecursiveCallbackType callback, void* user_data) 558 UnmountDeviceRecursiveCallbackType callback, void* user_data)
532 OVERRIDE {} 559 OVERRIDE {}
533 560
534 private: 561 private:
535 // The list of disks found. 562 // The list of disks found.
536 DiskMap disks_; 563 DiskMap disks_;
564 MountPointMap mount_points_;
537 565
538 DISALLOW_COPY_AND_ASSIGN(MountLibraryStubImpl); 566 DISALLOW_COPY_AND_ASSIGN(MountLibraryStubImpl);
539 }; 567 };
540 568
541 // static 569 // static
542 MountLibrary* MountLibrary::GetImpl(bool stub) { 570 MountLibrary* MountLibrary::GetImpl(bool stub) {
543 if (stub) 571 if (stub)
544 return new MountLibraryStubImpl(); 572 return new MountLibraryStubImpl();
545 else 573 else
546 return new MountLibraryImpl(); 574 return new MountLibraryImpl();
547 } 575 }
548 576
549 } // namespace chromeos 577 } // namespace chromeos
550 578
551 // Allows InvokeLater without adding refcounting. This class is a Singleton and 579 // Allows InvokeLater without adding refcounting. This class is a Singleton and
552 // won't be deleted until it's last InvokeLater is run. 580 // won't be deleted until it's last InvokeLater is run.
553 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::MountLibraryImpl); 581 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::MountLibraryImpl);
554 582
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698