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

Side by Side Diff: chrome/browser/extensions/extension_file_browser_private_api.cc

Issue 8497007: Switch from MountLibrary to CrosDisksLibrary (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased on ToT Created 9 years, 1 month 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 (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/extensions/extension_file_browser_private_api.h" 5 #include "chrome/browser/extensions/extension_file_browser_private_api.h"
6 6
7 #include "base/base64.h" 7 #include "base/base64.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/json/json_writer.h" 10 #include "base/json/json_writer.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 #include "ui/base/l10n/l10n_util.h" 43 #include "ui/base/l10n/l10n_util.h"
44 #include "webkit/fileapi/file_system_context.h" 44 #include "webkit/fileapi/file_system_context.h"
45 #include "webkit/fileapi/file_system_file_util.h" 45 #include "webkit/fileapi/file_system_file_util.h"
46 #include "webkit/fileapi/file_system_mount_point_provider.h" 46 #include "webkit/fileapi/file_system_mount_point_provider.h"
47 #include "webkit/fileapi/file_system_operation.h" 47 #include "webkit/fileapi/file_system_operation.h"
48 #include "webkit/fileapi/file_system_operation_context.h" 48 #include "webkit/fileapi/file_system_operation_context.h"
49 #include "webkit/fileapi/file_system_path_manager.h" 49 #include "webkit/fileapi/file_system_path_manager.h"
50 #include "webkit/fileapi/file_system_types.h" 50 #include "webkit/fileapi/file_system_types.h"
51 #include "webkit/fileapi/file_system_util.h" 51 #include "webkit/fileapi/file_system_util.h"
52 52
53 #ifdef OS_CHROMEOS 53 using content::BrowserThread;
54 #include "chrome/browser/chromeos/cros/cros_library.h"
55 #endif
56 54
57 using content::BrowserThread; 55 namespace {
58 56
59 // Error messages. 57 // Error messages.
60 const char kFileError[] = "File error %d"; 58 const char kFileError[] = "File error %d";
61 const char kInvalidFileUrl[] = "Invalid file URL"; 59 const char kInvalidFileUrl[] = "Invalid file URL";
62 const char kVolumeDevicePathNotFound[] = "Device path not found"; 60 const char kVolumeDevicePathNotFound[] = "Device path not found";
63 61
64 #ifdef OS_CHROMEOS 62 #ifdef OS_CHROMEOS
65 // Volume type strings. 63 // Volume type strings.
66 const std::string kVolumeTypeFlash = "flash"; 64 const std::string kVolumeTypeFlash = "flash";
67 const std::string kVolumeTypeOptical = "optical"; 65 const std::string kVolumeTypeOptical = "optical";
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 DictionaryPrefUpdate prefs_usage_update(profile->GetPrefs(), 258 DictionaryPrefUpdate prefs_usage_update(profile->GetPrefs(),
261 prefs::kLastUsedFileBrowserHandlers); 259 prefs::kLastUsedFileBrowserHandlers);
262 prefs_usage_update->SetWithoutPathExpansion(task_id, 260 prefs_usage_update->SetWithoutPathExpansion(task_id,
263 new base::FundamentalValue( 261 new base::FundamentalValue(
264 static_cast<int>(base::Time::Now().ToInternalValue()/ 262 static_cast<int>(base::Time::Now().ToInternalValue()/
265 base::Time::kMicrosecondsPerSecond))); 263 base::Time::kMicrosecondsPerSecond)));
266 } 264 }
267 265
268 #ifdef OS_CHROMEOS 266 #ifdef OS_CHROMEOS
269 base::DictionaryValue* MountPointToValue(Profile* profile, 267 base::DictionaryValue* MountPointToValue(Profile* profile,
270 const chromeos::MountLibrary::MountPointInfo& mount_point_info) { 268 const chromeos::disks::DiskMountManager::MountPointInfo& mount_point_info) {
271 269
272 base::DictionaryValue *mount_info = new base::DictionaryValue(); 270 base::DictionaryValue *mount_info = new base::DictionaryValue();
273 271
274 mount_info->SetString("mountType", 272 mount_info->SetString("mountType",
275 chromeos::MountLibrary::MountTypeToString(mount_point_info.mount_type)); 273 chromeos::disks::DiskMountManager::MountTypeToString(
274 mount_point_info.mount_type));
276 275
277 if (mount_point_info.mount_type == chromeos::MOUNT_TYPE_ARCHIVE) { 276 if (mount_point_info.mount_type == chromeos::MOUNT_TYPE_ARCHIVE) {
278 GURL source_url; 277 GURL source_url;
279 if (FileManagerUtil::ConvertFileToFileSystemUrl(profile, 278 if (FileManagerUtil::ConvertFileToFileSystemUrl(profile,
280 FilePath(mount_point_info.source_path), 279 FilePath(mount_point_info.source_path),
281 FileManagerUtil::GetFileBrowserExtensionUrl().GetOrigin(), 280 FileManagerUtil::GetFileBrowserExtensionUrl().GetOrigin(),
282 &source_url)) { 281 &source_url)) {
283 mount_info->SetString("sourceUrl", source_url.spec()); 282 mount_info->SetString("sourceUrl", source_url.spec());
284 } 283 }
285 } else { 284 } else {
286 mount_info->SetString("sourceUrl", mount_point_info.source_path); 285 mount_info->SetString("sourceUrl", mount_point_info.source_path);
287 } 286 }
288 287
289 FilePath relative_mount_path; 288 FilePath relative_mount_path;
290 // Convert mount point path to relative path with the external file system 289 // Convert mount point path to relative path with the external file system
291 // exposed within File API. 290 // exposed within File API.
292 if (FileManagerUtil::ConvertFileToRelativeFileSystemPath(profile, 291 if (FileManagerUtil::ConvertFileToRelativeFileSystemPath(profile,
293 FilePath(mount_point_info.mount_path), 292 FilePath(mount_point_info.mount_path),
294 &relative_mount_path)) { 293 &relative_mount_path)) {
295 mount_info->SetString("mountPath", relative_mount_path.value()); 294 mount_info->SetString("mountPath", relative_mount_path.value());
296 } 295 }
297 296
298 mount_info->SetString("mountCondition", 297 mount_info->SetString("mountCondition",
299 chromeos::MountLibrary::MountConditionToString( 298 chromeos::disks::DiskMountManager::MountConditionToString(
300 mount_point_info.mount_condition)); 299 mount_point_info.mount_condition));
301 300
302 return mount_info; 301 return mount_info;
303 } 302 }
304 #endif 303 #endif
305 304
305 } // namespace
306 306
307 class LocalFileSystemCallbackDispatcher 307 class RequestLocalFileSystemFunction::LocalFileSystemCallbackDispatcher
308 : public fileapi::FileSystemCallbackDispatcher { 308 : public fileapi::FileSystemCallbackDispatcher {
309 public: 309 public:
310 explicit LocalFileSystemCallbackDispatcher( 310 explicit LocalFileSystemCallbackDispatcher(
311 RequestLocalFileSystemFunction* function, 311 RequestLocalFileSystemFunction* function,
312 Profile* profile, 312 Profile* profile,
313 int child_id, 313 int child_id,
314 scoped_refptr<const Extension> extension) 314 scoped_refptr<const Extension> extension)
315 : function_(function), 315 : function_(function),
316 profile_(profile), 316 profile_(profile),
317 child_id_(child_id), 317 child_id_(child_id),
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
615 task->SetString("iconUrl", icon.spec()); 615 task->SetString("iconUrl", icon.spec());
616 result_list->Append(task); 616 result_list->Append(task);
617 } 617 }
618 618
619 // TODO(zelidrag, serya): Add intent content tasks to result_list once we 619 // TODO(zelidrag, serya): Add intent content tasks to result_list once we
620 // implement that API. 620 // implement that API.
621 SendResponse(true); 621 SendResponse(true);
622 return true; 622 return true;
623 } 623 }
624 624
625 class ExecuteTasksFileSystemCallbackDispatcher 625 class ExecuteTasksFileBrowserFunction::ExecuteTasksFileSystemCallbackDispatcher
626 : public fileapi::FileSystemCallbackDispatcher { 626 : public fileapi::FileSystemCallbackDispatcher {
627 public: 627 public:
628 explicit ExecuteTasksFileSystemCallbackDispatcher( 628 explicit ExecuteTasksFileSystemCallbackDispatcher(
629 ExecuteTasksFileBrowserFunction* function, 629 ExecuteTasksFileBrowserFunction* function,
630 Profile* profile, 630 Profile* profile,
631 int child_id, 631 int child_id,
632 const GURL& source_url, 632 const GURL& source_url,
633 scoped_refptr<const Extension> extension, 633 scoped_refptr<const Extension> extension,
634 const std::string task_id, 634 const std::string task_id,
635 const std::vector<GURL>& file_urls) 635 const std::vector<GURL>& file_urls)
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
985 } 985 }
986 TabContents* tab_contents = 986 TabContents* tab_contents =
987 dispatcher()->delegate()->GetAssociatedTabContents(); 987 dispatcher()->delegate()->GetAssociatedTabContents();
988 if (!tab_contents) { 988 if (!tab_contents) {
989 LOG(WARNING) << "No associated tab contents"; 989 LOG(WARNING) << "No associated tab contents";
990 return 0; 990 return 0;
991 } 991 }
992 return ExtensionTabUtil::GetTabId(tab_contents); 992 return ExtensionTabUtil::GetTabId(tab_contents);
993 } 993 }
994 994
995 void FileBrowserFunction::GetLocalPathsOnFileThreadAndRunCallbackOnUIThread(
996 const UrlList& file_urls,
997 GetLocalPathsCallback callback) {
998 BrowserThread::PostTask(
999 BrowserThread::FILE, FROM_HERE,
1000 base::Bind(
1001 &FileBrowserFunction::GetLocalPathsOnFileThread,
1002 this,
1003 file_urls, callback));
1004 }
1005
995 // GetFileSystemRootPathOnFileThread can only be called from the file thread, 1006 // GetFileSystemRootPathOnFileThread can only be called from the file thread,
996 // so here we are. This function takes a vector of virtual paths, converts 1007 // so here we are. This function takes a vector of virtual paths, converts
997 // them to local paths and calls GetLocalPathsResponseOnUIThread with the 1008 // them to local paths and calls |callback| with the result vector, on the UI
998 // result vector, on the UI thread. 1009 // thread.
999 void FileBrowserFunction::GetLocalPathsOnFileThread(const UrlList& file_urls, 1010 void FileBrowserFunction::GetLocalPathsOnFileThread(
1000 void* context) { 1011 const UrlList& file_urls,
1012 GetLocalPathsCallback callback) {
1001 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 1013 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
1002 FilePathList selected_files; 1014 FilePathList selected_files;
1003 1015
1004 // FilePath(virtual_path) doesn't work on win, so limit this to ChromeOS. 1016 // FilePath(virtual_path) doesn't work on win, so limit this to ChromeOS.
1005 #if defined(OS_CHROMEOS) 1017 #if defined(OS_CHROMEOS)
1006 GURL origin_url = source_url().GetOrigin(); 1018 GURL origin_url = source_url().GetOrigin();
1007 fileapi::FileSystemPathManager* path_manager = 1019 fileapi::FileSystemPathManager* path_manager =
1008 profile()->GetFileSystemContext()->path_manager(); 1020 profile()->GetFileSystemContext()->path_manager();
1009 1021
1010 size_t len = file_urls.size(); 1022 size_t len = file_urls.size();
(...skipping 18 matching lines...) Expand all
1029 false); 1041 false);
1030 if (!root.empty()) { 1042 if (!root.empty()) {
1031 selected_files.push_back(root.Append(virtual_path)); 1043 selected_files.push_back(root.Append(virtual_path));
1032 } else { 1044 } else {
1033 LOG(WARNING) << "GetLocalPathsOnFileThread failed " 1045 LOG(WARNING) << "GetLocalPathsOnFileThread failed "
1034 << file_url.spec(); 1046 << file_url.spec();
1035 } 1047 }
1036 } 1048 }
1037 #endif 1049 #endif
1038 1050
1039 BrowserThread::PostTask( 1051 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
1040 BrowserThread::UI, FROM_HERE, 1052 base::Bind(callback, selected_files));
1041 base::Bind(
1042 &FileBrowserFunction::GetLocalPathsResponseOnUIThread,
1043 this,
1044 selected_files, context));
1045 } 1053 }
1046 1054
1047 bool SelectFileFunction::RunImpl() { 1055 bool SelectFileFunction::RunImpl() {
1048 if (args_->GetSize() != 2) { 1056 if (args_->GetSize() != 2) {
1049 return false; 1057 return false;
1050 } 1058 }
1051 std::string file_url; 1059 std::string file_url;
1052 args_->GetString(0, &file_url); 1060 args_->GetString(0, &file_url);
1053 UrlList file_paths; 1061 UrlList file_paths;
1054 file_paths.push_back(GURL(file_url)); 1062 file_paths.push_back(GURL(file_url));
1055 1063
1056 BrowserThread::PostTask( 1064 GetLocalPathsOnFileThreadAndRunCallbackOnUIThread(
1057 BrowserThread::FILE, FROM_HERE, 1065 file_paths,
1058 base::Bind( 1066 base::Bind(&SelectFileFunction::GetLocalPathsResponseOnUIThread, this));
1059 &SelectFileFunction::GetLocalPathsOnFileThread,
1060 this,
1061 file_paths, reinterpret_cast<void*>(NULL)));
1062
1063 return true; 1067 return true;
1064 } 1068 }
1065 1069
1066 void SelectFileFunction::GetLocalPathsResponseOnUIThread( 1070 void SelectFileFunction::GetLocalPathsResponseOnUIThread(
1067 const FilePathList& files, void* context) { 1071 const FilePathList& files) {
1068 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1072 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1069 DCHECK(!context);
1070 if (files.size() != 1) { 1073 if (files.size() != 1) {
1071 SendResponse(false); 1074 SendResponse(false);
1072 return; 1075 return;
1073 } 1076 }
1074 int index; 1077 int index;
1075 args_->GetInteger(1, &index); 1078 args_->GetInteger(1, &index);
1076 int32 tab_id = GetTabId(); 1079 int32 tab_id = GetTabId();
1077 SelectFileDialogExtension::OnFileSelected(tab_id, files[0], index); 1080 SelectFileDialogExtension::OnFileSelected(tab_id, files[0], index);
1078 SendResponse(true); 1081 SendResponse(true);
1079 } 1082 }
(...skipping 19 matching lines...) Expand all
1099 1102
1100 std::string virtual_path; 1103 std::string virtual_path;
1101 size_t len = path_list->GetSize(); 1104 size_t len = path_list->GetSize();
1102 UrlList file_urls; 1105 UrlList file_urls;
1103 file_urls.reserve(len); 1106 file_urls.reserve(len);
1104 for (size_t i = 0; i < len; ++i) { 1107 for (size_t i = 0; i < len; ++i) {
1105 path_list->GetString(i, &virtual_path); 1108 path_list->GetString(i, &virtual_path);
1106 file_urls.push_back(GURL(virtual_path)); 1109 file_urls.push_back(GURL(virtual_path));
1107 } 1110 }
1108 1111
1109 BrowserThread::PostTask( 1112 GetLocalPathsOnFileThreadAndRunCallbackOnUIThread(
1110 BrowserThread::FILE, FROM_HERE, 1113 file_urls,
1111 base::Bind( 1114 base::Bind(&ViewFilesFunction::GetLocalPathsResponseOnUIThread,
1112 &ViewFilesFunction::GetLocalPathsOnFileThread, 1115 this,
1113 this, 1116 internal_task_id));
1114 file_urls,
1115 reinterpret_cast<void*>(new std::string(internal_task_id))));
1116
1117 return true; 1117 return true;
1118 } 1118 }
1119 1119
1120 void ViewFilesFunction::GetLocalPathsResponseOnUIThread( 1120 void ViewFilesFunction::GetLocalPathsResponseOnUIThread(
1121 const FilePathList& files, void* context) { 1121 const std::string& internal_task_id,
1122 const FilePathList& files) {
1122 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1123 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1123 DCHECK(context);
1124 scoped_ptr<std::string> internal_task_id(
1125 reinterpret_cast<std::string*>(context));
1126 for (FilePathList::const_iterator iter = files.begin(); 1124 for (FilePathList::const_iterator iter = files.begin();
1127 iter != files.end(); 1125 iter != files.end();
1128 ++iter) { 1126 ++iter) {
1129 FileManagerUtil::ViewItem(*iter, 1127 FileManagerUtil::ViewItem(*iter,
1130 *(internal_task_id.get()) == kEnqueueTaskId || 1128 internal_task_id == kEnqueueTaskId ||
1131 // Start the first one, enqueue others. 1129 // Start the first one, enqueue others.
1132 iter != files.begin()); 1130 iter != files.begin());
1133 } 1131 }
1134 SendResponse(true); 1132 SendResponse(true);
1135 } 1133 }
1136 1134
1137 SelectFilesFunction::SelectFilesFunction() { 1135 SelectFilesFunction::SelectFilesFunction() {
1138 } 1136 }
1139 1137
1140 SelectFilesFunction::~SelectFilesFunction() { 1138 SelectFilesFunction::~SelectFilesFunction() {
1141 } 1139 }
1142 1140
1143 bool SelectFilesFunction::RunImpl() { 1141 bool SelectFilesFunction::RunImpl() {
1144 if (args_->GetSize() != 1) { 1142 if (args_->GetSize() != 1) {
1145 return false; 1143 return false;
1146 } 1144 }
1147 1145
1148 ListValue* path_list = NULL; 1146 ListValue* path_list = NULL;
1149 args_->GetList(0, &path_list); 1147 args_->GetList(0, &path_list);
1150 DCHECK(path_list); 1148 DCHECK(path_list);
1151 1149
1152 std::string virtual_path; 1150 std::string virtual_path;
1153 size_t len = path_list->GetSize(); 1151 size_t len = path_list->GetSize();
1154 UrlList file_urls; 1152 UrlList file_urls;
1155 file_urls.reserve(len); 1153 file_urls.reserve(len);
1156 for (size_t i = 0; i < len; ++i) { 1154 for (size_t i = 0; i < len; ++i) {
1157 path_list->GetString(i, &virtual_path); 1155 path_list->GetString(i, &virtual_path);
1158 file_urls.push_back(GURL(virtual_path)); 1156 file_urls.push_back(GURL(virtual_path));
1159 } 1157 }
1160 1158
1161 BrowserThread::PostTask( 1159 GetLocalPathsOnFileThreadAndRunCallbackOnUIThread(
1162 BrowserThread::FILE, FROM_HERE, 1160 file_urls,
1163 base::Bind( 1161 base::Bind(&SelectFilesFunction::GetLocalPathsResponseOnUIThread, this));
1164 &SelectFilesFunction::GetLocalPathsOnFileThread,
1165 this,
1166 file_urls, reinterpret_cast<void*>(NULL)));
1167
1168 return true; 1162 return true;
1169 } 1163 }
1170 1164
1171 void SelectFilesFunction::GetLocalPathsResponseOnUIThread( 1165 void SelectFilesFunction::GetLocalPathsResponseOnUIThread(
1172 const FilePathList& files, void* context) { 1166 const FilePathList& files) {
1173 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1167 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1174 DCHECK(!context);
1175 int32 tab_id = GetTabId(); 1168 int32 tab_id = GetTabId();
1176 SelectFileDialogExtension::OnMultiFilesSelected(tab_id, files); 1169 SelectFileDialogExtension::OnMultiFilesSelected(tab_id, files);
1177 SendResponse(true); 1170 SendResponse(true);
1178 } 1171 }
1179 1172
1180 bool CancelFileDialogFunction::RunImpl() { 1173 bool CancelFileDialogFunction::RunImpl() {
1181 int32 tab_id = GetTabId(); 1174 int32 tab_id = GetTabId();
1182 SelectFileDialogExtension::OnFileSelectionCanceled(tab_id); 1175 SelectFileDialogExtension::OnFileSelectionCanceled(tab_id);
1183 SendResponse(true); 1176 SendResponse(true);
1184 return true; 1177 return true;
1185 } 1178 }
1186 1179
1187 AddMountFunction::AddMountFunction() { 1180 AddMountFunction::AddMountFunction() {
1188 } 1181 }
1189 1182
1190 AddMountFunction::~AddMountFunction() { 1183 AddMountFunction::~AddMountFunction() {
1191 } 1184 }
1192 1185
1193 bool AddMountFunction::RunImpl() { 1186 bool AddMountFunction::RunImpl() {
1187 // The third argument is simply ignored.
1194 if (args_->GetSize() != 2 && args_->GetSize() != 3) { 1188 if (args_->GetSize() != 2 && args_->GetSize() != 3) {
1195 error_ = "Invalid argument count"; 1189 error_ = "Invalid argument count";
1196 return false; 1190 return false;
1197 } 1191 }
1198 1192
1199 std::string file_url; 1193 std::string file_url;
1200 if (!args_->GetString(0, &file_url)) { 1194 if (!args_->GetString(0, &file_url)) {
1201 return false; 1195 return false;
1202 } 1196 }
1203 1197
1204 std::string mount_type_str; 1198 std::string mount_type_str;
1205 if (!args_->GetString(1, &mount_type_str)) { 1199 if (!args_->GetString(1, &mount_type_str)) {
1206 return false; 1200 return false;
1207 } 1201 }
1208 1202
1209 UrlList file_paths; 1203 UrlList file_paths;
1210 file_paths.push_back(GURL(file_url)); 1204 file_paths.push_back(GURL(file_url));
1211 1205
1212 #if defined(OS_CHROMEOS) 1206 #if defined(OS_CHROMEOS)
1213 chromeos::MountPathOptions options; 1207 GetLocalPathsOnFileThreadAndRunCallbackOnUIThread(
1214 if (args_->GetSize() == 3) { 1208 file_paths,
1215 DictionaryValue *dict; 1209 base::Bind(&AddMountFunction::GetLocalPathsResponseOnUIThread,
1216 if (!args_->GetDictionary(2, &dict)) { 1210 this,
1217 NOTREACHED(); 1211 mount_type_str));
1218 }
1219
1220 for (base::DictionaryValue::key_iterator it = dict->begin_keys();
1221 it != dict->end_keys();
1222 ++it) {
1223 std::string value;
1224 if (!dict->GetString(*it, &value)) {
1225 NOTREACHED();
1226 }
1227
1228 options.push_back(chromeos::MountPathOptions::value_type((*it).c_str(),
1229 value.c_str()));
1230 }
1231 }
1232
1233 MountParamaters* params = new MountParamaters(mount_type_str, options);
1234 BrowserThread::PostTask(
1235 BrowserThread::FILE, FROM_HERE,
1236 base::Bind(
1237 &AddMountFunction::GetLocalPathsOnFileThread,
1238 this,
1239 file_paths, reinterpret_cast<void*>(params)));
1240 #endif // OS_CHROMEOS 1212 #endif // OS_CHROMEOS
1241 1213
1242 return true; 1214 return true;
1243 } 1215 }
1244 1216
1245 void AddMountFunction::GetLocalPathsResponseOnUIThread( 1217 void AddMountFunction::GetLocalPathsResponseOnUIThread(
1246 const FilePathList& files, void* context) { 1218 const std::string& mount_type_str,
1219 const FilePathList& files) {
1247 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1220 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1248 DCHECK(context);
1249 1221
1250 if (!files.size()) { 1222 if (!files.size()) {
1251 SendResponse(false); 1223 SendResponse(false);
1252 return; 1224 return;
1253 } 1225 }
1254 1226
1255 #ifdef OS_CHROMEOS 1227 #ifdef OS_CHROMEOS
1256 scoped_ptr<MountParamaters> params(
1257 reinterpret_cast<MountParamaters*>(context));
1258 const std::string& mount_type_str = params->mount_type;
1259 const chromeos::MountPathOptions& options = params->mount_options;
1260 FilePath::StringType source_file = files[0].value(); 1228 FilePath::StringType source_file = files[0].value();
1261 1229
1262 chromeos::MountLibrary *mount_lib = 1230 chromeos::disks::DiskMountManager* disk_mount_manager =
1263 chromeos::CrosLibrary::Get()->GetMountLibrary(); 1231 chromeos::disks::DiskMountManager::GetInstance();
1264 1232
1265 chromeos::MountType mount_type = 1233 chromeos::MountType mount_type =
1266 mount_lib->MountTypeFromString(mount_type_str); 1234 disk_mount_manager->MountTypeFromString(mount_type_str);
1267 if (mount_type == chromeos::MOUNT_TYPE_INVALID) { 1235 if (mount_type == chromeos::MOUNT_TYPE_INVALID) {
1268 error_ = "Invalid mount type"; 1236 error_ = "Invalid mount type";
1269 SendResponse(false); 1237 SendResponse(false);
1270 return; 1238 return;
1271 } 1239 }
1272 1240
1273 mount_lib->MountPath(source_file.data(), mount_type, options); 1241 disk_mount_manager->MountPath(source_file.data(), mount_type);
1274 #endif 1242 #endif
1275 1243
1276 SendResponse(true); 1244 SendResponse(true);
1277 } 1245 }
1278 1246
1279 RemoveMountFunction::RemoveMountFunction() { 1247 RemoveMountFunction::RemoveMountFunction() {
1280 } 1248 }
1281 1249
1282 RemoveMountFunction::~RemoveMountFunction() { 1250 RemoveMountFunction::~RemoveMountFunction() {
1283 } 1251 }
1284 1252
1285 bool RemoveMountFunction::RunImpl() { 1253 bool RemoveMountFunction::RunImpl() {
1286 if (args_->GetSize() != 1) { 1254 if (args_->GetSize() != 1) {
1287 return false; 1255 return false;
1288 } 1256 }
1289 1257
1290 std::string mount_path; 1258 std::string mount_path;
1291 if (!args_->GetString(0, &mount_path)) { 1259 if (!args_->GetString(0, &mount_path)) {
1292 return false; 1260 return false;
1293 } 1261 }
1294 1262
1295 UrlList file_paths; 1263 UrlList file_paths;
1296 file_paths.push_back(GURL(mount_path)); 1264 file_paths.push_back(GURL(mount_path));
1297 BrowserThread::PostTask( 1265 GetLocalPathsOnFileThreadAndRunCallbackOnUIThread(
1298 BrowserThread::FILE, FROM_HERE, 1266 file_paths,
1299 base::Bind( 1267 base::Bind(&RemoveMountFunction::GetLocalPathsResponseOnUIThread, this));
1300 &RemoveMountFunction::GetLocalPathsOnFileThread,
1301 this,
1302 file_paths, reinterpret_cast<void*>(NULL)));
1303 return true; 1268 return true;
1304 } 1269 }
1305 1270
1306 void RemoveMountFunction::GetLocalPathsResponseOnUIThread( 1271 void RemoveMountFunction::GetLocalPathsResponseOnUIThread(
1307 const FilePathList& files, void* context) { 1272 const FilePathList& files) {
1308 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1273 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1309 DCHECK(!context);
1310 1274
1311 if (files.size() != 1) { 1275 if (files.size() != 1) {
1312 SendResponse(false); 1276 SendResponse(false);
1313 return; 1277 return;
1314 } 1278 }
1315 #ifdef OS_CHROMEOS 1279 #ifdef OS_CHROMEOS
1316 chromeos::CrosLibrary::Get()->GetMountLibrary()->UnmountPath( 1280 chromeos::disks::DiskMountManager::GetInstance()->UnmountPath(
1317 files[0].value().c_str()); 1281 files[0].value());
1318 #endif 1282 #endif
1319 1283
1320 SendResponse(true); 1284 SendResponse(true);
1321 } 1285 }
1322 1286
1323 GetMountPointsFunction::GetMountPointsFunction() { 1287 GetMountPointsFunction::GetMountPointsFunction() {
1324 } 1288 }
1325 1289
1326 GetMountPointsFunction::~GetMountPointsFunction() { 1290 GetMountPointsFunction::~GetMountPointsFunction() {
1327 } 1291 }
1328 1292
1329 bool GetMountPointsFunction::RunImpl() { 1293 bool GetMountPointsFunction::RunImpl() {
1330 if (args_->GetSize()) 1294 if (args_->GetSize())
1331 return false; 1295 return false;
1332 1296
1333 base::ListValue *mounts = new base::ListValue(); 1297 base::ListValue *mounts = new base::ListValue();
1334 result_.reset(mounts); 1298 result_.reset(mounts);
1335 1299
1336 #ifdef OS_CHROMEOS 1300 #ifdef OS_CHROMEOS
1337 chromeos::MountLibrary *mount_lib = 1301 chromeos::disks::DiskMountManager* disk_mount_manager =
1338 chromeos::CrosLibrary::Get()->GetMountLibrary(); 1302 chromeos::disks::DiskMountManager::GetInstance();
1339 chromeos::MountLibrary::MountPointMap mount_points = 1303 chromeos::disks::DiskMountManager::MountPointMap mount_points =
1340 mount_lib->mount_points(); 1304 disk_mount_manager->mount_points();
1341 1305
1342 for (chromeos::MountLibrary::MountPointMap::const_iterator it = 1306 for (chromeos::disks::DiskMountManager::MountPointMap::const_iterator it =
1343 mount_points.begin(); 1307 mount_points.begin();
1344 it != mount_points.end(); 1308 it != mount_points.end();
1345 ++it) { 1309 ++it) {
1346 mounts->Append(MountPointToValue(profile_, it->second)); 1310 mounts->Append(MountPointToValue(profile_, it->second));
1347 } 1311 }
1348 #endif 1312 #endif
1349 1313
1350 SendResponse(true); 1314 SendResponse(true);
1351 return true; 1315 return true;
1352 } 1316 }
1353 1317
1354 GetSizeStatsFunction::GetSizeStatsFunction() { 1318 GetSizeStatsFunction::GetSizeStatsFunction() {
1355 } 1319 }
1356 1320
1357 GetSizeStatsFunction::~GetSizeStatsFunction() { 1321 GetSizeStatsFunction::~GetSizeStatsFunction() {
1358 } 1322 }
1359 1323
1360 bool GetSizeStatsFunction::RunImpl() { 1324 bool GetSizeStatsFunction::RunImpl() {
1361 if (args_->GetSize() != 1) { 1325 if (args_->GetSize() != 1) {
1362 return false; 1326 return false;
1363 } 1327 }
1364 1328
1365 std::string mount_url; 1329 std::string mount_url;
1366 if (!args_->GetString(0, &mount_url)) 1330 if (!args_->GetString(0, &mount_url))
1367 return false; 1331 return false;
1368 1332
1369 UrlList mount_paths; 1333 UrlList mount_paths;
1370 mount_paths.push_back(GURL(mount_url)); 1334 mount_paths.push_back(GURL(mount_url));
1371 1335
1372 BrowserThread::PostTask( 1336 GetLocalPathsOnFileThreadAndRunCallbackOnUIThread(
1373 BrowserThread::FILE, FROM_HERE, 1337 mount_paths,
1374 base::Bind( 1338 base::Bind(&GetSizeStatsFunction::GetLocalPathsResponseOnUIThread, this));
1375 &GetSizeStatsFunction::GetLocalPathsOnFileThread,
1376 this,
1377 mount_paths, reinterpret_cast<void*>(NULL)));
1378 return true; 1339 return true;
1379 } 1340 }
1380 1341
1381 void GetSizeStatsFunction::GetLocalPathsResponseOnUIThread( 1342 void GetSizeStatsFunction::GetLocalPathsResponseOnUIThread(
1382 const FilePathList& files, void* context) { 1343 const FilePathList& files) {
1383 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1344 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1384 1345
1385 if (files.size() != 1) { 1346 if (files.size() != 1) {
1386 SendResponse(false); 1347 SendResponse(false);
1387 return; 1348 return;
1388 } 1349 }
1389 1350
1390 BrowserThread::PostTask( 1351 BrowserThread::PostTask(
1391 BrowserThread::FILE, FROM_HERE, 1352 BrowserThread::FILE, FROM_HERE,
1392 base::Bind( 1353 base::Bind(
1393 &GetSizeStatsFunction::CallGetSizeStatsOnFileThread, 1354 &GetSizeStatsFunction::CallGetSizeStatsOnFileThread,
1394 this, 1355 this,
1395 files[0].value().c_str())); 1356 files[0].value()));
1396 } 1357 }
1397 1358
1398 void GetSizeStatsFunction::CallGetSizeStatsOnFileThread( 1359 void GetSizeStatsFunction::CallGetSizeStatsOnFileThread(
1399 const char* mount_path) { 1360 const std::string& mount_path) {
1400 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 1361 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
1401 1362
1402 size_t total_size_kb = 0; 1363 size_t total_size_kb = 0;
1403 size_t remaining_size_kb = 0; 1364 size_t remaining_size_kb = 0;
1404 #ifdef OS_CHROMEOS 1365 #ifdef OS_CHROMEOS
1405 chromeos::CrosLibrary::Get()->GetMountLibrary()->GetSizeStatsOnFileThread( 1366 chromeos::disks::DiskMountManager::GetInstance()->
1406 mount_path, &total_size_kb, &remaining_size_kb); 1367 GetSizeStatsOnFileThread(mount_path, &total_size_kb, &remaining_size_kb);
1407 #endif 1368 #endif
1408 1369
1409 BrowserThread::PostTask( 1370 BrowserThread::PostTask(
1410 BrowserThread::UI, FROM_HERE, 1371 BrowserThread::UI, FROM_HERE,
1411 base::Bind( 1372 base::Bind(
1412 &GetSizeStatsFunction::GetSizeStatsCallbackOnUIThread, 1373 &GetSizeStatsFunction::GetSizeStatsCallbackOnUIThread,
1413 this, 1374 this,
1414 mount_path, total_size_kb, remaining_size_kb)); 1375 mount_path, total_size_kb, remaining_size_kb));
1415 } 1376 }
1416 1377
1417 void GetSizeStatsFunction::GetSizeStatsCallbackOnUIThread( 1378 void GetSizeStatsFunction::GetSizeStatsCallbackOnUIThread(
1418 const char* mount_path, size_t total_size_kb, size_t remaining_size_kb) { 1379 const std::string& mount_path,
1380 size_t total_size_kb,
1381 size_t remaining_size_kb) {
1419 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1382 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1420 1383
1421 base::DictionaryValue* sizes = new base::DictionaryValue(); 1384 base::DictionaryValue* sizes = new base::DictionaryValue();
1422 result_.reset(sizes); 1385 result_.reset(sizes);
1423 1386
1424 sizes->SetInteger("totalSizeKB", total_size_kb); 1387 sizes->SetInteger("totalSizeKB", total_size_kb);
1425 sizes->SetInteger("remainingSizeKB", remaining_size_kb); 1388 sizes->SetInteger("remainingSizeKB", remaining_size_kb);
1426 1389
1427 SendResponse(true); 1390 SendResponse(true);
1428 } 1391 }
(...skipping 11 matching lines...) Expand all
1440 1403
1441 std::string volume_file_url; 1404 std::string volume_file_url;
1442 if (!args_->GetString(0, &volume_file_url)) { 1405 if (!args_->GetString(0, &volume_file_url)) {
1443 NOTREACHED(); 1406 NOTREACHED();
1444 return false; 1407 return false;
1445 } 1408 }
1446 1409
1447 UrlList file_paths; 1410 UrlList file_paths;
1448 file_paths.push_back(GURL(volume_file_url)); 1411 file_paths.push_back(GURL(volume_file_url));
1449 1412
1450 BrowserThread::PostTask( 1413 GetLocalPathsOnFileThreadAndRunCallbackOnUIThread(
1451 BrowserThread::FILE, FROM_HERE, 1414 file_paths,
1452 base::Bind( 1415 base::Bind(&FormatDeviceFunction::GetLocalPathsResponseOnUIThread, this));
1453 &FormatDeviceFunction::GetLocalPathsOnFileThread,
1454 this,
1455 file_paths, reinterpret_cast<void*>(NULL)));
1456 return true; 1416 return true;
1457 } 1417 }
1458 1418
1459 void FormatDeviceFunction::GetLocalPathsResponseOnUIThread( 1419 void FormatDeviceFunction::GetLocalPathsResponseOnUIThread(
1460 const FilePathList& files, void* context) { 1420 const FilePathList& files) {
1461 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1421 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1462 1422
1463 if (files.size() != 1) { 1423 if (files.size() != 1) {
1464 SendResponse(false); 1424 SendResponse(false);
1465 return; 1425 return;
1466 } 1426 }
1467 1427
1468 #ifdef OS_CHROMEOS 1428 #ifdef OS_CHROMEOS
1469 chromeos::CrosLibrary::Get()->GetMountLibrary()->FormatMountedDevice( 1429 chromeos::disks::DiskMountManager::GetInstance()->FormatMountedDevice(
1470 files[0].value().c_str()); 1430 files[0].value());
1471 #endif 1431 #endif
1472 1432
1473 SendResponse(true); 1433 SendResponse(true);
1474 } 1434 }
1475 1435
1476 GetVolumeMetadataFunction::GetVolumeMetadataFunction() { 1436 GetVolumeMetadataFunction::GetVolumeMetadataFunction() {
1477 } 1437 }
1478 1438
1479 GetVolumeMetadataFunction::~GetVolumeMetadataFunction() { 1439 GetVolumeMetadataFunction::~GetVolumeMetadataFunction() {
1480 } 1440 }
1481 1441
1482 bool GetVolumeMetadataFunction::RunImpl() { 1442 bool GetVolumeMetadataFunction::RunImpl() {
1483 if (args_->GetSize() != 1) { 1443 if (args_->GetSize() != 1) {
1484 error_ = "Invalid argument count"; 1444 error_ = "Invalid argument count";
1485 return false; 1445 return false;
1486 } 1446 }
1487 1447
1488 std::string volume_device_path; 1448 std::string volume_device_path;
1489 if (!args_->GetString(0, &volume_device_path)) { 1449 if (!args_->GetString(0, &volume_device_path)) {
1490 NOTREACHED(); 1450 NOTREACHED();
1491 } 1451 }
1492 1452
1493 #ifdef OS_CHROMEOS 1453 #ifdef OS_CHROMEOS
1494 chromeos::MountLibrary* mount_lib = 1454 chromeos::disks::DiskMountManager* disk_mount_manager =
1495 chromeos::CrosLibrary::Get()->GetMountLibrary(); 1455 chromeos::disks::DiskMountManager::GetInstance();
1496 chromeos::MountLibrary::DiskMap::const_iterator volume_it = 1456 chromeos::disks::DiskMountManager::DiskMap::const_iterator volume_it =
1497 mount_lib->disks().find(volume_device_path); 1457 disk_mount_manager->disks().find(volume_device_path);
1498 1458
1499 if (volume_it != mount_lib->disks().end() && 1459 if (volume_it != disk_mount_manager->disks().end() &&
1500 !volume_it->second->is_hidden()) { 1460 !volume_it->second->is_hidden()) {
1501 chromeos::MountLibrary::Disk* volume = volume_it->second; 1461 chromeos::disks::DiskMountManager::Disk* volume = volume_it->second;
1502 DictionaryValue* volume_info = new DictionaryValue(); 1462 DictionaryValue* volume_info = new DictionaryValue();
1503 result_.reset(volume_info); 1463 result_.reset(volume_info);
1504 // Localising mount path. 1464 // Localising mount path.
1505 std::string mount_path; 1465 std::string mount_path;
1506 if (!volume->mount_path().empty()) { 1466 if (!volume->mount_path().empty()) {
1507 FilePath relative_mount_path; 1467 FilePath relative_mount_path;
1508 FileManagerUtil::ConvertFileToRelativeFileSystemPath(profile_, 1468 FileManagerUtil::ConvertFileToRelativeFileSystemPath(profile_,
1509 FilePath(volume->mount_path()), &relative_mount_path); 1469 FilePath(volume->mount_path()), &relative_mount_path);
1510 mount_path = relative_mount_path.value(); 1470 mount_path = relative_mount_path.value();
1511 } 1471 }
1512 volume_info->SetString("devicePath", volume->device_path()); 1472 volume_info->SetString("devicePath", volume->device_path());
1513 volume_info->SetString("mountPath", mount_path); 1473 volume_info->SetString("mountPath", mount_path);
1514 volume_info->SetString("systemPath", volume->system_path()); 1474 volume_info->SetString("systemPath", volume->system_path());
1515 volume_info->SetString("filePath", volume->file_path()); 1475 volume_info->SetString("filePath", volume->file_path());
1516 volume_info->SetString("deviceLabel", volume->device_label()); 1476 volume_info->SetString("deviceLabel", volume->device_label());
1517 volume_info->SetString("driveLabel", volume->drive_label()); 1477 volume_info->SetString("driveLabel", volume->drive_label());
1518 volume_info->SetString("deviceType", 1478 volume_info->SetString("deviceType",
1519 DeviceTypeToString(volume->device_type())); 1479 DeviceTypeToString(volume->device_type()));
1520 volume_info->SetInteger("totalSize", volume->total_size()); 1480 volume_info->SetInteger("totalSize", volume->total_size_in_bytes());
1521 volume_info->SetBoolean("isParent", volume->is_parent()); 1481 volume_info->SetBoolean("isParent", volume->is_parent());
1522 volume_info->SetBoolean("isReadOnly", volume->is_read_only()); 1482 volume_info->SetBoolean("isReadOnly", volume->is_read_only());
1523 volume_info->SetBoolean("hasMedia", volume->has_media()); 1483 volume_info->SetBoolean("hasMedia", volume->has_media());
1524 volume_info->SetBoolean("isOnBootDevice", volume->on_boot_device()); 1484 volume_info->SetBoolean("isOnBootDevice", volume->on_boot_device());
1525 1485
1526 return true; 1486 return true;
1527 } 1487 }
1528 #endif 1488 #endif
1529 error_ = kVolumeDevicePathNotFound; 1489 error_ = kVolumeDevicePathNotFound;
1530 return false; 1490 return false;
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
1715 l10n_util::GetStringUTF16(IDS_CERT_MANAGER_VIEW_CERT_BUTTON)); 1675 l10n_util::GetStringUTF16(IDS_CERT_MANAGER_VIEW_CERT_BUTTON));
1716 dict->SetString("PLAY_MEDIA", 1676 dict->SetString("PLAY_MEDIA",
1717 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_PLAY)); 1677 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_PLAY));
1718 #if defined(OS_CHROMEOS) 1678 #if defined(OS_CHROMEOS)
1719 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnablePhotoEditor)) 1679 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnablePhotoEditor))
1720 dict->SetString("ENABLE_PHOTO_EDITOR", "true"); 1680 dict->SetString("ENABLE_PHOTO_EDITOR", "true");
1721 #endif 1681 #endif
1722 1682
1723 return true; 1683 return true;
1724 } 1684 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698