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

Side by Side Diff: chrome/browser/chromeos/extensions/file_browser_private_api.cc

Issue 10804026: Fix open dialog not remembering last opened folder on drive (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (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
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
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
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
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
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
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
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 536 matching lines...) Expand 10 before | Expand all | Expand 10 after
1986 this)); 1983 this));
1987 return true; 1984 return true;
1988 } 1985 }
1989 1986
1990 void GetFileLocationsFunction::GetLocalPathsResponseOnUIThread( 1987 void GetFileLocationsFunction::GetLocalPathsResponseOnUIThread(
1991 const SelectedFileInfoList& files) { 1988 const SelectedFileInfoList& files) {
1992 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1989 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1993 1990
1994 ListValue* locations = new ListValue; 1991 ListValue* locations = new ListValue;
1995 for (size_t i = 0; i < files.size(); ++i) { 1992 for (size_t i = 0; i < files.size(); ++i) {
1996 if (gdata::util::IsUnderGDataMountPoint(files[i].path)) { 1993 if (gdata::util::IsUnderGDataMountPoint(files[i].file_path)) {
1997 locations->Append(Value::CreateStringValue("drive")); 1994 locations->Append(Value::CreateStringValue("drive"));
1998 } else { 1995 } else {
1999 locations->Append(Value::CreateStringValue("local")); 1996 locations->Append(Value::CreateStringValue("local"));
2000 } 1997 }
2001 } 1998 }
2002 1999
2003 SetResult(locations); 2000 SetResult(locations);
2004 SendResponse(true); 2001 SendResponse(true);
2005 } 2002 }
2006 2003
(...skipping 23 matching lines...) Expand all
2030 base::Bind(&GetGDataFilesFunction::GetLocalPathsResponseOnUIThread, 2027 base::Bind(&GetGDataFilesFunction::GetLocalPathsResponseOnUIThread,
2031 this)); 2028 this));
2032 return true; 2029 return true;
2033 } 2030 }
2034 2031
2035 void GetGDataFilesFunction::GetLocalPathsResponseOnUIThread( 2032 void GetGDataFilesFunction::GetLocalPathsResponseOnUIThread(
2036 const SelectedFileInfoList& files) { 2033 const SelectedFileInfoList& files) {
2037 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2034 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2038 2035
2039 for (size_t i = 0; i < files.size(); ++i) { 2036 for (size_t i = 0; i < files.size(); ++i) {
2040 DCHECK(gdata::util::IsUnderGDataMountPoint(files[i].path)); 2037 DCHECK(gdata::util::IsUnderGDataMountPoint(files[i].file_path));
2041 FilePath gdata_path = gdata::util::ExtractGDataPath(files[i].path); 2038 FilePath gdata_path = gdata::util::ExtractGDataPath(files[i].file_path);
2042 remaining_gdata_paths_.push(gdata_path); 2039 remaining_gdata_paths_.push(gdata_path);
2043 } 2040 }
2044 2041
2045 local_paths_ = new ListValue; 2042 local_paths_ = new ListValue;
2046 GetFileOrSendResponse(); 2043 GetFileOrSendResponse();
2047 } 2044 }
2048 2045
2049 void GetGDataFilesFunction::GetFileOrSendResponse() { 2046 void GetGDataFilesFunction::GetFileOrSendResponse() {
2050 // Send the response if all files are obtained. 2047 // Send the response if all files are obtained.
2051 if (remaining_gdata_paths_.empty()) { 2048 if (remaining_gdata_paths_.empty()) {
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
2160 if (!system_service) { 2157 if (!system_service) {
2161 SendResponse(false); 2158 SendResponse(false);
2162 return; 2159 return;
2163 } 2160 }
2164 2161
2165 gdata::GDataOperationRegistry* operation_registry = 2162 gdata::GDataOperationRegistry* operation_registry =
2166 system_service->docs_service()->operation_registry(); 2163 system_service->docs_service()->operation_registry();
2167 2164
2168 scoped_ptr<ListValue> responses(new ListValue()); 2165 scoped_ptr<ListValue> responses(new ListValue());
2169 for (size_t i = 0; i < files.size(); ++i) { 2166 for (size_t i = 0; i < files.size(); ++i) {
2170 DCHECK(gdata::util::IsUnderGDataMountPoint(files[i].path)); 2167 DCHECK(gdata::util::IsUnderGDataMountPoint(files[i].file_path));
2171 FilePath file_path = gdata::util::ExtractGDataPath(files[i].path); 2168 FilePath file_path = gdata::util::ExtractGDataPath(files[i].file_path);
2172 scoped_ptr<DictionaryValue> result(new DictionaryValue()); 2169 scoped_ptr<DictionaryValue> result(new DictionaryValue());
2173 result->SetBoolean( 2170 result->SetBoolean(
2174 "canceled", 2171 "canceled",
2175 operation_registry->CancelForFilePath(file_path)); 2172 operation_registry->CancelForFilePath(file_path));
2176 GURL file_url; 2173 GURL file_url;
2177 if (file_manager_util::ConvertFileToFileSystemUrl(profile_, 2174 if (file_manager_util::ConvertFileToFileSystemUrl(profile_,
2178 gdata::util::GetSpecialRemoteRootPath().Append(file_path), 2175 gdata::util::GetSpecialRemoteRootPath().Append(file_path),
2179 source_url_.GetOrigin(), 2176 source_url_.GetOrigin(),
2180 &file_url)) { 2177 &file_url)) {
2181 result->SetString("fileUrl", file_url.spec()); 2178 result->SetString("fileUrl", file_url.spec());
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
2218 return; 2215 return;
2219 } 2216 }
2220 2217
2221 gdata::GDataSystemService* system_service = 2218 gdata::GDataSystemService* system_service =
2222 gdata::GDataSystemServiceFactory::GetForProfile(profile_); 2219 gdata::GDataSystemServiceFactory::GetForProfile(profile_);
2223 if (!system_service) { 2220 if (!system_service) {
2224 SendResponse(false); 2221 SendResponse(false);
2225 return; 2222 return;
2226 } 2223 }
2227 2224
2228 FilePath source_file = files[0].path; 2225 FilePath source_file = files[0].file_path;
2229 FilePath destination_file = files[1].path; 2226 FilePath destination_file = files[1].file_path;
2230 2227
2231 bool source_file_under_gdata = 2228 bool source_file_under_gdata =
2232 gdata::util::IsUnderGDataMountPoint(source_file); 2229 gdata::util::IsUnderGDataMountPoint(source_file);
2233 bool destination_file_under_gdata = 2230 bool destination_file_under_gdata =
2234 gdata::util::IsUnderGDataMountPoint(destination_file); 2231 gdata::util::IsUnderGDataMountPoint(destination_file);
2235 2232
2236 if (source_file_under_gdata && !destination_file_under_gdata) { 2233 if (source_file_under_gdata && !destination_file_under_gdata) {
2237 // Transfer a file from gdata to local file system. 2234 // Transfer a file from gdata to local file system.
2238 source_file = gdata::util::ExtractGDataPath(source_file); 2235 source_file = gdata::util::ExtractGDataPath(source_file);
2239 system_service->file_system()->TransferFileFromRemoteToLocal( 2236 system_service->file_system()->TransferFileFromRemoteToLocal(
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
2404 gdata::GDataSystemService* system_service = 2401 gdata::GDataSystemService* system_service =
2405 gdata::GDataSystemServiceFactory::GetForProfile(profile_); 2402 gdata::GDataSystemServiceFactory::GetForProfile(profile_);
2406 if (!system_service || !system_service->file_system()) 2403 if (!system_service || !system_service->file_system())
2407 return false; 2404 return false;
2408 2405
2409 FilePath directory_path = GetVirtualPathFromURL(GURL(file_url_as_string)); 2406 FilePath directory_path = GetVirtualPathFromURL(GURL(file_url_as_string));
2410 system_service->file_system()->RequestDirectoryRefresh(directory_path); 2407 system_service->file_system()->RequestDirectoryRefresh(directory_path);
2411 2408
2412 return true; 2409 return true;
2413 } 2410 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698