| 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 DiskMountManager::MountTypeFromString(mount_type_str); | 96 DiskMountManager::MountTypeFromString(mount_type_str); |
| 97 switch (mount_type) { | 97 switch (mount_type) { |
| 98 case chromeos::MOUNT_TYPE_INVALID: { | 98 case chromeos::MOUNT_TYPE_INVALID: { |
| 99 error_ = "Invalid mount type"; | 99 error_ = "Invalid mount type"; |
| 100 SendResponse(false); | 100 SendResponse(false); |
| 101 break; | 101 break; |
| 102 } | 102 } |
| 103 case chromeos::MOUNT_TYPE_GOOGLE_DRIVE: { | 103 case chromeos::MOUNT_TYPE_GOOGLE_DRIVE: { |
| 104 // Dispatch fake 'mounted' event because JS code depends on it. | 104 // Dispatch fake 'mounted' event because JS code depends on it. |
| 105 // TODO(hashimoto): Remove this redanduncy. | 105 // TODO(hashimoto): Remove this redanduncy. |
| 106 FileBrowserPrivateAPI::Get(profile_)->event_router()-> | 106 file_manager::FileBrowserPrivateAPI::Get(profile_)->event_router()-> |
| 107 OnFileSystemMounted(); | 107 OnFileSystemMounted(); |
| 108 | 108 |
| 109 // Pass back the drive mount point path as source path. | 109 // Pass back the drive mount point path as source path. |
| 110 const std::string& drive_path = | 110 const std::string& drive_path = |
| 111 drive::util::GetDriveMountPointPathAsString(); | 111 drive::util::GetDriveMountPointPathAsString(); |
| 112 SetResult(new base::StringValue(drive_path)); | 112 SetResult(new base::StringValue(drive_path)); |
| 113 SendResponse(true); | 113 SendResponse(true); |
| 114 break; | 114 break; |
| 115 } | 115 } |
| 116 default: { | 116 default: { |
| 117 const base::FilePath path = util::GetLocalPathFromURL( | 117 const base::FilePath path = file_manager::util::GetLocalPathFromURL( |
| 118 render_view_host(), profile(), GURL(file_url)); | 118 render_view_host(), profile(), GURL(file_url)); |
| 119 | 119 |
| 120 if (path.empty()) { | 120 if (path.empty()) { |
| 121 SendResponse(false); | 121 SendResponse(false); |
| 122 break; | 122 break; |
| 123 } | 123 } |
| 124 | 124 |
| 125 const base::FilePath::StringType display_name = path.BaseName().value(); | 125 const base::FilePath::StringType display_name = path.BaseName().value(); |
| 126 | 126 |
| 127 // Check if the source path is under Drive cache directory. | 127 // Check if the source path is under Drive cache directory. |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 | 189 |
| 190 drive::util::Log(logging::LOG_INFO, | 190 drive::util::Log(logging::LOG_INFO, |
| 191 "%s[%d] called. (mount_path: '%s')", | 191 "%s[%d] called. (mount_path: '%s')", |
| 192 name().c_str(), | 192 name().c_str(), |
| 193 request_id(), | 193 request_id(), |
| 194 mount_path.c_str()); | 194 mount_path.c_str()); |
| 195 set_log_on_completion(true); | 195 set_log_on_completion(true); |
| 196 | 196 |
| 197 std::vector<GURL> file_paths; | 197 std::vector<GURL> file_paths; |
| 198 file_paths.push_back(GURL(mount_path)); | 198 file_paths.push_back(GURL(mount_path)); |
| 199 util::GetSelectedFileInfo( | 199 file_manager::util::GetSelectedFileInfo( |
| 200 render_view_host(), | 200 render_view_host(), |
| 201 profile(), | 201 profile(), |
| 202 file_paths, | 202 file_paths, |
| 203 util::NEED_LOCAL_PATH_FOR_OPENING, | 203 file_manager::util::NEED_LOCAL_PATH_FOR_OPENING, |
| 204 base::Bind(&RemoveMountFunction::GetSelectedFileInfoResponse, this)); | 204 base::Bind(&RemoveMountFunction::GetSelectedFileInfoResponse, this)); |
| 205 return true; | 205 return true; |
| 206 } | 206 } |
| 207 | 207 |
| 208 void RemoveMountFunction::GetSelectedFileInfoResponse( | 208 void RemoveMountFunction::GetSelectedFileInfoResponse( |
| 209 const std::vector<ui::SelectedFileInfo>& files) { | 209 const std::vector<ui::SelectedFileInfo>& files) { |
| 210 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 210 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 211 | 211 |
| 212 if (files.size() != 1) { | 212 if (files.size() != 1) { |
| 213 SendResponse(false); | 213 SendResponse(false); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 "%s[%d] succeeded. (results: '%s', %" PRIuS " mount points)", | 260 "%s[%d] succeeded. (results: '%s', %" PRIuS " mount points)", |
| 261 name().c_str(), | 261 name().c_str(), |
| 262 request_id(), | 262 request_id(), |
| 263 log_string.c_str(), | 263 log_string.c_str(), |
| 264 mount_points.size()); | 264 mount_points.size()); |
| 265 | 265 |
| 266 SendResponse(true); | 266 SendResponse(true); |
| 267 return true; | 267 return true; |
| 268 } | 268 } |
| 269 | 269 |
| 270 } // namespace file_manager | 270 } // namespace extensions |
| OLD | NEW |