| 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/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 mount_info_value->SetString("eventType", "unmount"); | 292 mount_info_value->SetString("eventType", "unmount"); |
| 293 } | 293 } |
| 294 mount_info_value->SetString("status", MountErrorToString(error_code)); | 294 mount_info_value->SetString("status", MountErrorToString(error_code)); |
| 295 mount_info_value->SetString( | 295 mount_info_value->SetString( |
| 296 "mountType", | 296 "mountType", |
| 297 chromeos::disks::DiskMountManager::MountTypeToString( | 297 chromeos::disks::DiskMountManager::MountTypeToString( |
| 298 mount_info.mount_type)); | 298 mount_info.mount_type)); |
| 299 | 299 |
| 300 if (mount_info.mount_type == chromeos::MOUNT_TYPE_ARCHIVE) { | 300 if (mount_info.mount_type == chromeos::MOUNT_TYPE_ARCHIVE) { |
| 301 GURL source_url; | 301 GURL source_url; |
| 302 if (FileManagerUtil::ConvertFileToFileSystemUrl(profile_, | 302 if (file_manager_util::ConvertFileToFileSystemUrl(profile_, |
| 303 FilePath(mount_info.source_path), | 303 FilePath(mount_info.source_path), |
| 304 FileManagerUtil::GetFileBrowserExtensionUrl().GetOrigin(), | 304 file_manager_util::GetFileBrowserExtensionUrl().GetOrigin(), |
| 305 &source_url)) { | 305 &source_url)) { |
| 306 mount_info_value->SetString("sourceUrl", source_url.spec()); | 306 mount_info_value->SetString("sourceUrl", source_url.spec()); |
| 307 } | 307 } |
| 308 } else { | 308 } else { |
| 309 mount_info_value->SetString("sourceUrl", mount_info.source_path); | 309 mount_info_value->SetString("sourceUrl", mount_info.source_path); |
| 310 } | 310 } |
| 311 | 311 |
| 312 FilePath relative_mount_path; | 312 FilePath relative_mount_path; |
| 313 bool relative_mount_path_set = false; | 313 bool relative_mount_path_set = false; |
| 314 | 314 |
| 315 // If there were no error or some special conditions occured, add mountPath | 315 // If there were no error or some special conditions occured, add mountPath |
| 316 // to the event. | 316 // to the event. |
| 317 if (error_code == chromeos::MOUNT_ERROR_NONE || | 317 if (error_code == chromeos::MOUNT_ERROR_NONE || |
| 318 mount_info.mount_condition) { | 318 mount_info.mount_condition) { |
| 319 // Convert mount point path to relative path with the external file system | 319 // Convert mount point path to relative path with the external file system |
| 320 // exposed within File API. | 320 // exposed within File API. |
| 321 if (FileManagerUtil::ConvertFileToRelativeFileSystemPath(profile_, | 321 if (file_manager_util::ConvertFileToRelativeFileSystemPath(profile_, |
| 322 FilePath(mount_info.mount_path), | 322 FilePath(mount_info.mount_path), |
| 323 &relative_mount_path)) { | 323 &relative_mount_path)) { |
| 324 mount_info_value->SetString("mountPath", | 324 mount_info_value->SetString("mountPath", |
| 325 "/" + relative_mount_path.value()); | 325 "/" + relative_mount_path.value()); |
| 326 relative_mount_path_set = true; | 326 relative_mount_path_set = true; |
| 327 } | 327 } |
| 328 } | 328 } |
| 329 | 329 |
| 330 std::string args_json; | 330 std::string args_json; |
| 331 base::JSONWriter::Write(&args, false /* pretty_print */, &args_json); | 331 base::JSONWriter::Write(&args, false /* pretty_print */, &args_json); |
| 332 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( | 332 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( |
| 333 extension_event_names::kOnFileBrowserMountCompleted, args_json, NULL, | 333 extension_event_names::kOnFileBrowserMountCompleted, args_json, NULL, |
| 334 GURL()); | 334 GURL()); |
| 335 | 335 |
| 336 if (relative_mount_path_set && | 336 if (relative_mount_path_set && |
| 337 mount_info.mount_type == chromeos::MOUNT_TYPE_DEVICE && | 337 mount_info.mount_type == chromeos::MOUNT_TYPE_DEVICE && |
| 338 !mount_info.mount_condition && | 338 !mount_info.mount_condition && |
| 339 event == chromeos::disks::DiskMountManager::MOUNTING) { | 339 event == chromeos::disks::DiskMountManager::MOUNTING) { |
| 340 FileManagerUtil::ViewFolder(FilePath(mount_info.mount_path)); | 340 file_manager_util::ViewFolder(FilePath(mount_info.mount_path)); |
| 341 } | 341 } |
| 342 } | 342 } |
| 343 | 343 |
| 344 void ExtensionFileBrowserEventRouter::OnDiskAdded( | 344 void ExtensionFileBrowserEventRouter::OnDiskAdded( |
| 345 const chromeos::disks::DiskMountManager::Disk* disk) { | 345 const chromeos::disks::DiskMountManager::Disk* disk) { |
| 346 VLOG(1) << "Disk added: " << disk->device_path(); | 346 VLOG(1) << "Disk added: " << disk->device_path(); |
| 347 if (disk->device_path().empty()) { | 347 if (disk->device_path().empty()) { |
| 348 VLOG(1) << "Empty system path for " << disk->device_path(); | 348 VLOG(1) << "Empty system path for " << disk->device_path(); |
| 349 return; | 349 return; |
| 350 } | 350 } |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 508 | 508 |
| 509 const FilePath& | 509 const FilePath& |
| 510 ExtensionFileBrowserEventRouter::FileWatcherExtensions::GetVirtualPath() const { | 510 ExtensionFileBrowserEventRouter::FileWatcherExtensions::GetVirtualPath() const { |
| 511 return virtual_path; | 511 return virtual_path; |
| 512 } | 512 } |
| 513 | 513 |
| 514 bool ExtensionFileBrowserEventRouter::FileWatcherExtensions::Watch | 514 bool ExtensionFileBrowserEventRouter::FileWatcherExtensions::Watch |
| 515 (const FilePath& path, FileWatcherDelegate* delegate) { | 515 (const FilePath& path, FileWatcherDelegate* delegate) { |
| 516 return file_watcher->Watch(path, delegate); | 516 return file_watcher->Watch(path, delegate); |
| 517 } | 517 } |
| OLD | NEW |