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

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

Issue 7891021: Use stub impl when libcros fails to load (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase with power library changes Created 9 years, 3 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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 94
95 MountLibrary::Disk::~Disk() {} 95 MountLibrary::Disk::~Disk() {}
96 96
97 class MountLibcrosProxyImpl : public MountLibcrosProxy { 97 class MountLibcrosProxyImpl : public MountLibcrosProxy {
98 public: 98 public:
99 virtual void CallMountPath(const char* source_path, 99 virtual void CallMountPath(const char* source_path,
100 MountType type, 100 MountType type,
101 const MountPathOptions& options, 101 const MountPathOptions& options,
102 MountCompletedMonitor callback, 102 MountCompletedMonitor callback,
103 void* object) OVERRIDE { 103 void* object) OVERRIDE {
104 MountSourcePath(source_path, type, options, callback, object); 104 chromeos::MountSourcePath(source_path, type, options, callback, object);
105 } 105 }
106 106
107 virtual void CallUnmountPath(const char* path, 107 virtual void CallUnmountPath(const char* path,
108 UnmountRequestCallback callback, 108 UnmountRequestCallback callback,
109 void* object) OVERRIDE { 109 void* object) OVERRIDE {
110 UnmountMountPoint(path, callback, object); 110 chromeos::UnmountMountPoint(path, callback, object);
111 } 111 }
112 112
113 virtual void CallRequestMountInfo(RequestMountInfoCallback callback, 113 virtual void CallRequestMountInfo(RequestMountInfoCallback callback,
114 void* object) OVERRIDE { 114 void* object) OVERRIDE {
115 RequestMountInfo(callback, object); 115 chromeos::RequestMountInfo(callback, object);
116 } 116 }
117 117
118 virtual void CallFormatDevice(const char* file_path, 118 virtual void CallFormatDevice(const char* file_path,
119 const char* filesystem, 119 const char* filesystem,
120 FormatRequestCallback callback, 120 FormatRequestCallback callback,
121 void* object) OVERRIDE { 121 void* object) OVERRIDE {
122 FormatDevice(file_path, filesystem, callback, object); 122 chromeos::FormatDevice(file_path, filesystem, callback, object);
123 } 123 }
124 124
125 virtual void CallGetDiskProperties(const char* device_path, 125 virtual void CallGetDiskProperties(const char* device_path,
126 GetDiskPropertiesCallback callback, 126 GetDiskPropertiesCallback callback,
127 void* object) OVERRIDE { 127 void* object) OVERRIDE {
128 GetDiskProperties(device_path, callback, object); 128 chromeos::GetDiskProperties(device_path, callback, object);
129 } 129 }
130 130
131 virtual MountEventConnection MonitorCrosDisks(MountEventMonitor monitor, 131 virtual MountEventConnection MonitorCrosDisks(
132 MountEventMonitor monitor,
132 MountCompletedMonitor mount_completed_monitor, 133 MountCompletedMonitor mount_completed_monitor,
133 void* object) OVERRIDE { 134 void* object) OVERRIDE {
134 return MonitorAllMountEvents(monitor, mount_completed_monitor, object); 135 return chromeos::MonitorAllMountEvents(
136 monitor, mount_completed_monitor, object);
135 } 137 }
136 138
137 virtual void DisconnectCrosDisksMonitorIfSet(MountEventConnection conn) 139 virtual void DisconnectCrosDisksMonitorIfSet(
138 OVERRIDE { 140 MountEventConnection conn) OVERRIDE {
139 if (conn) 141 if (conn)
140 DisconnectMountEventMonitor(conn); 142 chromeos::DisconnectMountEventMonitor(conn);
141 } 143 }
142 }; 144 };
143 145
144 class MountLibraryImpl : public MountLibrary { 146 class MountLibraryImpl : public MountLibrary {
145 147
146 struct UnmountDeviceRecursiveCallbackData { 148 struct UnmountDeviceRecursiveCallbackData {
147 MountLibraryImpl* const object; 149 MountLibraryImpl* const object;
148 void* user_data; 150 void* user_data;
149 UnmountDeviceRecursiveCallbackType callback; 151 UnmountDeviceRecursiveCallbackType callback;
150 size_t pending_callbacks_count; 152 size_t pending_callbacks_count;
151 bool success; 153 bool success;
152 154
153 UnmountDeviceRecursiveCallbackData(MountLibraryImpl* const o, void* ud, 155 UnmountDeviceRecursiveCallbackData(MountLibraryImpl* const o, void* ud,
154 UnmountDeviceRecursiveCallbackType cb, int count) 156 UnmountDeviceRecursiveCallbackType cb, int count)
155 : object(o), 157 : object(o),
156 user_data(ud), 158 user_data(ud),
157 callback(cb), 159 callback(cb),
158 pending_callbacks_count(count), 160 pending_callbacks_count(count),
159 success(true) { 161 success(true) {
160 } 162 }
161 }; 163 };
162 164
163 public: 165 public:
164 MountLibraryImpl() : libcros_proxy_(new MountLibcrosProxyImpl()), 166 MountLibraryImpl() : libcros_proxy_(new MountLibcrosProxyImpl()),
165 mount_status_connection_(NULL) { 167 mount_status_connection_(NULL) {
166 if (CrosLibrary::Get()->EnsureLoaded())
167 Init();
168 else
169 LOG(ERROR) << kLibraryNotLoaded;
170 } 168 }
171 169
172 virtual ~MountLibraryImpl() { 170 virtual ~MountLibraryImpl() {
173 libcros_proxy_->DisconnectCrosDisksMonitorIfSet( 171 libcros_proxy_->DisconnectCrosDisksMonitorIfSet(
174 mount_status_connection_); 172 mount_status_connection_);
175 } 173 }
176 174
177 // MountLibrary overrides. 175 // MountLibrary overrides.
176 virtual void Init() OVERRIDE {
177 DCHECK(CrosLibrary::Get()->libcros_loaded());
178 // Getting the monitor status so that the daemon starts up.
179 mount_status_connection_ = libcros_proxy_->MonitorCrosDisks(
180 &MonitorMountEventsHandler, &MountCompletedHandler, this);
181 }
182
178 virtual void AddObserver(Observer* observer) OVERRIDE { 183 virtual void AddObserver(Observer* observer) OVERRIDE {
179 observers_.AddObserver(observer); 184 observers_.AddObserver(observer);
180 } 185 }
181 186
182 virtual void RemoveObserver(Observer* observer) OVERRIDE { 187 virtual void RemoveObserver(Observer* observer) OVERRIDE {
183 observers_.RemoveObserver(observer); 188 observers_.RemoveObserver(observer);
184 } 189 }
185 190
186 virtual void MountPath(const char* source_path, 191 virtual void MountPath(const char* source_path,
187 MountType type, 192 MountType type,
188 const MountPathOptions& options) OVERRIDE { 193 const MountPathOptions& options) OVERRIDE {
189 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 194 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
190 if (!CrosLibrary::Get()->EnsureLoaded()) {
191 OnMountCompleted(MOUNT_ERROR_LIBRARY_NOT_LOADED,
192 MountPointInfo(source_path,
193 NULL,
194 type,
195 MOUNT_CONDITION_NONE));
196 return;
197 }
198 libcros_proxy_->CallMountPath(source_path, type, options, 195 libcros_proxy_->CallMountPath(source_path, type, options,
199 &MountCompletedHandler, this); 196 &MountCompletedHandler, this);
200 } 197 }
201 198
202 virtual void UnmountPath(const char* mount_path) OVERRIDE { 199 virtual void UnmountPath(const char* mount_path) OVERRIDE {
203 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 200 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
204 if (!CrosLibrary::Get()->EnsureLoaded()) {
205 OnUnmountPath(mount_path,
206 MOUNT_METHOD_ERROR_LOCAL,
207 kLibraryNotLoaded);
208 return;
209 }
210
211 libcros_proxy_->CallUnmountPath(mount_path, &UnmountMountPointCallback, 201 libcros_proxy_->CallUnmountPath(mount_path, &UnmountMountPointCallback,
212 this); 202 this);
213 } 203 }
214 204
215 virtual void FormatUnmountedDevice(const char* file_path) OVERRIDE { 205 virtual void FormatUnmountedDevice(const char* file_path) OVERRIDE {
216 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 206 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
217 if (!CrosLibrary::Get()->EnsureLoaded()) {
218 OnFormatDevice(file_path,
219 false,
220 MOUNT_METHOD_ERROR_LOCAL,
221 kLibraryNotLoaded);
222 return;
223 }
224 for (MountLibrary::DiskMap::iterator it = disks_.begin(); 207 for (MountLibrary::DiskMap::iterator it = disks_.begin();
225 it != disks_.end(); ++it) { 208 it != disks_.end(); ++it) {
226 if (it->second->file_path().compare(file_path) == 0 && 209 if (it->second->file_path().compare(file_path) == 0 &&
227 !it->second->mount_path().empty()) { 210 !it->second->mount_path().empty()) {
228 OnFormatDevice(file_path, 211 OnFormatDevice(file_path,
229 false, 212 false,
230 MOUNT_METHOD_ERROR_LOCAL, 213 MOUNT_METHOD_ERROR_LOCAL,
231 "Device is still mounted."); 214 "Device is still mounted.");
232 return; 215 return;
233 } 216 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 UnmountPath(disk->mount_path().c_str()); 250 UnmountPath(disk->mount_path().c_str());
268 } 251 }
269 252
270 virtual void UnmountDeviceRecursive(const char* device_path, 253 virtual void UnmountDeviceRecursive(const char* device_path,
271 UnmountDeviceRecursiveCallbackType callback, void* user_data) 254 UnmountDeviceRecursiveCallbackType callback, void* user_data)
272 OVERRIDE { 255 OVERRIDE {
273 bool success = true; 256 bool success = true;
274 const char* error_message = NULL; 257 const char* error_message = NULL;
275 std::vector<const char*> devices_to_unmount; 258 std::vector<const char*> devices_to_unmount;
276 259
277 if (!CrosLibrary::Get()->EnsureLoaded()) { 260 // Get list of all devices to unmount.
278 success = false; 261 int device_path_len = strlen(device_path);
279 error_message = kLibraryNotLoaded; 262 for (DiskMap::iterator it = disks_.begin(); it != disks_.end(); ++it) {
280 } else { 263 if (!it->second->mount_path().empty() &&
281 // Get list of all devices to unmount. 264 strncmp(device_path, it->second->device_path().c_str(),
282 int device_path_len = strlen(device_path); 265 device_path_len) == 0) {
283 for (DiskMap::iterator it = disks_.begin(); it != disks_.end(); ++it) { 266 devices_to_unmount.push_back(it->second->mount_path().c_str());
284 if (!it->second->mount_path().empty() &&
285 strncmp(device_path, it->second->device_path().c_str(),
286 device_path_len) == 0) {
287 devices_to_unmount.push_back(it->second->mount_path().c_str());
288 }
289 }
290
291 // We should detect at least original device.
292 if (devices_to_unmount.size() == 0) {
293 if (disks_.find(device_path) == disks_.end()) {
294 success = false;
295 error_message = kDeviceNotFound;
296 } else {
297 // Nothing to unmount.
298 callback(user_data, true);
299 return;
300 }
301 } 267 }
302 } 268 }
303 269
270 // We should detect at least original device.
271 if (devices_to_unmount.size() == 0) {
272 if (disks_.find(device_path) == disks_.end()) {
273 success = false;
274 error_message = kDeviceNotFound;
275 } else {
276 // Nothing to unmount.
277 callback(user_data, true);
278 return;
279 }
280 }
281
304 if (success) { 282 if (success) {
305 // We will send the same callback data object to all Unmount calls and use 283 // We will send the same callback data object to all Unmount calls and use
306 // it to syncronize callbacks. 284 // it to syncronize callbacks.
307 UnmountDeviceRecursiveCallbackData* 285 UnmountDeviceRecursiveCallbackData*
308 cb_data = new UnmountDeviceRecursiveCallbackData(this, user_data, 286 cb_data = new UnmountDeviceRecursiveCallbackData(this, user_data,
309 callback, devices_to_unmount.size()); 287 callback, devices_to_unmount.size());
310 for (std::vector<const char*>::iterator it = devices_to_unmount.begin(); 288 for (std::vector<const char*>::iterator it = devices_to_unmount.begin();
311 it != devices_to_unmount.end(); 289 it != devices_to_unmount.end();
312 ++it) { 290 ++it) {
313 libcros_proxy_->CallUnmountPath(*it, &UnmountDeviceRecursiveCallback, 291 libcros_proxy_->CallUnmountPath(*it, &UnmountDeviceRecursiveCallback,
314 cb_data); 292 cb_data);
315 } 293 }
316 } else { 294 } else {
317 LOG(WARNING) << "Unmount recursive request failed for device " 295 LOG(WARNING) << "Unmount recursive request failed for device "
318 << device_path << ", with error: " << error_message; 296 << device_path << ", with error: " << error_message;
319 callback(user_data, false); 297 callback(user_data, false);
320 } 298 }
321 } 299 }
322 300
323 virtual void RequestMountInfoRefresh() OVERRIDE { 301 virtual void RequestMountInfoRefresh() OVERRIDE {
324 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 302 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
325 if (!CrosLibrary::Get()->EnsureLoaded()) {
326 OnRequestMountInfo(NULL,
327 0,
328 MOUNT_METHOD_ERROR_LOCAL,
329 kLibraryNotLoaded);
330 return;
331 }
332 libcros_proxy_->CallRequestMountInfo(RequestMountInfoCallback, this); 303 libcros_proxy_->CallRequestMountInfo(RequestMountInfoCallback, this);
333 } 304 }
334 305
335 const DiskMap& disks() const OVERRIDE { return disks_; } 306 const DiskMap& disks() const OVERRIDE { return disks_; }
336 const MountPointMap& mount_points() const OVERRIDE { return mount_points_; } 307 const MountPointMap& mount_points() const OVERRIDE { return mount_points_; }
337 308
338 virtual void SetLibcrosProxy(MountLibcrosProxy* proxy) OVERRIDE { 309 virtual void SetLibcrosProxy(MountLibcrosProxy* proxy) OVERRIDE {
339 libcros_proxy_->DisconnectCrosDisksMonitorIfSet(mount_status_connection_); 310 libcros_proxy_->DisconnectCrosDisksMonitorIfSet(mount_status_connection_);
340 libcros_proxy_.reset(proxy); 311 libcros_proxy_.reset(proxy);
341 mount_status_connection_ = libcros_proxy_->MonitorCrosDisks( 312 mount_status_connection_ = libcros_proxy_->MonitorCrosDisks(
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
715 type = MOUNT_FORMATTING_FINISHED; 686 type = MOUNT_FORMATTING_FINISHED;
716 break; 687 break;
717 } 688 }
718 default: { 689 default: {
719 return; 690 return;
720 } 691 }
721 } 692 }
722 FireDeviceStatusUpdate(type, std::string(device_path)); 693 FireDeviceStatusUpdate(type, std::string(device_path));
723 } 694 }
724 695
725 void Init() {
726 // Getting the monitor status so that the daemon starts up.
727 mount_status_connection_ = libcros_proxy_->MonitorCrosDisks(
728 &MonitorMountEventsHandler, &MountCompletedHandler, this);
729 }
730
731 void FireDiskStatusUpdate(MountLibraryEventType evt, 696 void FireDiskStatusUpdate(MountLibraryEventType evt,
732 const Disk* disk) { 697 const Disk* disk) {
733 // Make sure we run on UI thread. 698 // Make sure we run on UI thread.
734 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 699 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
735 FOR_EACH_OBSERVER( 700 FOR_EACH_OBSERVER(
736 Observer, observers_, DiskChanged(evt, disk)); 701 Observer, observers_, DiskChanged(evt, disk));
737 } 702 }
738 703
739 void FireDeviceStatusUpdate(MountLibraryEventType evt, 704 void FireDeviceStatusUpdate(MountLibraryEventType evt,
740 const std::string& device_path) { 705 const std::string& device_path) {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
806 771
807 DISALLOW_COPY_AND_ASSIGN(MountLibraryImpl); 772 DISALLOW_COPY_AND_ASSIGN(MountLibraryImpl);
808 }; 773 };
809 774
810 class MountLibraryStubImpl : public MountLibrary { 775 class MountLibraryStubImpl : public MountLibrary {
811 public: 776 public:
812 MountLibraryStubImpl() {} 777 MountLibraryStubImpl() {}
813 virtual ~MountLibraryStubImpl() {} 778 virtual ~MountLibraryStubImpl() {}
814 779
815 // MountLibrary overrides. 780 // MountLibrary overrides.
781 virtual void Init() OVERRIDE {}
816 virtual void AddObserver(Observer* observer) OVERRIDE {} 782 virtual void AddObserver(Observer* observer) OVERRIDE {}
817 virtual void RemoveObserver(Observer* observer) OVERRIDE {} 783 virtual void RemoveObserver(Observer* observer) OVERRIDE {}
818 virtual const DiskMap& disks() const OVERRIDE { return disks_; } 784 virtual const DiskMap& disks() const OVERRIDE { return disks_; }
819 virtual const MountPointMap& mount_points() const OVERRIDE { 785 virtual const MountPointMap& mount_points() const OVERRIDE {
820 return mount_points_; 786 return mount_points_;
821 } 787 }
822 virtual void RequestMountInfoRefresh() OVERRIDE {} 788 virtual void RequestMountInfoRefresh() OVERRIDE {}
823 virtual void MountPath(const char* source_path, MountType type, 789 virtual void MountPath(const char* source_path, MountType type,
824 const MountPathOptions& options) OVERRIDE {} 790 const MountPathOptions& options) OVERRIDE {}
825 virtual void UnmountPath(const char* mount_path) OVERRIDE {} 791 virtual void UnmountPath(const char* mount_path) OVERRIDE {}
826 virtual void FormatUnmountedDevice(const char* device_path) OVERRIDE {} 792 virtual void FormatUnmountedDevice(const char* device_path) OVERRIDE {}
827 virtual void FormatMountedDevice(const char* mount_path) OVERRIDE {} 793 virtual void FormatMountedDevice(const char* mount_path) OVERRIDE {}
828 virtual void UnmountDeviceRecursive(const char* device_path, 794 virtual void UnmountDeviceRecursive(const char* device_path,
829 UnmountDeviceRecursiveCallbackType callback, void* user_data) 795 UnmountDeviceRecursiveCallbackType callback, void* user_data)
830 OVERRIDE {} 796 OVERRIDE {}
831 private: 797 private:
832 // The list of disks found. 798 // The list of disks found.
833 DiskMap disks_; 799 DiskMap disks_;
834 MountPointMap mount_points_; 800 MountPointMap mount_points_;
835 801
836 DISALLOW_COPY_AND_ASSIGN(MountLibraryStubImpl); 802 DISALLOW_COPY_AND_ASSIGN(MountLibraryStubImpl);
837 }; 803 };
838 804
839 // static 805 // static
840 MountLibrary* MountLibrary::GetImpl(bool stub) { 806 MountLibrary* MountLibrary::GetImpl(bool stub) {
807 MountLibrary* impl;
841 if (stub) 808 if (stub)
842 return new MountLibraryStubImpl(); 809 impl = new MountLibraryStubImpl();
843 else 810 else
844 return new MountLibraryImpl(); 811 impl = new MountLibraryImpl();
812 impl->Init();
813 return impl;
845 } 814 }
846 815
847 } // namespace chromeos 816 } // namespace chromeos
848
849 // Allows InvokeLater without adding refcounting. This class is a Singleton and
850 // won't be deleted until it's last InvokeLater is run.
851 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::MountLibraryImpl);
852
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/cros/mount_library.h ('k') | chrome/browser/chromeos/cros/network_library.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698