OLD | NEW |
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/extensions/file_browser_event_router.h" | 5 #include "chrome/browser/chromeos/extensions/file_browser_event_router.h" |
6 | 6 |
7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "chrome/browser/chromeos/cros/cros_library.h" | 10 #include "chrome/browser/chromeos/cros/cros_library.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 DictionaryValue* result = new DictionaryValue(); | 47 DictionaryValue* result = new DictionaryValue(); |
48 result->SetString("mountPath", disk->mount_path()); | 48 result->SetString("mountPath", disk->mount_path()); |
49 result->SetString("devicePath", disk->device_path()); | 49 result->SetString("devicePath", disk->device_path()); |
50 result->SetString("label", disk->device_label()); | 50 result->SetString("label", disk->device_label()); |
51 result->SetString("deviceType", DeviceTypeToString(disk->device_type())); | 51 result->SetString("deviceType", DeviceTypeToString(disk->device_type())); |
52 result->SetInteger("totalSizeKB", disk->total_size() / 1024); | 52 result->SetInteger("totalSizeKB", disk->total_size() / 1024); |
53 result->SetBoolean("readOnly", disk->is_read_only()); | 53 result->SetBoolean("readOnly", disk->is_read_only()); |
54 return result; | 54 return result; |
55 } | 55 } |
56 | 56 |
| 57 const char* MountErrorToString(chromeos::MountError error) { |
| 58 switch (error) { |
| 59 case chromeos::MOUNT_ERROR_NONE: |
| 60 return "success"; |
| 61 case chromeos::MOUNT_ERROR_UNKNOWN: |
| 62 return "error_unknown"; |
| 63 case chromeos::MOUNT_ERROR_INTERNAL: |
| 64 return "error_internal"; |
| 65 case chromeos::MOUNT_ERROR_UNKNOWN_FILESYSTEM: |
| 66 return "error_unknown_filesystem"; |
| 67 case chromeos::MOUNT_ERROR_UNSUPORTED_FILESYSTEM: |
| 68 return "error_unsuported_filesystem"; |
| 69 case chromeos::MOUNT_ERROR_INVALID_ARCHIVE: |
| 70 return "error_invalid_archive"; |
| 71 case chromeos::MOUNT_ERROR_LIBRARY_NOT_LOADED: |
| 72 return "error_libcros_missing"; |
| 73 default: |
| 74 NOTREACHED(); |
| 75 } |
| 76 return ""; |
| 77 } |
| 78 |
57 ExtensionFileBrowserEventRouter::ExtensionFileBrowserEventRouter( | 79 ExtensionFileBrowserEventRouter::ExtensionFileBrowserEventRouter( |
58 Profile* profile) | 80 Profile* profile) |
59 : delegate_(new ExtensionFileBrowserEventRouter::FileWatcherDelegate(this)), | 81 : delegate_(new ExtensionFileBrowserEventRouter::FileWatcherDelegate(this)), |
60 profile_(profile) { | 82 profile_(profile) { |
61 } | 83 } |
62 | 84 |
63 ExtensionFileBrowserEventRouter::~ExtensionFileBrowserEventRouter() { | 85 ExtensionFileBrowserEventRouter::~ExtensionFileBrowserEventRouter() { |
64 DCHECK(file_watchers_.empty()); | 86 DCHECK(file_watchers_.empty()); |
65 STLDeleteValues(&file_watchers_); | 87 STLDeleteValues(&file_watchers_); |
66 | 88 |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 const std::string& device_path) { | 168 const std::string& device_path) { |
147 if (event == chromeos::MOUNT_DEVICE_ADDED) { | 169 if (event == chromeos::MOUNT_DEVICE_ADDED) { |
148 OnDeviceAdded(device_path); | 170 OnDeviceAdded(device_path); |
149 } else if (event == chromeos::MOUNT_DEVICE_REMOVED) { | 171 } else if (event == chromeos::MOUNT_DEVICE_REMOVED) { |
150 OnDeviceRemoved(device_path); | 172 OnDeviceRemoved(device_path); |
151 } else if (event == chromeos::MOUNT_DEVICE_SCANNED) { | 173 } else if (event == chromeos::MOUNT_DEVICE_SCANNED) { |
152 OnDeviceScanned(device_path); | 174 OnDeviceScanned(device_path); |
153 } | 175 } |
154 } | 176 } |
155 | 177 |
| 178 void ExtensionFileBrowserEventRouter::MountCompleted( |
| 179 chromeos::MountLibrary::MountEvent event_type, |
| 180 chromeos::MountError error_code, |
| 181 const chromeos::MountLibrary::MountPointInfo& mount_info) { |
| 182 DispatchMountCompletedEvent(event_type, error_code, mount_info); |
| 183 } |
| 184 |
156 void ExtensionFileBrowserEventRouter::HandleFileWatchNotification( | 185 void ExtensionFileBrowserEventRouter::HandleFileWatchNotification( |
157 const FilePath& local_path, bool got_error) { | 186 const FilePath& local_path, bool got_error) { |
158 base::AutoLock lock(lock_); | 187 base::AutoLock lock(lock_); |
159 WatcherMap::const_iterator iter = file_watchers_.find(local_path); | 188 WatcherMap::const_iterator iter = file_watchers_.find(local_path); |
160 if (iter == file_watchers_.end()) { | 189 if (iter == file_watchers_.end()) { |
161 NOTREACHED(); | 190 NOTREACHED(); |
162 return; | 191 return; |
163 } | 192 } |
164 DispatchFolderChangeEvent(iter->second->virtual_path, got_error, | 193 DispatchFolderChangeEvent(iter->second->virtual_path, got_error, |
165 iter->second->extensions); | 194 iter->second->extensions); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 DictionaryValue* disk_info = DiskToDictionaryValue(disk); | 240 DictionaryValue* disk_info = DiskToDictionaryValue(disk); |
212 mount_info->Set("volumeInfo", disk_info); | 241 mount_info->Set("volumeInfo", disk_info); |
213 | 242 |
214 std::string args_json; | 243 std::string args_json; |
215 base::JSONWriter::Write(&args, false /* pretty_print */, &args_json); | 244 base::JSONWriter::Write(&args, false /* pretty_print */, &args_json); |
216 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( | 245 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( |
217 extension_event_names::kOnFileBrowserDiskChanged, args_json, NULL, | 246 extension_event_names::kOnFileBrowserDiskChanged, args_json, NULL, |
218 GURL()); | 247 GURL()); |
219 } | 248 } |
220 | 249 |
| 250 void ExtensionFileBrowserEventRouter::DispatchMountCompletedEvent( |
| 251 chromeos::MountLibrary::MountEvent event, |
| 252 chromeos::MountError error_code, |
| 253 const chromeos::MountLibrary::MountPointInfo& mount_info) { |
| 254 if (!profile_ || mount_info.mount_type == chromeos::MOUNT_TYPE_INVALID) { |
| 255 NOTREACHED(); |
| 256 return; |
| 257 } |
| 258 |
| 259 ListValue args; |
| 260 DictionaryValue* mount_info_value = new DictionaryValue(); |
| 261 args.Append(mount_info_value); |
| 262 mount_info_value->SetString("sourcePath", mount_info.source_path); |
| 263 if (event == chromeos::MountLibrary::MOUNTING) { |
| 264 mount_info_value->SetString("eventType", "mount"); |
| 265 } else { |
| 266 mount_info_value->SetString("eventType", "unmount"); |
| 267 } |
| 268 mount_info_value->SetString("status", MountErrorToString(error_code)); |
| 269 chromeos::MountLibrary* lib = chromeos::CrosLibrary::Get()->GetMountLibrary(); |
| 270 mount_info_value->SetString("mountType", |
| 271 lib->MountTypeToString(mount_info.mount_type)); |
| 272 mount_info_value->SetString("mountPath", mount_info.mount_path); |
| 273 |
| 274 std::string args_json; |
| 275 base::JSONWriter::Write(&args, false /* pretty_print */, &args_json); |
| 276 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( |
| 277 extension_event_names::kOnFileBrowserMountCompleted, args_json, NULL, |
| 278 GURL()); |
| 279 } |
| 280 |
221 void ExtensionFileBrowserEventRouter::OnDiskAdded( | 281 void ExtensionFileBrowserEventRouter::OnDiskAdded( |
222 const chromeos::MountLibrary::Disk* disk) { | 282 const chromeos::MountLibrary::Disk* disk) { |
223 VLOG(1) << "Disk added: " << disk->device_path(); | 283 VLOG(1) << "Disk added: " << disk->device_path(); |
224 if (disk->device_path().empty()) { | 284 if (disk->device_path().empty()) { |
225 VLOG(1) << "Empty system path for " << disk->device_path(); | 285 VLOG(1) << "Empty system path for " << disk->device_path(); |
226 return; | 286 return; |
227 } | 287 } |
228 if (disk->is_parent()) { | 288 if (disk->is_parent()) { |
229 if (!disk->has_media()) { | 289 if (!disk->has_media()) { |
230 HideDeviceNotification(disk->system_path()); | 290 HideDeviceNotification(disk->system_path()); |
231 return; | 291 return; |
232 } | 292 } |
233 } | 293 } |
234 | 294 |
235 // If disk is not mounted yet, give it a try. | 295 // If disk is not mounted yet, give it a try. |
236 if (disk->mount_path().empty()) { | 296 if (disk->mount_path().empty()) { |
237 // Initiate disk mount operation. | 297 // Initiate disk mount operation. |
238 chromeos::MountLibrary* lib = | 298 chromeos::MountLibrary* lib = |
239 chromeos::CrosLibrary::Get()->GetMountLibrary(); | 299 chromeos::CrosLibrary::Get()->GetMountLibrary(); |
240 lib->MountPath(disk->device_path().c_str()); | 300 lib->MountPath(disk->device_path().c_str(), |
| 301 chromeos::MOUNT_TYPE_DEVICE, |
| 302 chromeos::MountPathOptions()); // Unused. |
241 } | 303 } |
242 } | 304 } |
243 | 305 |
244 void ExtensionFileBrowserEventRouter::OnDiskRemoved( | 306 void ExtensionFileBrowserEventRouter::OnDiskRemoved( |
245 const chromeos::MountLibrary::Disk* disk) { | 307 const chromeos::MountLibrary::Disk* disk) { |
246 VLOG(1) << "Disk removed: " << disk->device_path(); | 308 VLOG(1) << "Disk removed: " << disk->device_path(); |
247 HideDeviceNotification(disk->system_path()); | 309 HideDeviceNotification(disk->system_path()); |
248 MountPointMap::iterator iter = mounted_devices_.find(disk->device_path()); | 310 MountPointMap::iterator iter = mounted_devices_.find(disk->device_path()); |
249 if (iter == mounted_devices_.end()) | 311 if (iter == mounted_devices_.end()) |
250 return; | 312 return; |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 &FileWatcherDelegate::HandleFileWatchOnUIThread, | 430 &FileWatcherDelegate::HandleFileWatchOnUIThread, |
369 local_path, | 431 local_path, |
370 true)); // got_error | 432 true)); // got_error |
371 } | 433 } |
372 | 434 |
373 void | 435 void |
374 ExtensionFileBrowserEventRouter::FileWatcherDelegate::HandleFileWatchOnUIThread( | 436 ExtensionFileBrowserEventRouter::FileWatcherDelegate::HandleFileWatchOnUIThread( |
375 const FilePath& local_path, bool got_error) { | 437 const FilePath& local_path, bool got_error) { |
376 router_->HandleFileWatchNotification(local_path, got_error); | 438 router_->HandleFileWatchNotification(local_path, got_error); |
377 } | 439 } |
OLD | NEW |