| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_manager/private_api_mount.h" | 5 #include "chrome/browser/chromeos/extensions/file_manager/private_api_mount.h" |
| 6 | 6 |
| 7 #include "base/format_macros.h" | 7 #include "base/format_macros.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 #include "chrome/browser/chromeos/drive/drive_integration_service.h" | 9 #include "chrome/browser/chromeos/drive/drive_integration_service.h" |
| 10 #include "chrome/browser/chromeos/drive/file_system_interface.h" | 10 #include "chrome/browser/chromeos/drive/file_system_interface.h" |
| 11 #include "chrome/browser/chromeos/drive/file_system_util.h" | 11 #include "chrome/browser/chromeos/drive/file_system_util.h" |
| 12 #include "chrome/browser/chromeos/drive/logging.h" | 12 #include "chrome/browser/chromeos/drive/logging.h" |
| 13 #include "chrome/browser/chromeos/extensions/file_manager/event_router.h" | 13 #include "chrome/browser/chromeos/extensions/file_manager/event_router.h" |
| 14 #include "chrome/browser/chromeos/extensions/file_manager/file_browser_private_a
pi.h" | 14 #include "chrome/browser/chromeos/extensions/file_manager/file_browser_private_a
pi.h" |
| 15 #include "chrome/browser/chromeos/extensions/file_manager/fileapi_util.h" | 15 #include "chrome/browser/chromeos/extensions/file_manager/fileapi_util.h" |
| 16 #include "chrome/browser/chromeos/extensions/file_manager/private_api_util.h" | 16 #include "chrome/browser/chromeos/extensions/file_manager/private_api_util.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chromeos/disks/disk_mount_manager.h" | 18 #include "chromeos/disks/disk_mount_manager.h" |
| 19 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
| 20 #include "ui/shell_dialogs/selected_file_info.h" | 20 #include "ui/shell_dialogs/selected_file_info.h" |
| 21 | 21 |
| 22 using chromeos::disks::DiskMountManager; | 22 using chromeos::disks::DiskMountManager; |
| 23 using content::BrowserThread; | 23 using content::BrowserThread; |
| 24 | 24 |
| 25 namespace file_manager { | 25 namespace extensions { |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 // Creates a dictionary describing the mount point of |mount_point_info|. | 28 // Creates a dictionary describing the mount point of |mount_point_info|. |
| 29 base::DictionaryValue* CreateValueFromMountPoint( | 29 base::DictionaryValue* CreateValueFromMountPoint( |
| 30 Profile* profile, | 30 Profile* profile, |
| 31 const DiskMountManager::MountPointInfo& mount_point_info, | 31 const DiskMountManager::MountPointInfo& mount_point_info, |
| 32 const std::string& extension_id) { | 32 const std::string& extension_id) { |
| 33 | 33 |
| 34 base::DictionaryValue *mount_info = new base::DictionaryValue(); | 34 base::DictionaryValue *mount_info = new base::DictionaryValue(); |
| 35 | 35 |
| 36 mount_info->SetString("mountType", | 36 mount_info->SetString("mountType", |
| 37 DiskMountManager::MountTypeToString( | 37 DiskMountManager::MountTypeToString( |
| 38 mount_point_info.mount_type)); | 38 mount_point_info.mount_type)); |
| 39 mount_info->SetString("sourcePath", mount_point_info.source_path); | 39 mount_info->SetString("sourcePath", mount_point_info.source_path); |
| 40 | 40 |
| 41 base::FilePath relative_mount_path; | 41 base::FilePath relative_mount_path; |
| 42 // Convert mount point path to relative path with the external file system | 42 // Convert mount point path to relative path with the external file system |
| 43 // exposed within File API. | 43 // exposed within File API. |
| 44 if (util::ConvertAbsoluteFilePathToRelativeFileSystemPath( | 44 if (file_manager::util::ConvertAbsoluteFilePathToRelativeFileSystemPath( |
| 45 profile, | 45 profile, |
| 46 extension_id, | 46 extension_id, |
| 47 base::FilePath(mount_point_info.mount_path), | 47 base::FilePath(mount_point_info.mount_path), |
| 48 &relative_mount_path)) { | 48 &relative_mount_path)) { |
| 49 mount_info->SetString("mountPath", relative_mount_path.value()); | 49 mount_info->SetString("mountPath", relative_mount_path.value()); |
| 50 } | 50 } |
| 51 | 51 |
| 52 mount_info->SetString("mountCondition", | 52 mount_info->SetString("mountCondition", |
| 53 DiskMountManager::MountConditionToString( | 53 DiskMountManager::MountConditionToString( |
| 54 mount_point_info.mount_condition)); | 54 mount_point_info.mount_condition)); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 DiskMountManager::MountTypeFromString(mount_type_str); | 106 DiskMountManager::MountTypeFromString(mount_type_str); |
| 107 switch (mount_type) { | 107 switch (mount_type) { |
| 108 case chromeos::MOUNT_TYPE_INVALID: { | 108 case chromeos::MOUNT_TYPE_INVALID: { |
| 109 error_ = "Invalid mount type"; | 109 error_ = "Invalid mount type"; |
| 110 SendResponse(false); | 110 SendResponse(false); |
| 111 break; | 111 break; |
| 112 } | 112 } |
| 113 case chromeos::MOUNT_TYPE_GOOGLE_DRIVE: { | 113 case chromeos::MOUNT_TYPE_GOOGLE_DRIVE: { |
| 114 // Dispatch fake 'mounted' event because JS code depends on it. | 114 // Dispatch fake 'mounted' event because JS code depends on it. |
| 115 // TODO(hashimoto): Remove this redanduncy. | 115 // TODO(hashimoto): Remove this redanduncy. |
| 116 FileBrowserPrivateAPI::Get(profile_)->event_router()-> | 116 file_manager::FileBrowserPrivateAPI::Get(profile_)->event_router()-> |
| 117 OnFileSystemMounted(); | 117 OnFileSystemMounted(); |
| 118 | 118 |
| 119 // Pass back the drive mount point path as source path. | 119 // Pass back the drive mount point path as source path. |
| 120 const std::string& drive_path = | 120 const std::string& drive_path = |
| 121 drive::util::GetDriveMountPointPathAsString(); | 121 drive::util::GetDriveMountPointPathAsString(); |
| 122 SetResult(new base::StringValue(drive_path)); | 122 SetResult(new base::StringValue(drive_path)); |
| 123 SendResponse(true); | 123 SendResponse(true); |
| 124 break; | 124 break; |
| 125 } | 125 } |
| 126 default: { | 126 default: { |
| 127 const base::FilePath path = util::GetLocalPathFromURL( | 127 const base::FilePath path = file_manager::util::GetLocalPathFromURL( |
| 128 render_view_host(), profile(), GURL(file_url)); | 128 render_view_host(), profile(), GURL(file_url)); |
| 129 | 129 |
| 130 if (path.empty()) { | 130 if (path.empty()) { |
| 131 SendResponse(false); | 131 SendResponse(false); |
| 132 break; | 132 break; |
| 133 } | 133 } |
| 134 | 134 |
| 135 const base::FilePath::StringType display_name = path.BaseName().value(); | 135 const base::FilePath::StringType display_name = path.BaseName().value(); |
| 136 | 136 |
| 137 // Check if the source path is under Drive cache directory. | 137 // Check if the source path is under Drive cache directory. |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 | 199 |
| 200 drive::util::Log(logging::LOG_INFO, | 200 drive::util::Log(logging::LOG_INFO, |
| 201 "%s[%d] called. (mount_path: '%s')", | 201 "%s[%d] called. (mount_path: '%s')", |
| 202 name().c_str(), | 202 name().c_str(), |
| 203 request_id(), | 203 request_id(), |
| 204 mount_path.c_str()); | 204 mount_path.c_str()); |
| 205 set_log_on_completion(true); | 205 set_log_on_completion(true); |
| 206 | 206 |
| 207 std::vector<GURL> file_paths; | 207 std::vector<GURL> file_paths; |
| 208 file_paths.push_back(GURL(mount_path)); | 208 file_paths.push_back(GURL(mount_path)); |
| 209 util::GetSelectedFileInfo( | 209 file_manager::util::GetSelectedFileInfo( |
| 210 render_view_host(), | 210 render_view_host(), |
| 211 profile(), | 211 profile(), |
| 212 file_paths, | 212 file_paths, |
| 213 util::NEED_LOCAL_PATH_FOR_OPENING, | 213 file_manager::util::NEED_LOCAL_PATH_FOR_OPENING, |
| 214 base::Bind(&RemoveMountFunction::GetSelectedFileInfoResponse, this)); | 214 base::Bind(&RemoveMountFunction::GetSelectedFileInfoResponse, this)); |
| 215 return true; | 215 return true; |
| 216 } | 216 } |
| 217 | 217 |
| 218 void RemoveMountFunction::GetSelectedFileInfoResponse( | 218 void RemoveMountFunction::GetSelectedFileInfoResponse( |
| 219 const std::vector<ui::SelectedFileInfo>& files) { | 219 const std::vector<ui::SelectedFileInfo>& files) { |
| 220 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 220 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 221 | 221 |
| 222 if (files.size() != 1) { | 222 if (files.size() != 1) { |
| 223 SendResponse(false); | 223 SendResponse(false); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 "%s[%d] succeeded. (results: '%s', %" PRIuS " mount points)", | 276 "%s[%d] succeeded. (results: '%s', %" PRIuS " mount points)", |
| 277 name().c_str(), | 277 name().c_str(), |
| 278 request_id(), | 278 request_id(), |
| 279 log_string.c_str(), | 279 log_string.c_str(), |
| 280 mount_points.size()); | 280 mount_points.size()); |
| 281 | 281 |
| 282 SendResponse(true); | 282 SendResponse(true); |
| 283 return true; | 283 return true; |
| 284 } | 284 } |
| 285 | 285 |
| 286 } // namespace file_manager | 286 } // namespace extensions |
| OLD | NEW |