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

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: Cleaned up namespace, eliminated void* 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
hashimoto 2011/11/16 04:28:15 Introduced anonymous namespace to make locally use
satorux1 2011/11/16 06:46:06 +1
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";
68 const std::string kVolumeTypeHardDrive = "hdd"; 66 const std::string kVolumeTypeHardDrive = "hdd";
(...skipping 191 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
hashimoto 2011/11/16 04:28:15 LocalFileSystemCallbackDispatcher and ExecuteTasks
satorux1 2011/11/16 06:46:06 +1
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::GetLocalPaths(const UrlList& file_urls,
996 GetLocalPathsCallback callback) {
satorux1 2011/11/16 06:46:06 This function does something a bit tricky. Would b
hashimoto 2011/11/16 07:45:32 Done.
997 BrowserThread::PostTask(
998 BrowserThread::FILE, FROM_HERE,
999 base::Bind(
1000 &SelectFileFunction::GetLocalPathsOnFileThread,
1001 this,
satorux1 2011/11/16 06:46:06 Did you mean FileBrowserFunction::GetLocalPathsOnF
hashimoto 2011/11/16 07:45:32 Thank you for finding this mistake, fixed. BTW, t
satorux1 2011/11/16 18:01:09 Heh, interesting. Learned something new...
1002 file_urls, callback));
1003 }
1004
995 // GetFileSystemRootPathOnFileThread can only be called from the file thread, 1005 // GetFileSystemRootPathOnFileThread can only be called from the file thread,
996 // so here we are. This function takes a vector of virtual paths, converts 1006 // so here we are. This function takes a vector of virtual paths, converts
997 // them to local paths and calls GetLocalPathsResponseOnUIThread with the 1007 // them to local paths and calls GetLocalPathsResponseOnUIThread with the
998 // result vector, on the UI thread. 1008 // result vector, on the UI thread.
999 void FileBrowserFunction::GetLocalPathsOnFileThread(const UrlList& file_urls, 1009 void FileBrowserFunction::GetLocalPathsOnFileThread(
1000 void* context) { 1010 const UrlList& file_urls,
1011 GetLocalPathsCallback callback) {
1001 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 1012 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
1002 FilePathList selected_files; 1013 FilePathList selected_files;
1003 1014
1004 // FilePath(virtual_path) doesn't work on win, so limit this to ChromeOS. 1015 // FilePath(virtual_path) doesn't work on win, so limit this to ChromeOS.
1005 #if defined(OS_CHROMEOS) 1016 #if defined(OS_CHROMEOS)
1006 GURL origin_url = source_url().GetOrigin(); 1017 GURL origin_url = source_url().GetOrigin();
1007 fileapi::FileSystemPathManager* path_manager = 1018 fileapi::FileSystemPathManager* path_manager =
1008 profile()->GetFileSystemContext()->path_manager(); 1019 profile()->GetFileSystemContext()->path_manager();
1009 1020
1010 size_t len = file_urls.size(); 1021 size_t len = file_urls.size();
(...skipping 18 matching lines...) Expand all
1029 false); 1040 false);
1030 if (!root.empty()) { 1041 if (!root.empty()) {
1031 selected_files.push_back(root.Append(virtual_path)); 1042 selected_files.push_back(root.Append(virtual_path));
1032 } else { 1043 } else {
1033 LOG(WARNING) << "GetLocalPathsOnFileThread failed " 1044 LOG(WARNING) << "GetLocalPathsOnFileThread failed "
1034 << file_url.spec(); 1045 << file_url.spec();
1035 } 1046 }
1036 } 1047 }
1037 #endif 1048 #endif
1038 1049
1039 BrowserThread::PostTask( 1050 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
1040 BrowserThread::UI, FROM_HERE, 1051 base::Bind(callback, selected_files));
1041 base::Bind(
1042 &FileBrowserFunction::GetLocalPathsResponseOnUIThread,
1043 this,
1044 selected_files, context));
1045 } 1052 }
1046 1053
1047 bool SelectFileFunction::RunImpl() { 1054 bool SelectFileFunction::RunImpl() {
1048 if (args_->GetSize() != 2) { 1055 if (args_->GetSize() != 2) {
1049 return false; 1056 return false;
1050 } 1057 }
1051 std::string file_url; 1058 std::string file_url;
1052 args_->GetString(0, &file_url); 1059 args_->GetString(0, &file_url);
1053 UrlList file_paths; 1060 UrlList file_paths;
1054 file_paths.push_back(GURL(file_url)); 1061 file_paths.push_back(GURL(file_url));
1055 1062
1056 BrowserThread::PostTask( 1063 GetLocalPaths(file_paths,
1057 BrowserThread::FILE, FROM_HERE, 1064 base::Bind(
1058 base::Bind( 1065 &SelectFileFunction::GetLocalPathsResponseOnUIThread,
1059 &SelectFileFunction::GetLocalPathsOnFileThread, 1066 this));
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 FileManagerDialog::OnFileSelected(tab_id, files[0], index); 1080 FileManagerDialog::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 GetLocalPaths(file_urls,
1110 BrowserThread::FILE, FROM_HERE, 1113 base::Bind(&ViewFilesFunction::GetLocalPathsResponseOnUIThread,
1111 base::Bind( 1114 this,
1112 &ViewFilesFunction::GetLocalPathsOnFileThread, 1115 internal_task_id));
1113 this,
1114 file_urls,
1115 reinterpret_cast<void*>(new std::string(internal_task_id))));
1116
1117 return true; 1116 return true;
1118 } 1117 }
1119 1118
1120 void ViewFilesFunction::GetLocalPathsResponseOnUIThread( 1119 void ViewFilesFunction::GetLocalPathsResponseOnUIThread(
1121 const FilePathList& files, void* context) { 1120 const std::string& internal_task_id,
1121 const FilePathList& files) {
1122 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1122 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(); 1123 for (FilePathList::const_iterator iter = files.begin();
1127 iter != files.end(); 1124 iter != files.end();
1128 ++iter) { 1125 ++iter) {
1129 FileManagerUtil::ViewItem(*iter, 1126 FileManagerUtil::ViewItem(*iter,
1130 *(internal_task_id.get()) == kEnqueueTaskId || 1127 internal_task_id == kEnqueueTaskId ||
1131 // Start the first one, enqueue others. 1128 // Start the first one, enqueue others.
1132 iter != files.begin()); 1129 iter != files.begin());
1133 } 1130 }
1134 SendResponse(true); 1131 SendResponse(true);
1135 } 1132 }
1136 1133
1137 SelectFilesFunction::SelectFilesFunction() { 1134 SelectFilesFunction::SelectFilesFunction() {
1138 } 1135 }
1139 1136
1140 SelectFilesFunction::~SelectFilesFunction() { 1137 SelectFilesFunction::~SelectFilesFunction() {
1141 } 1138 }
1142 1139
1143 bool SelectFilesFunction::RunImpl() { 1140 bool SelectFilesFunction::RunImpl() {
1144 if (args_->GetSize() != 1) { 1141 if (args_->GetSize() != 1) {
1145 return false; 1142 return false;
1146 } 1143 }
1147 1144
1148 ListValue* path_list = NULL; 1145 ListValue* path_list = NULL;
1149 args_->GetList(0, &path_list); 1146 args_->GetList(0, &path_list);
1150 DCHECK(path_list); 1147 DCHECK(path_list);
1151 1148
1152 std::string virtual_path; 1149 std::string virtual_path;
1153 size_t len = path_list->GetSize(); 1150 size_t len = path_list->GetSize();
1154 UrlList file_urls; 1151 UrlList file_urls;
1155 file_urls.reserve(len); 1152 file_urls.reserve(len);
1156 for (size_t i = 0; i < len; ++i) { 1153 for (size_t i = 0; i < len; ++i) {
1157 path_list->GetString(i, &virtual_path); 1154 path_list->GetString(i, &virtual_path);
1158 file_urls.push_back(GURL(virtual_path)); 1155 file_urls.push_back(GURL(virtual_path));
1159 } 1156 }
1160 1157
1161 BrowserThread::PostTask( 1158 GetLocalPaths(file_urls,
1162 BrowserThread::FILE, FROM_HERE, 1159 base::Bind(
1163 base::Bind( 1160 &SelectFilesFunction::GetLocalPathsResponseOnUIThread,
1164 &SelectFilesFunction::GetLocalPathsOnFileThread, 1161 this));
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 FileManagerDialog::OnMultiFilesSelected(tab_id, files); 1169 FileManagerDialog::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 FileManagerDialog::OnFileSelectionCanceled(tab_id); 1175 FileManagerDialog::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 GetLocalPaths(file_paths,
1214 if (args_->GetSize() == 3) { 1208 base::Bind(&AddMountFunction::GetLocalPathsResponseOnUIThread,
1215 DictionaryValue *dict; 1209 this,
1216 if (!args_->GetDictionary(2, &dict)) { 1210 mount_type_str));
1217 NOTREACHED();
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 1211 #endif // OS_CHROMEOS
1241 1212
1242 return true; 1213 return true;
1243 } 1214 }
1244 1215
1245 void AddMountFunction::GetLocalPathsResponseOnUIThread( 1216 void AddMountFunction::GetLocalPathsResponseOnUIThread(
1246 const FilePathList& files, void* context) { 1217 const std::string& mount_type_str,
1218 const FilePathList& files) {
1247 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1219 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1248 DCHECK(context);
1249 1220
1250 if (!files.size()) { 1221 if (!files.size()) {
1251 SendResponse(false); 1222 SendResponse(false);
1252 return; 1223 return;
1253 } 1224 }
1254 1225
1255 #ifdef OS_CHROMEOS 1226 #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(); 1227 FilePath::StringType source_file = files[0].value();
1261 1228
1262 chromeos::MountLibrary *mount_lib = 1229 chromeos::disks::DiskMountManager* disk_mount_manager =
1263 chromeos::CrosLibrary::Get()->GetMountLibrary(); 1230 chromeos::disks::DiskMountManager::GetInstance();
1264 1231
1265 chromeos::MountType mount_type = 1232 chromeos::MountType mount_type =
1266 mount_lib->MountTypeFromString(mount_type_str); 1233 disk_mount_manager->MountTypeFromString(mount_type_str);
1267 if (mount_type == chromeos::MOUNT_TYPE_INVALID) { 1234 if (mount_type == chromeos::MOUNT_TYPE_INVALID) {
1268 error_ = "Invalid mount type"; 1235 error_ = "Invalid mount type";
1269 SendResponse(false); 1236 SendResponse(false);
1270 return; 1237 return;
1271 } 1238 }
1272 1239
1273 mount_lib->MountPath(source_file.data(), mount_type, options); 1240 disk_mount_manager->MountPath(source_file.data(), mount_type);
1274 #endif 1241 #endif
1275 1242
1276 SendResponse(true); 1243 SendResponse(true);
1277 } 1244 }
1278 1245
1279 RemoveMountFunction::RemoveMountFunction() { 1246 RemoveMountFunction::RemoveMountFunction() {
1280 } 1247 }
1281 1248
1282 RemoveMountFunction::~RemoveMountFunction() { 1249 RemoveMountFunction::~RemoveMountFunction() {
1283 } 1250 }
1284 1251
1285 bool RemoveMountFunction::RunImpl() { 1252 bool RemoveMountFunction::RunImpl() {
1286 if (args_->GetSize() != 1) { 1253 if (args_->GetSize() != 1) {
1287 return false; 1254 return false;
1288 } 1255 }
1289 1256
1290 std::string mount_path; 1257 std::string mount_path;
1291 if (!args_->GetString(0, &mount_path)) { 1258 if (!args_->GetString(0, &mount_path)) {
1292 return false; 1259 return false;
1293 } 1260 }
1294 1261
1295 UrlList file_paths; 1262 UrlList file_paths;
1296 file_paths.push_back(GURL(mount_path)); 1263 file_paths.push_back(GURL(mount_path));
1297 BrowserThread::PostTask( 1264 GetLocalPaths(file_paths,
1298 BrowserThread::FILE, FROM_HERE, 1265 base::Bind(
1299 base::Bind( 1266 &RemoveMountFunction::GetLocalPathsResponseOnUIThread,
1300 &RemoveMountFunction::GetLocalPathsOnFileThread, 1267 this));
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 GetLocalPaths(mount_paths,
1373 BrowserThread::FILE, FROM_HERE, 1337 base::Bind(
1374 base::Bind( 1338 &GetSizeStatsFunction::GetLocalPathsResponseOnUIThread,
1375 &GetSizeStatsFunction::GetLocalPathsOnFileThread, 1339 this));
1376 this,
1377 mount_paths, reinterpret_cast<void*>(NULL)));
1378 return true; 1340 return true;
1379 } 1341 }
1380 1342
1381 void GetSizeStatsFunction::GetLocalPathsResponseOnUIThread( 1343 void GetSizeStatsFunction::GetLocalPathsResponseOnUIThread(
1382 const FilePathList& files, void* context) { 1344 const FilePathList& files) {
1383 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1345 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1384 1346
1385 if (files.size() != 1) { 1347 if (files.size() != 1) {
1386 SendResponse(false); 1348 SendResponse(false);
1387 return; 1349 return;
1388 } 1350 }
1389 1351
1390 BrowserThread::PostTask( 1352 BrowserThread::PostTask(
1391 BrowserThread::FILE, FROM_HERE, 1353 BrowserThread::FILE, FROM_HERE,
1392 base::Bind( 1354 base::Bind(
1393 &GetSizeStatsFunction::CallGetSizeStatsOnFileThread, 1355 &GetSizeStatsFunction::CallGetSizeStatsOnFileThread,
1394 this, 1356 this,
1395 files[0].value().c_str())); 1357 files[0].value()));
1396 } 1358 }
1397 1359
1398 void GetSizeStatsFunction::CallGetSizeStatsOnFileThread( 1360 void GetSizeStatsFunction::CallGetSizeStatsOnFileThread(
1399 const char* mount_path) { 1361 const std::string& mount_path) {
1400 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 1362 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
1401 1363
1402 size_t total_size_kb = 0; 1364 size_t total_size_kb = 0;
1403 size_t remaining_size_kb = 0; 1365 size_t remaining_size_kb = 0;
1404 #ifdef OS_CHROMEOS 1366 #ifdef OS_CHROMEOS
1405 chromeos::CrosLibrary::Get()->GetMountLibrary()->GetSizeStatsOnFileThread( 1367 chromeos::disks::DiskMountManager::GetInstance()->
1406 mount_path, &total_size_kb, &remaining_size_kb); 1368 GetSizeStatsOnFileThread(mount_path, &total_size_kb, &remaining_size_kb);
1407 #endif 1369 #endif
1408 1370
1409 BrowserThread::PostTask( 1371 BrowserThread::PostTask(
1410 BrowserThread::UI, FROM_HERE, 1372 BrowserThread::UI, FROM_HERE,
1411 base::Bind( 1373 base::Bind(
1412 &GetSizeStatsFunction::GetSizeStatsCallbackOnUIThread, 1374 &GetSizeStatsFunction::GetSizeStatsCallbackOnUIThread,
1413 this, 1375 this,
1414 mount_path, total_size_kb, remaining_size_kb)); 1376 mount_path, total_size_kb, remaining_size_kb));
1415 } 1377 }
1416 1378
1417 void GetSizeStatsFunction::GetSizeStatsCallbackOnUIThread( 1379 void GetSizeStatsFunction::GetSizeStatsCallbackOnUIThread(
1418 const char* mount_path, size_t total_size_kb, size_t remaining_size_kb) { 1380 const std::string& mount_path,
1381 size_t total_size_kb,
1382 size_t remaining_size_kb) {
1419 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1383 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1420 1384
1421 base::DictionaryValue* sizes = new base::DictionaryValue(); 1385 base::DictionaryValue* sizes = new base::DictionaryValue();
1422 result_.reset(sizes); 1386 result_.reset(sizes);
1423 1387
1424 sizes->SetInteger("totalSizeKB", total_size_kb); 1388 sizes->SetInteger("totalSizeKB", total_size_kb);
1425 sizes->SetInteger("remainingSizeKB", remaining_size_kb); 1389 sizes->SetInteger("remainingSizeKB", remaining_size_kb);
1426 1390
1427 SendResponse(true); 1391 SendResponse(true);
1428 } 1392 }
(...skipping 11 matching lines...) Expand all
1440 1404
1441 std::string volume_file_url; 1405 std::string volume_file_url;
1442 if (!args_->GetString(0, &volume_file_url)) { 1406 if (!args_->GetString(0, &volume_file_url)) {
1443 NOTREACHED(); 1407 NOTREACHED();
1444 return false; 1408 return false;
1445 } 1409 }
1446 1410
1447 UrlList file_paths; 1411 UrlList file_paths;
1448 file_paths.push_back(GURL(volume_file_url)); 1412 file_paths.push_back(GURL(volume_file_url));
1449 1413
1450 BrowserThread::PostTask( 1414 GetLocalPaths(file_paths,
1451 BrowserThread::FILE, FROM_HERE, 1415 base::Bind(
1452 base::Bind( 1416 &FormatDeviceFunction::GetLocalPathsResponseOnUIThread,
1453 &FormatDeviceFunction::GetLocalPathsOnFileThread, 1417 this));
1454 this,
1455 file_paths, reinterpret_cast<void*>(NULL)));
1456 return true; 1418 return true;
1457 } 1419 }
1458 1420
1459 void FormatDeviceFunction::GetLocalPathsResponseOnUIThread( 1421 void FormatDeviceFunction::GetLocalPathsResponseOnUIThread(
1460 const FilePathList& files, void* context) { 1422 const FilePathList& files) {
1461 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1423 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1462 1424
1463 if (files.size() != 1) { 1425 if (files.size() != 1) {
1464 SendResponse(false); 1426 SendResponse(false);
1465 return; 1427 return;
1466 } 1428 }
1467 1429
1468 #ifdef OS_CHROMEOS 1430 #ifdef OS_CHROMEOS
1469 chromeos::CrosLibrary::Get()->GetMountLibrary()->FormatMountedDevice( 1431 chromeos::disks::DiskMountManager::GetInstance()->FormatMountedDevice(
1470 files[0].value().c_str()); 1432 files[0].value());
1471 #endif 1433 #endif
1472 1434
1473 SendResponse(true); 1435 SendResponse(true);
1474 } 1436 }
1475 1437
1476 GetVolumeMetadataFunction::GetVolumeMetadataFunction() { 1438 GetVolumeMetadataFunction::GetVolumeMetadataFunction() {
1477 } 1439 }
1478 1440
1479 GetVolumeMetadataFunction::~GetVolumeMetadataFunction() { 1441 GetVolumeMetadataFunction::~GetVolumeMetadataFunction() {
1480 } 1442 }
1481 1443
1482 bool GetVolumeMetadataFunction::RunImpl() { 1444 bool GetVolumeMetadataFunction::RunImpl() {
1483 if (args_->GetSize() != 1) { 1445 if (args_->GetSize() != 1) {
1484 error_ = "Invalid argument count"; 1446 error_ = "Invalid argument count";
1485 return false; 1447 return false;
1486 } 1448 }
1487 1449
1488 std::string volume_device_path; 1450 std::string volume_device_path;
1489 if (!args_->GetString(0, &volume_device_path)) { 1451 if (!args_->GetString(0, &volume_device_path)) {
1490 NOTREACHED(); 1452 NOTREACHED();
1491 } 1453 }
1492 1454
1493 #ifdef OS_CHROMEOS 1455 #ifdef OS_CHROMEOS
1494 chromeos::MountLibrary* mount_lib = 1456 chromeos::disks::DiskMountManager* disk_mount_manager =
1495 chromeos::CrosLibrary::Get()->GetMountLibrary(); 1457 chromeos::disks::DiskMountManager::GetInstance();
1496 chromeos::MountLibrary::DiskMap::const_iterator volume_it = 1458 chromeos::disks::DiskMountManager::DiskMap::const_iterator volume_it =
1497 mount_lib->disks().find(volume_device_path); 1459 disk_mount_manager->disks().find(volume_device_path);
1498 1460
1499 if (volume_it != mount_lib->disks().end() && 1461 if (volume_it != disk_mount_manager->disks().end() &&
1500 !volume_it->second->is_hidden()) { 1462 !volume_it->second->is_hidden()) {
1501 chromeos::MountLibrary::Disk* volume = volume_it->second; 1463 chromeos::disks::DiskMountManager::Disk* volume = volume_it->second;
1502 DictionaryValue* volume_info = new DictionaryValue(); 1464 DictionaryValue* volume_info = new DictionaryValue();
1503 result_.reset(volume_info); 1465 result_.reset(volume_info);
1504 // Localising mount path. 1466 // Localising mount path.
1505 std::string mount_path; 1467 std::string mount_path;
1506 if (!volume->mount_path().empty()) { 1468 if (!volume->mount_path().empty()) {
1507 FilePath relative_mount_path; 1469 FilePath relative_mount_path;
1508 FileManagerUtil::ConvertFileToRelativeFileSystemPath(profile_, 1470 FileManagerUtil::ConvertFileToRelativeFileSystemPath(profile_,
1509 FilePath(volume->mount_path()), &relative_mount_path); 1471 FilePath(volume->mount_path()), &relative_mount_path);
1510 mount_path = relative_mount_path.value(); 1472 mount_path = relative_mount_path.value();
1511 } 1473 }
1512 volume_info->SetString("devicePath", volume->device_path()); 1474 volume_info->SetString("devicePath", volume->device_path());
1513 volume_info->SetString("mountPath", mount_path); 1475 volume_info->SetString("mountPath", mount_path);
1514 volume_info->SetString("systemPath", volume->system_path()); 1476 volume_info->SetString("systemPath", volume->system_path());
1515 volume_info->SetString("filePath", volume->file_path()); 1477 volume_info->SetString("filePath", volume->file_path());
1516 volume_info->SetString("deviceLabel", volume->device_label()); 1478 volume_info->SetString("deviceLabel", volume->device_label());
1517 volume_info->SetString("driveLabel", volume->drive_label()); 1479 volume_info->SetString("driveLabel", volume->drive_label());
1518 volume_info->SetString("deviceType", 1480 volume_info->SetString("deviceType",
1519 DeviceTypeToString(volume->device_type())); 1481 DeviceTypeToString(volume->device_type()));
1520 volume_info->SetInteger("totalSize", volume->total_size()); 1482 volume_info->SetInteger("totalSize", volume->total_size_in_bytes());
1521 volume_info->SetBoolean("isParent", volume->is_parent()); 1483 volume_info->SetBoolean("isParent", volume->is_parent());
1522 volume_info->SetBoolean("isReadOnly", volume->is_read_only()); 1484 volume_info->SetBoolean("isReadOnly", volume->is_read_only());
1523 volume_info->SetBoolean("hasMedia", volume->has_media()); 1485 volume_info->SetBoolean("hasMedia", volume->has_media());
1524 volume_info->SetBoolean("isOnBootDevice", volume->on_boot_device()); 1486 volume_info->SetBoolean("isOnBootDevice", volume->on_boot_device());
1525 1487
1526 return true; 1488 return true;
1527 } 1489 }
1528 #endif 1490 #endif
1529 error_ = kVolumeDevicePathNotFound; 1491 error_ = kVolumeDevicePathNotFound;
1530 return false; 1492 return false;
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
1715 l10n_util::GetStringUTF16(IDS_CERT_MANAGER_VIEW_CERT_BUTTON)); 1677 l10n_util::GetStringUTF16(IDS_CERT_MANAGER_VIEW_CERT_BUTTON));
1716 dict->SetString("PLAY_MEDIA", 1678 dict->SetString("PLAY_MEDIA",
1717 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_PLAY)); 1679 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_PLAY));
1718 #if defined(OS_CHROMEOS) 1680 #if defined(OS_CHROMEOS)
1719 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnablePhotoEditor)) 1681 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnablePhotoEditor))
1720 dict->SetString("ENABLE_PHOTO_EDITOR", "true"); 1682 dict->SetString("ENABLE_PHOTO_EDITOR", "true");
1721 #endif 1683 #endif
1722 1684
1723 return true; 1685 return true;
1724 } 1686 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698