OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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" |
11 #include "chrome/browser/chromeos/cros/cros_library.h" | 11 #include "chrome/browser/chromeos/cros/cros_library.h" |
12 #include "content/browser/browser_thread.h" | 12 #include "content/browser/browser_thread.h" |
13 | 13 |
| 14 const char* kLibraryNotLoaded = "Cros Library has not been loaded"; |
| 15 |
14 namespace chromeos { | 16 namespace chromeos { |
15 | 17 |
16 class MountLibraryImpl : public MountLibrary { | 18 class MountLibraryImpl : public MountLibrary { |
17 public: | 19 public: |
18 MountLibraryImpl() : mount_status_connection_(NULL) { | 20 MountLibraryImpl() : mount_status_connection_(NULL) { |
19 if (CrosLibrary::Get()->EnsureLoaded()) | 21 if (CrosLibrary::Get()->EnsureLoaded()) |
20 Init(); | 22 Init(); |
21 else | 23 else |
22 LOG(ERROR) << "Cros Library has not been loaded"; | 24 LOG(ERROR) << kLibraryNotLoaded; |
23 } | 25 } |
24 | 26 |
25 virtual ~MountLibraryImpl() { | 27 virtual ~MountLibraryImpl() { |
26 if (mount_status_connection_) | 28 if (mount_status_connection_) |
27 DisconnectMountEventMonitor(mount_status_connection_); | 29 DisconnectMountEventMonitor(mount_status_connection_); |
28 } | 30 } |
29 | 31 |
30 // MountLibrary overrides. | 32 // MountLibrary overrides. |
31 virtual void AddObserver(Observer* observer) OVERRIDE { | 33 virtual void AddObserver(Observer* observer) OVERRIDE { |
32 observers_.AddObserver(observer); | 34 observers_.AddObserver(observer); |
33 } | 35 } |
34 | 36 |
35 virtual void RemoveObserver(Observer* observer) OVERRIDE { | 37 virtual void RemoveObserver(Observer* observer) OVERRIDE { |
36 observers_.RemoveObserver(observer); | 38 observers_.RemoveObserver(observer); |
37 } | 39 } |
38 | 40 |
39 virtual void MountPath(const char* device_path) OVERRIDE { | 41 virtual void MountPath(const char* device_path) OVERRIDE { |
| 42 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 43 if (!CrosLibrary::Get()->EnsureLoaded()) { |
| 44 OnMountRemovableDevice(device_path, |
| 45 NULL, |
| 46 MOUNT_METHOD_ERROR_NOT_LOADED, |
| 47 kLibraryNotLoaded); |
| 48 return; |
| 49 } |
40 MountRemovableDevice(device_path, | 50 MountRemovableDevice(device_path, |
41 &MountLibraryImpl::MountRemovableDeviceCallback, | 51 &MountLibraryImpl::MountRemovableDeviceCallback, |
42 this); | 52 this); |
43 } | 53 } |
44 | 54 |
45 virtual void UnmountPath(const char* device_path) OVERRIDE { | 55 virtual void UnmountPath(const char* device_path) OVERRIDE { |
| 56 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 57 if (!CrosLibrary::Get()->EnsureLoaded()) { |
| 58 OnUnmountRemovableDevice(device_path, |
| 59 MOUNT_METHOD_ERROR_NOT_LOADED, |
| 60 kLibraryNotLoaded); |
| 61 return; |
| 62 } |
46 UnmountRemovableDevice(device_path, | 63 UnmountRemovableDevice(device_path, |
47 &MountLibraryImpl::UnmountRemovableDeviceCallback, | 64 &MountLibraryImpl::UnmountRemovableDeviceCallback, |
48 this); | 65 this); |
49 } | 66 } |
50 | 67 |
51 virtual void RequestMountInfoRefresh() OVERRIDE { | 68 virtual void RequestMountInfoRefresh() OVERRIDE { |
| 69 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 70 if (!CrosLibrary::Get()->EnsureLoaded()) { |
| 71 OnRequestMountInfo(NULL, |
| 72 0, |
| 73 MOUNT_METHOD_ERROR_NOT_LOADED, |
| 74 kLibraryNotLoaded); |
| 75 return; |
| 76 } |
52 RequestMountInfo(&MountLibraryImpl::RequestMountInfoCallback, | 77 RequestMountInfo(&MountLibraryImpl::RequestMountInfoCallback, |
53 this); | 78 this); |
54 } | 79 } |
55 | 80 |
56 virtual void RefreshDiskProperties(const Disk* disk) OVERRIDE { | 81 virtual void RefreshDiskProperties(const Disk* disk) OVERRIDE { |
| 82 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
57 DCHECK(disk); | 83 DCHECK(disk); |
| 84 if (!CrosLibrary::Get()->EnsureLoaded()) { |
| 85 OnGetDiskProperties(disk->device_path().c_str(), |
| 86 NULL, |
| 87 MOUNT_METHOD_ERROR_NOT_LOADED, |
| 88 kLibraryNotLoaded); |
| 89 return; |
| 90 } |
58 GetDiskProperties(disk->device_path().c_str(), | 91 GetDiskProperties(disk->device_path().c_str(), |
59 &MountLibraryImpl::GetDiskPropertiesCallback, | 92 &MountLibraryImpl::GetDiskPropertiesCallback, |
60 this); | 93 this); |
61 } | 94 } |
62 | 95 |
63 const DiskMap& disks() const OVERRIDE { return disks_; } | 96 const DiskMap& disks() const OVERRIDE { return disks_; } |
64 | 97 |
65 private: | 98 private: |
66 | 99 |
67 // Callback for MountRemovableDevice method. | 100 // Callback for MountRemovableDevice method. |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 else | 401 else |
369 return new MountLibraryImpl(); | 402 return new MountLibraryImpl(); |
370 } | 403 } |
371 | 404 |
372 } // namespace chromeos | 405 } // namespace chromeos |
373 | 406 |
374 // Allows InvokeLater without adding refcounting. This class is a Singleton and | 407 // Allows InvokeLater without adding refcounting. This class is a Singleton and |
375 // won't be deleted until it's last InvokeLater is run. | 408 // won't be deleted until it's last InvokeLater is run. |
376 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::MountLibraryImpl); | 409 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::MountLibraryImpl); |
377 | 410 |
OLD | NEW |