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

Side by Side Diff: chrome/browser/chromeos/extensions/file_manager/private_api_mount.cc

Issue 23658009: Replace mountType by volumeType on fileBrowserPrivate APIs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 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/chromeos/extensions/file_manager/volume_manager.h" 17 #include "chrome/browser/chromeos/extensions/file_manager/volume_manager.h"
18 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
19 #include "chromeos/disks/disk_mount_manager.h" 19 #include "chromeos/disks/disk_mount_manager.h"
20 #include "content/public/browser/browser_thread.h" 20 #include "content/public/browser/browser_thread.h"
21 #include "ui/shell_dialogs/selected_file_info.h" 21 #include "ui/shell_dialogs/selected_file_info.h"
22 22
23 using chromeos::disks::DiskMountManager; 23 using chromeos::disks::DiskMountManager;
24 using content::BrowserThread; 24 using content::BrowserThread;
25 25
26 namespace extensions { 26 namespace extensions {
27 namespace { 27 namespace {
28 28
29 // Returns string representaion of VolumeType.
30 std::string VolumeTypeToString(file_manager::VolumeType type) {
31 switch (type) {
32 case file_manager::VOLUME_TYPE_GOOGLE_DRIVE:
33 return "drive";
34 case file_manager::VOLUME_TYPE_DOWNLOADS_DIRECTORY:
35 // Return empty string here for backword compatibility.
36 // TODO(hidehiko): Fix this to return "downloads".
37 return "";
38 case file_manager::VOLUME_TYPE_REMOVABLE_DISK_PARTITION:
39 return "device";
40 case file_manager::VOLUME_TYPE_MOUNTED_ARCHIVE_FILE:
41 return "file";
42 }
43
44 NOTREACHED();
45 return "";
46 }
47
48 // Returns the Value of the |volume_info|. 29 // Returns the Value of the |volume_info|.
49 base::Value* CreateValueFromVolumeInfo( 30 base::Value* CreateValueFromVolumeInfo(
50 const file_manager::VolumeInfo& volume_info, 31 const file_manager::VolumeInfo& volume_info,
51 Profile* profile, 32 Profile* profile,
52 const std::string& extension_id) { 33 const std::string& extension_id) {
53 base::DictionaryValue* result = new base::DictionaryValue; 34 base::DictionaryValue* result = new base::DictionaryValue;
54 std::string mount_type = VolumeTypeToString(volume_info.type); 35 std::string volume_type =
55 if (!mount_type.empty()) 36 file_manager::util::VolumeTypeToStringEnum(volume_info.type);
56 result->SetString("mountType", mount_type); 37 if (!volume_type.empty())
38 result->SetString("volumeType", volume_type);
57 39
58 if (!volume_info.source_path.empty()) 40 if (!volume_info.source_path.empty())
59 result->SetString("sourcePath", volume_info.source_path.value()); 41 result->SetString("sourcePath", volume_info.source_path.value());
60 42
61 // Convert mount point path to relative path with the external file system 43 // Convert mount point path to relative path with the external file system
62 // exposed within File API. 44 // exposed within File API.
63 base::FilePath relative_path; 45 base::FilePath relative_path;
64 if (file_manager::util::ConvertAbsoluteFilePathToRelativeFileSystemPath( 46 if (file_manager::util::ConvertAbsoluteFilePathToRelativeFileSystemPath(
65 profile, extension_id, volume_info.mount_path, &relative_path)) 47 profile, extension_id, volume_info.mount_path, &relative_path))
66 result->SetString("mountPath", relative_path.value()); 48 result->SetString("mountPath", relative_path.value());
(...skipping 13 matching lines...) Expand all
80 } 62 }
81 63
82 bool FileBrowserPrivateAddMountFunction::RunImpl() { 64 bool FileBrowserPrivateAddMountFunction::RunImpl() {
83 // The third argument is simply ignored. 65 // The third argument is simply ignored.
84 if (args_->GetSize() != 2 && args_->GetSize() != 3) { 66 if (args_->GetSize() != 2 && args_->GetSize() != 3) {
85 error_ = "Invalid argument count"; 67 error_ = "Invalid argument count";
86 return false; 68 return false;
87 } 69 }
88 70
89 std::string file_url; 71 std::string file_url;
90 if (!args_->GetString(0, &file_url)) { 72 if (!args_->GetString(0, &file_url))
91 return false; 73 return false;
92 }
93 74
94 std::string mount_type_str; 75 std::string mount_type;
95 if (!args_->GetString(1, &mount_type_str)) { 76 if (!args_->GetString(1, &mount_type))
96 return false; 77 return false;
97 }
98 78
99 drive::util::Log(logging::LOG_INFO, 79 drive::util::Log(logging::LOG_INFO,
100 "%s[%d] called. (source: '%s', type:'%s')", 80 "%s[%d] called. (source: '%s', type:'%s')",
101 name().c_str(), 81 name().c_str(),
102 request_id(), 82 request_id(),
103 file_url.empty() ? "(none)" : file_url.c_str(), 83 file_url.empty() ? "(none)" : file_url.c_str(),
104 mount_type_str.c_str()); 84 mount_type.c_str());
105 set_log_on_completion(true); 85 set_log_on_completion(true);
106 86
107 // Set default return source path to the empty string. 87 if (mount_type == "drive") {
108 SetResult(new base::StringValue("")); 88 // Dispatch fake 'mounted' event because JS code depends on it.
89 // TODO(hashimoto): Remove this redanduncy.
90 file_manager::FileBrowserPrivateAPI::Get(profile_)->event_router()->
91 OnFileSystemMounted();
109 92
110 chromeos::MountType mount_type = 93 // Pass back the drive mount point path as source path.
111 DiskMountManager::MountTypeFromString(mount_type_str); 94 const std::string& drive_path =
112 switch (mount_type) { 95 drive::util::GetDriveMountPointPathAsString();
113 case chromeos::MOUNT_TYPE_INVALID: { 96 SetResult(new base::StringValue(drive_path));
114 error_ = "Invalid mount type"; 97 SendResponse(true);
115 SendResponse(false); 98 } else if (mount_type == "archive") {
116 break; 99 const base::FilePath path = file_manager::util::GetLocalPathFromURL(
100 render_view_host(), profile(), GURL(file_url));
101
102 if (path.empty())
103 return false;
104
105 const base::FilePath::StringType display_name = path.BaseName().value();
106
107 // Check if the source path is under Drive cache directory.
108 if (drive::util::IsUnderDriveMountPoint(path)) {
109 drive::DriveIntegrationService* integration_service =
110 drive::DriveIntegrationServiceFactory::GetForProfile(profile_);
111 drive::FileSystemInterface* file_system =
112 integration_service ? integration_service->file_system() : NULL;
113 if (!file_system)
114 return false;
115
116 file_system->MarkCacheFileAsMounted(
117 drive::util::ExtractDrivePath(path),
118 base::Bind(&FileBrowserPrivateAddMountFunction::OnMountedStateSet,
119 this, display_name));
120 } else {
121 OnMountedStateSet(display_name, drive::FILE_ERROR_OK, path);
117 } 122 }
118 case chromeos::MOUNT_TYPE_GOOGLE_DRIVE: { 123 } else {
119 // Dispatch fake 'mounted' event because JS code depends on it. 124 error_ = "Invalid mount type";
120 // TODO(hashimoto): Remove this redanduncy. 125 return false;
121 file_manager::FileBrowserPrivateAPI::Get(profile_)->event_router()->
122 OnFileSystemMounted();
123
124 // Pass back the drive mount point path as source path.
125 const std::string& drive_path =
126 drive::util::GetDriveMountPointPathAsString();
127 SetResult(new base::StringValue(drive_path));
128 SendResponse(true);
129 break;
130 }
131 default: {
132 const base::FilePath path = file_manager::util::GetLocalPathFromURL(
133 render_view_host(), profile(), GURL(file_url));
134
135 if (path.empty()) {
136 SendResponse(false);
137 break;
138 }
139
140 const base::FilePath::StringType display_name = path.BaseName().value();
141
142 // Check if the source path is under Drive cache directory.
143 if (drive::util::IsUnderDriveMountPoint(path)) {
144 drive::DriveIntegrationService* integration_service =
145 drive::DriveIntegrationServiceFactory::GetForProfile(profile_);
146 drive::FileSystemInterface* file_system =
147 integration_service ? integration_service->file_system() : NULL;
148 if (!file_system) {
149 SendResponse(false);
150 break;
151 }
152 file_system->MarkCacheFileAsMounted(
153 drive::util::ExtractDrivePath(path),
154 base::Bind(&FileBrowserPrivateAddMountFunction::OnMountedStateSet,
155 this, mount_type_str, display_name));
156 } else {
157 OnMountedStateSet(mount_type_str, display_name,
158 drive::FILE_ERROR_OK, path);
159 }
160 break;
161 }
162 } 126 }
163 127
164 return true; 128 return true;
165 } 129 }
166 130
167 void FileBrowserPrivateAddMountFunction::OnMountedStateSet( 131 void FileBrowserPrivateAddMountFunction::OnMountedStateSet(
168 const std::string& mount_type,
169 const base::FilePath::StringType& file_name, 132 const base::FilePath::StringType& file_name,
170 drive::FileError error, 133 drive::FileError error,
171 const base::FilePath& file_path) { 134 const base::FilePath& file_path) {
172 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 135 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
173 136
174 if (error != drive::FILE_ERROR_OK) { 137 if (error != drive::FILE_ERROR_OK) {
175 SendResponse(false); 138 SendResponse(false);
176 return; 139 return;
177 } 140 }
178 141
179 DiskMountManager* disk_mount_manager = DiskMountManager::GetInstance(); 142 DiskMountManager* disk_mount_manager = DiskMountManager::GetInstance();
180 // Pass back the actual source path of the mount point. 143 // Pass back the actual source path of the mount point.
181 SetResult(new base::StringValue(file_path.value())); 144 SetResult(new base::StringValue(file_path.value()));
182 SendResponse(true); 145 SendResponse(true);
183 // MountPath() takes a std::string. 146 // MountPath() takes a std::string.
184 disk_mount_manager->MountPath( 147 disk_mount_manager->MountPath(
185 file_path.AsUTF8Unsafe(), base::FilePath(file_name).Extension(), 148 file_path.AsUTF8Unsafe(), base::FilePath(file_name).Extension(),
186 file_name, DiskMountManager::MountTypeFromString(mount_type)); 149 file_name, chromeos::MOUNT_TYPE_ARCHIVE);
187 } 150 }
188 151
189 FileBrowserPrivateRemoveMountFunction::FileBrowserPrivateRemoveMountFunction() { 152 FileBrowserPrivateRemoveMountFunction::FileBrowserPrivateRemoveMountFunction() {
190 } 153 }
191 154
192 FileBrowserPrivateRemoveMountFunction:: 155 FileBrowserPrivateRemoveMountFunction::
193 ~FileBrowserPrivateRemoveMountFunction() { 156 ~FileBrowserPrivateRemoveMountFunction() {
194 } 157 }
195 158
196 bool FileBrowserPrivateRemoveMountFunction::RunImpl() { 159 bool FileBrowserPrivateRemoveMountFunction::RunImpl() {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 logging::LOG_INFO, 233 logging::LOG_INFO,
271 "%s[%d] succeeded. (results: '[%s]', %" PRIuS " mount points)", 234 "%s[%d] succeeded. (results: '[%s]', %" PRIuS " mount points)",
272 name().c_str(), request_id(), log_string.c_str(), result->GetSize()); 235 name().c_str(), request_id(), log_string.c_str(), result->GetSize());
273 236
274 SetResult(result); 237 SetResult(result);
275 SendResponse(true); 238 SendResponse(true);
276 return true; 239 return true;
277 } 240 }
278 241
279 } // namespace extensions 242 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698