OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_browser_private_api.h" | 5 #include "chrome/browser/chromeos/extensions/file_browser_private_api.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/base64.h" | 9 #include "base/base64.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 883 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
894 | 894 |
895 if (!CrackFileSystemURL(file_url, &file_origin_url, &type, | 895 if (!CrackFileSystemURL(file_url, &file_origin_url, &type, |
896 &virtual_path)) { | 896 &virtual_path)) { |
897 continue; | 897 continue; |
898 } | 898 } |
899 if (type != fileapi::kFileSystemTypeExternal) { | 899 if (type != fileapi::kFileSystemTypeExternal) { |
900 NOTREACHED(); | 900 NOTREACHED(); |
901 continue; | 901 continue; |
902 } | 902 } |
903 | 903 |
904 FilePath::StringType display_name; | |
905 FilePath root = provider->GetFileSystemRootPathOnFileThread( | 904 FilePath root = provider->GetFileSystemRootPathOnFileThread( |
906 origin_url, | 905 origin_url, |
907 fileapi::kFileSystemTypeExternal, | 906 fileapi::kFileSystemTypeExternal, |
908 FilePath(virtual_path), | 907 FilePath(virtual_path), |
909 false); | 908 false); |
| 909 FilePath file_path; |
910 if (!root.empty()) { | 910 if (!root.empty()) { |
911 // If we haven't got the real path from "localPath", use it as the | 911 file_path = root.Append(virtual_path); |
912 // real path. Otherwise, use it as the display name. | |
913 if (real_path.empty()) | |
914 real_path = root.Append(virtual_path); | |
915 else | |
916 display_name = virtual_path.BaseName().value(); | |
917 } else { | 912 } else { |
918 LOG(WARNING) << "GetLocalPathsOnFileThread failed " | 913 LOG(WARNING) << "GetLocalPathsOnFileThread failed " |
919 << file_url.spec(); | 914 << file_url.spec(); |
920 } | 915 } |
921 | 916 |
922 if (!real_path.empty()) { | 917 if (!file_path.empty()) { |
923 DVLOG(1) << "Selected: real path: " << real_path.value() | 918 DVLOG(1) << "Selected: file path: " << file_path.value() |
924 << " display name: " << display_name; | 919 << " real path: " << real_path.value(); |
925 selected_files.push_back( | 920 selected_files.push_back( |
926 ui::SelectedFileInfo(real_path, display_name)); | 921 ui::SelectedFileInfo(file_path, real_path)); |
927 } | 922 } |
928 } | 923 } |
929 | 924 |
930 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 925 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
931 base::Bind(callback, selected_files)); | 926 base::Bind(callback, selected_files)); |
932 } | 927 } |
933 | 928 |
934 bool SelectFileFunction::RunImpl() { | 929 bool SelectFileFunction::RunImpl() { |
935 if (args_->GetSize() != 2) { | 930 if (args_->GetSize() != 2) { |
936 return false; | 931 return false; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
998 | 993 |
999 void ViewFilesFunction::GetLocalPathsResponseOnUIThread( | 994 void ViewFilesFunction::GetLocalPathsResponseOnUIThread( |
1000 const std::string& internal_task_id, | 995 const std::string& internal_task_id, |
1001 const SelectedFileInfoList& files) { | 996 const SelectedFileInfoList& files) { |
1002 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 997 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1003 bool success = true; | 998 bool success = true; |
1004 for (SelectedFileInfoList::const_iterator iter = files.begin(); | 999 for (SelectedFileInfoList::const_iterator iter = files.begin(); |
1005 iter != files.end(); | 1000 iter != files.end(); |
1006 ++iter) { | 1001 ++iter) { |
1007 bool handled = file_manager_util::ExecuteBuiltinHandler( | 1002 bool handled = file_manager_util::ExecuteBuiltinHandler( |
1008 GetCurrentBrowser(), iter->path, internal_task_id); | 1003 GetCurrentBrowser(), iter->file_path, internal_task_id); |
1009 if (!handled && files.size() == 1) | 1004 if (!handled && files.size() == 1) |
1010 success = false; | 1005 success = false; |
1011 } | 1006 } |
1012 SetResult(Value::CreateBooleanValue(success)); | 1007 SetResult(Value::CreateBooleanValue(success)); |
1013 SendResponse(true); | 1008 SendResponse(true); |
1014 } | 1009 } |
1015 | 1010 |
1016 SelectFilesFunction::SelectFilesFunction() { | 1011 SelectFilesFunction::SelectFilesFunction() { |
1017 } | 1012 } |
1018 | 1013 |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1148 void AddMountFunction::GetLocalPathsResponseOnUIThread( | 1143 void AddMountFunction::GetLocalPathsResponseOnUIThread( |
1149 const std::string& mount_type_str, | 1144 const std::string& mount_type_str, |
1150 const SelectedFileInfoList& files) { | 1145 const SelectedFileInfoList& files) { |
1151 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1146 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1152 | 1147 |
1153 if (!files.size()) { | 1148 if (!files.size()) { |
1154 SendResponse(false); | 1149 SendResponse(false); |
1155 return; | 1150 return; |
1156 } | 1151 } |
1157 | 1152 |
1158 const FilePath& source_path = files[0].path; | 1153 const FilePath& source_path = files[0].real_path; |
1159 const FilePath::StringType& display_name = files[0].display_name; | 1154 const FilePath::StringType& display_name = |
| 1155 files[0].file_path.BaseName().value(); |
1160 // Check if the source path is under GData cache directory. | 1156 // Check if the source path is under GData cache directory. |
1161 gdata::GDataSystemService* system_service = | 1157 gdata::GDataSystemService* system_service = |
1162 gdata::GDataSystemServiceFactory::GetForProfile(profile_); | 1158 gdata::GDataSystemServiceFactory::GetForProfile(profile_); |
1163 gdata::GDataCache* cache = system_service ? system_service->cache() : NULL; | 1159 gdata::GDataCache* cache = system_service ? system_service->cache() : NULL; |
1164 if (cache && cache->IsUnderGDataCacheDirectory(source_path)) { | 1160 if (cache && cache->IsUnderGDataCacheDirectory(source_path)) { |
1165 cache->SetMountedStateOnUIThread( | 1161 cache->SetMountedStateOnUIThread( |
1166 source_path, | 1162 source_path, |
1167 true, | 1163 true, |
1168 base::Bind(&AddMountFunction::OnMountedStateSet, this, mount_type_str, | 1164 base::Bind(&AddMountFunction::OnMountedStateSet, this, mount_type_str, |
1169 display_name)); | 1165 display_name)); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1214 } | 1210 } |
1215 | 1211 |
1216 void RemoveMountFunction::GetLocalPathsResponseOnUIThread( | 1212 void RemoveMountFunction::GetLocalPathsResponseOnUIThread( |
1217 const SelectedFileInfoList& files) { | 1213 const SelectedFileInfoList& files) { |
1218 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1214 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1219 | 1215 |
1220 if (files.size() != 1) { | 1216 if (files.size() != 1) { |
1221 SendResponse(false); | 1217 SendResponse(false); |
1222 return; | 1218 return; |
1223 } | 1219 } |
1224 DiskMountManager::GetInstance()->UnmountPath(files[0].path.value()); | 1220 DiskMountManager::GetInstance()->UnmountPath(files[0].real_path.value()); |
1225 SendResponse(true); | 1221 SendResponse(true); |
1226 } | 1222 } |
1227 | 1223 |
1228 GetMountPointsFunction::GetMountPointsFunction() { | 1224 GetMountPointsFunction::GetMountPointsFunction() { |
1229 } | 1225 } |
1230 | 1226 |
1231 GetMountPointsFunction::~GetMountPointsFunction() { | 1227 GetMountPointsFunction::~GetMountPointsFunction() { |
1232 } | 1228 } |
1233 | 1229 |
1234 bool GetMountPointsFunction::RunImpl() { | 1230 bool GetMountPointsFunction::RunImpl() { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1280 | 1276 |
1281 void GetSizeStatsFunction::GetLocalPathsResponseOnUIThread( | 1277 void GetSizeStatsFunction::GetLocalPathsResponseOnUIThread( |
1282 const SelectedFileInfoList& files) { | 1278 const SelectedFileInfoList& files) { |
1283 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1279 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1284 | 1280 |
1285 if (files.size() != 1) { | 1281 if (files.size() != 1) { |
1286 SendResponse(false); | 1282 SendResponse(false); |
1287 return; | 1283 return; |
1288 } | 1284 } |
1289 | 1285 |
1290 if (files[0].path == gdata::util::GetGDataMountPointPath()) { | 1286 if (files[0].file_path == gdata::util::GetGDataMountPointPath()) { |
1291 gdata::GDataSystemService* system_service = | 1287 gdata::GDataSystemService* system_service = |
1292 gdata::GDataSystemServiceFactory::GetForProfile(profile_); | 1288 gdata::GDataSystemServiceFactory::GetForProfile(profile_); |
1293 | 1289 |
1294 gdata::GDataFileSystemInterface* file_system = | 1290 gdata::GDataFileSystemInterface* file_system = |
1295 system_service->file_system(); | 1291 system_service->file_system(); |
1296 | 1292 |
1297 file_system->GetAvailableSpace( | 1293 file_system->GetAvailableSpace( |
1298 base::Bind(&GetSizeStatsFunction::GetGDataAvailableSpaceCallback, | 1294 base::Bind(&GetSizeStatsFunction::GetGDataAvailableSpaceCallback, |
1299 this)); | 1295 this)); |
1300 | 1296 |
1301 } else { | 1297 } else { |
1302 BrowserThread::PostTask( | 1298 BrowserThread::PostTask( |
1303 BrowserThread::FILE, FROM_HERE, | 1299 BrowserThread::FILE, FROM_HERE, |
1304 base::Bind( | 1300 base::Bind( |
1305 &GetSizeStatsFunction::CallGetSizeStatsOnFileThread, | 1301 &GetSizeStatsFunction::CallGetSizeStatsOnFileThread, |
1306 this, | 1302 this, |
1307 files[0].path.value())); | 1303 files[0].file_path.value())); |
1308 } | 1304 } |
1309 } | 1305 } |
1310 | 1306 |
1311 void GetSizeStatsFunction::GetGDataAvailableSpaceCallback( | 1307 void GetSizeStatsFunction::GetGDataAvailableSpaceCallback( |
1312 gdata::GDataFileError error, | 1308 gdata::GDataFileError error, |
1313 int64 bytes_total, | 1309 int64 bytes_total, |
1314 int64 bytes_used) { | 1310 int64 bytes_used) { |
1315 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1311 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1316 | 1312 |
1317 if (error == gdata::GDATA_FILE_OK) { | 1313 if (error == gdata::GDATA_FILE_OK) { |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1383 | 1379 |
1384 void FormatDeviceFunction::GetLocalPathsResponseOnUIThread( | 1380 void FormatDeviceFunction::GetLocalPathsResponseOnUIThread( |
1385 const SelectedFileInfoList& files) { | 1381 const SelectedFileInfoList& files) { |
1386 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1382 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1387 | 1383 |
1388 if (files.size() != 1) { | 1384 if (files.size() != 1) { |
1389 SendResponse(false); | 1385 SendResponse(false); |
1390 return; | 1386 return; |
1391 } | 1387 } |
1392 | 1388 |
1393 DiskMountManager::GetInstance()->FormatMountedDevice(files[0].path.value()); | 1389 DiskMountManager::GetInstance()->FormatMountedDevice( |
| 1390 files[0].file_path.value()); |
1394 SendResponse(true); | 1391 SendResponse(true); |
1395 } | 1392 } |
1396 | 1393 |
1397 GetVolumeMetadataFunction::GetVolumeMetadataFunction() { | 1394 GetVolumeMetadataFunction::GetVolumeMetadataFunction() { |
1398 } | 1395 } |
1399 | 1396 |
1400 GetVolumeMetadataFunction::~GetVolumeMetadataFunction() { | 1397 GetVolumeMetadataFunction::~GetVolumeMetadataFunction() { |
1401 } | 1398 } |
1402 | 1399 |
1403 bool GetVolumeMetadataFunction::RunImpl() { | 1400 bool GetVolumeMetadataFunction::RunImpl() { |
(...skipping 25 matching lines...) Expand all Loading... |
1429 // Should contain volume's mount path. | 1426 // Should contain volume's mount path. |
1430 if (files.size() != 1) { | 1427 if (files.size() != 1) { |
1431 error_ = "Invalid mount path."; | 1428 error_ = "Invalid mount path."; |
1432 SendResponse(false); | 1429 SendResponse(false); |
1433 return; | 1430 return; |
1434 } | 1431 } |
1435 | 1432 |
1436 results_.reset(); | 1433 results_.reset(); |
1437 | 1434 |
1438 const DiskMountManager::Disk* volume = GetVolumeAsDisk( | 1435 const DiskMountManager::Disk* volume = GetVolumeAsDisk( |
1439 files[0].path.value()); | 1436 files[0].file_path.value()); |
1440 if (volume) { | 1437 if (volume) { |
1441 DictionaryValue* volume_info = | 1438 DictionaryValue* volume_info = |
1442 CreateValueFromDisk(profile_, volume); | 1439 CreateValueFromDisk(profile_, volume); |
1443 SetResult(volume_info); | 1440 SetResult(volume_info); |
1444 } | 1441 } |
1445 | 1442 |
1446 SendResponse(true); | 1443 SendResponse(true); |
1447 } | 1444 } |
1448 | 1445 |
1449 bool ToggleFullscreenFunction::RunImpl() { | 1446 bool ToggleFullscreenFunction::RunImpl() { |
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1988 this)); | 1985 this)); |
1989 return true; | 1986 return true; |
1990 } | 1987 } |
1991 | 1988 |
1992 void GetFileLocationsFunction::GetLocalPathsResponseOnUIThread( | 1989 void GetFileLocationsFunction::GetLocalPathsResponseOnUIThread( |
1993 const SelectedFileInfoList& files) { | 1990 const SelectedFileInfoList& files) { |
1994 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1991 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1995 | 1992 |
1996 ListValue* locations = new ListValue; | 1993 ListValue* locations = new ListValue; |
1997 for (size_t i = 0; i < files.size(); ++i) { | 1994 for (size_t i = 0; i < files.size(); ++i) { |
1998 if (gdata::util::IsUnderGDataMountPoint(files[i].path)) { | 1995 if (gdata::util::IsUnderGDataMountPoint(files[i].file_path)) { |
1999 locations->Append(Value::CreateStringValue("drive")); | 1996 locations->Append(Value::CreateStringValue("drive")); |
2000 } else { | 1997 } else { |
2001 locations->Append(Value::CreateStringValue("local")); | 1998 locations->Append(Value::CreateStringValue("local")); |
2002 } | 1999 } |
2003 } | 2000 } |
2004 | 2001 |
2005 SetResult(locations); | 2002 SetResult(locations); |
2006 SendResponse(true); | 2003 SendResponse(true); |
2007 } | 2004 } |
2008 | 2005 |
(...skipping 23 matching lines...) Expand all Loading... |
2032 base::Bind(&GetGDataFilesFunction::GetLocalPathsResponseOnUIThread, | 2029 base::Bind(&GetGDataFilesFunction::GetLocalPathsResponseOnUIThread, |
2033 this)); | 2030 this)); |
2034 return true; | 2031 return true; |
2035 } | 2032 } |
2036 | 2033 |
2037 void GetGDataFilesFunction::GetLocalPathsResponseOnUIThread( | 2034 void GetGDataFilesFunction::GetLocalPathsResponseOnUIThread( |
2038 const SelectedFileInfoList& files) { | 2035 const SelectedFileInfoList& files) { |
2039 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2036 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2040 | 2037 |
2041 for (size_t i = 0; i < files.size(); ++i) { | 2038 for (size_t i = 0; i < files.size(); ++i) { |
2042 DCHECK(gdata::util::IsUnderGDataMountPoint(files[i].path)); | 2039 DCHECK(gdata::util::IsUnderGDataMountPoint(files[i].file_path)); |
2043 FilePath gdata_path = gdata::util::ExtractGDataPath(files[i].path); | 2040 FilePath gdata_path = gdata::util::ExtractGDataPath(files[i].file_path); |
2044 remaining_gdata_paths_.push(gdata_path); | 2041 remaining_gdata_paths_.push(gdata_path); |
2045 } | 2042 } |
2046 | 2043 |
2047 local_paths_ = new ListValue; | 2044 local_paths_ = new ListValue; |
2048 GetFileOrSendResponse(); | 2045 GetFileOrSendResponse(); |
2049 } | 2046 } |
2050 | 2047 |
2051 void GetGDataFilesFunction::GetFileOrSendResponse() { | 2048 void GetGDataFilesFunction::GetFileOrSendResponse() { |
2052 // Send the response if all files are obtained. | 2049 // Send the response if all files are obtained. |
2053 if (remaining_gdata_paths_.empty()) { | 2050 if (remaining_gdata_paths_.empty()) { |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2162 if (!system_service) { | 2159 if (!system_service) { |
2163 SendResponse(false); | 2160 SendResponse(false); |
2164 return; | 2161 return; |
2165 } | 2162 } |
2166 | 2163 |
2167 gdata::GDataOperationRegistry* operation_registry = | 2164 gdata::GDataOperationRegistry* operation_registry = |
2168 system_service->docs_service()->operation_registry(); | 2165 system_service->docs_service()->operation_registry(); |
2169 | 2166 |
2170 scoped_ptr<ListValue> responses(new ListValue()); | 2167 scoped_ptr<ListValue> responses(new ListValue()); |
2171 for (size_t i = 0; i < files.size(); ++i) { | 2168 for (size_t i = 0; i < files.size(); ++i) { |
2172 DCHECK(gdata::util::IsUnderGDataMountPoint(files[i].path)); | 2169 DCHECK(gdata::util::IsUnderGDataMountPoint(files[i].file_path)); |
2173 FilePath file_path = gdata::util::ExtractGDataPath(files[i].path); | 2170 FilePath file_path = gdata::util::ExtractGDataPath(files[i].file_path); |
2174 scoped_ptr<DictionaryValue> result(new DictionaryValue()); | 2171 scoped_ptr<DictionaryValue> result(new DictionaryValue()); |
2175 result->SetBoolean( | 2172 result->SetBoolean( |
2176 "canceled", | 2173 "canceled", |
2177 operation_registry->CancelForFilePath(file_path)); | 2174 operation_registry->CancelForFilePath(file_path)); |
2178 GURL file_url; | 2175 GURL file_url; |
2179 if (file_manager_util::ConvertFileToFileSystemUrl(profile_, | 2176 if (file_manager_util::ConvertFileToFileSystemUrl(profile_, |
2180 gdata::util::GetSpecialRemoteRootPath().Append(file_path), | 2177 gdata::util::GetSpecialRemoteRootPath().Append(file_path), |
2181 source_url_.GetOrigin(), | 2178 source_url_.GetOrigin(), |
2182 &file_url)) { | 2179 &file_url)) { |
2183 result->SetString("fileUrl", file_url.spec()); | 2180 result->SetString("fileUrl", file_url.spec()); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2220 return; | 2217 return; |
2221 } | 2218 } |
2222 | 2219 |
2223 gdata::GDataSystemService* system_service = | 2220 gdata::GDataSystemService* system_service = |
2224 gdata::GDataSystemServiceFactory::GetForProfile(profile_); | 2221 gdata::GDataSystemServiceFactory::GetForProfile(profile_); |
2225 if (!system_service) { | 2222 if (!system_service) { |
2226 SendResponse(false); | 2223 SendResponse(false); |
2227 return; | 2224 return; |
2228 } | 2225 } |
2229 | 2226 |
2230 FilePath source_file = files[0].path; | 2227 FilePath source_file = files[0].file_path; |
2231 FilePath destination_file = files[1].path; | 2228 FilePath destination_file = files[1].file_path; |
2232 | 2229 |
2233 bool source_file_under_gdata = | 2230 bool source_file_under_gdata = |
2234 gdata::util::IsUnderGDataMountPoint(source_file); | 2231 gdata::util::IsUnderGDataMountPoint(source_file); |
2235 bool destination_file_under_gdata = | 2232 bool destination_file_under_gdata = |
2236 gdata::util::IsUnderGDataMountPoint(destination_file); | 2233 gdata::util::IsUnderGDataMountPoint(destination_file); |
2237 | 2234 |
2238 if (source_file_under_gdata && !destination_file_under_gdata) { | 2235 if (source_file_under_gdata && !destination_file_under_gdata) { |
2239 // Transfer a file from gdata to local file system. | 2236 // Transfer a file from gdata to local file system. |
2240 source_file = gdata::util::ExtractGDataPath(source_file); | 2237 source_file = gdata::util::ExtractGDataPath(source_file); |
2241 system_service->file_system()->TransferFileFromRemoteToLocal( | 2238 system_service->file_system()->TransferFileFromRemoteToLocal( |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2406 gdata::GDataSystemService* system_service = | 2403 gdata::GDataSystemService* system_service = |
2407 gdata::GDataSystemServiceFactory::GetForProfile(profile_); | 2404 gdata::GDataSystemServiceFactory::GetForProfile(profile_); |
2408 if (!system_service || !system_service->file_system()) | 2405 if (!system_service || !system_service->file_system()) |
2409 return false; | 2406 return false; |
2410 | 2407 |
2411 FilePath directory_path = GetVirtualPathFromURL(GURL(file_url_as_string)); | 2408 FilePath directory_path = GetVirtualPathFromURL(GURL(file_url_as_string)); |
2412 system_service->file_system()->RequestDirectoryRefresh(directory_path); | 2409 system_service->file_system()->RequestDirectoryRefresh(directory_path); |
2413 | 2410 |
2414 return true; | 2411 return true; |
2415 } | 2412 } |
OLD | NEW |