| 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 <sys/stat.h> | 7 #include <sys/stat.h> |
| 8 #include <sys/statvfs.h> | 8 #include <sys/statvfs.h> |
| 9 #include <sys/types.h> | 9 #include <sys/types.h> |
| 10 #include <utime.h> | 10 #include <utime.h> |
| (...skipping 1328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1339 if (!args_->GetString(0, &file_url)) { | 1339 if (!args_->GetString(0, &file_url)) { |
| 1340 return false; | 1340 return false; |
| 1341 } | 1341 } |
| 1342 | 1342 |
| 1343 std::string mount_type_str; | 1343 std::string mount_type_str; |
| 1344 if (!args_->GetString(1, &mount_type_str)) { | 1344 if (!args_->GetString(1, &mount_type_str)) { |
| 1345 return false; | 1345 return false; |
| 1346 } | 1346 } |
| 1347 | 1347 |
| 1348 // Set default return source path to the empty string. | 1348 // Set default return source path to the empty string. |
| 1349 SetResult(Value::CreateStringValue("")); | 1349 SetResult(new base::StringValue("")); |
| 1350 | 1350 |
| 1351 chromeos::MountType mount_type = | 1351 chromeos::MountType mount_type = |
| 1352 DiskMountManager::MountTypeFromString(mount_type_str); | 1352 DiskMountManager::MountTypeFromString(mount_type_str); |
| 1353 switch (mount_type) { | 1353 switch (mount_type) { |
| 1354 case chromeos::MOUNT_TYPE_INVALID: { | 1354 case chromeos::MOUNT_TYPE_INVALID: { |
| 1355 error_ = "Invalid mount type"; | 1355 error_ = "Invalid mount type"; |
| 1356 SendResponse(false); | 1356 SendResponse(false); |
| 1357 break; | 1357 break; |
| 1358 } | 1358 } |
| 1359 case chromeos::MOUNT_TYPE_GDATA: { | 1359 case chromeos::MOUNT_TYPE_GDATA: { |
| 1360 const bool success = true; | 1360 const bool success = true; |
| 1361 // Pass back the drive mount point path as source path. | 1361 // Pass back the drive mount point path as source path. |
| 1362 const std::string& drive_path = | 1362 const std::string& drive_path = |
| 1363 drive::util::GetDriveMountPointPathAsString(); | 1363 drive::util::GetDriveMountPointPathAsString(); |
| 1364 SetResult(Value::CreateStringValue(drive_path)); | 1364 SetResult(new base::StringValue(drive_path)); |
| 1365 FileBrowserEventRouterFactory::GetForProfile(profile_)-> | 1365 FileBrowserEventRouterFactory::GetForProfile(profile_)-> |
| 1366 MountDrive(base::Bind(&AddMountFunction::SendResponse, | 1366 MountDrive(base::Bind(&AddMountFunction::SendResponse, |
| 1367 this, | 1367 this, |
| 1368 success)); | 1368 success)); |
| 1369 break; | 1369 break; |
| 1370 } | 1370 } |
| 1371 default: { | 1371 default: { |
| 1372 UrlList file_paths; | 1372 UrlList file_paths; |
| 1373 file_paths.push_back(GURL(file_url)); | 1373 file_paths.push_back(GURL(file_url)); |
| 1374 | 1374 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1412 } | 1412 } |
| 1413 } | 1413 } |
| 1414 | 1414 |
| 1415 void AddMountFunction::OnMountedStateSet(const std::string& mount_type, | 1415 void AddMountFunction::OnMountedStateSet(const std::string& mount_type, |
| 1416 const FilePath::StringType& file_name, | 1416 const FilePath::StringType& file_name, |
| 1417 drive::DriveFileError error, | 1417 drive::DriveFileError error, |
| 1418 const FilePath& file_path) { | 1418 const FilePath& file_path) { |
| 1419 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1419 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1420 DiskMountManager* disk_mount_manager = DiskMountManager::GetInstance(); | 1420 DiskMountManager* disk_mount_manager = DiskMountManager::GetInstance(); |
| 1421 // Pass back the actual source path of the mount point. | 1421 // Pass back the actual source path of the mount point. |
| 1422 SetResult(Value::CreateStringValue(file_path.value())); | 1422 SetResult(new base::StringValue(file_path.value())); |
| 1423 SendResponse(true); | 1423 SendResponse(true); |
| 1424 // MountPath() takes a std::string. | 1424 // MountPath() takes a std::string. |
| 1425 disk_mount_manager->MountPath(file_path.AsUTF8Unsafe(), | 1425 disk_mount_manager->MountPath(file_path.AsUTF8Unsafe(), |
| 1426 FilePath(file_name).Extension(), file_name, | 1426 FilePath(file_name).Extension(), file_name, |
| 1427 DiskMountManager::MountTypeFromString( | 1427 DiskMountManager::MountTypeFromString( |
| 1428 mount_type)); | 1428 mount_type)); |
| 1429 } | 1429 } |
| 1430 | 1430 |
| 1431 RemoveMountFunction::RemoveMountFunction() { | 1431 RemoveMountFunction::RemoveMountFunction() { |
| 1432 } | 1432 } |
| (...skipping 987 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2420 return true; | 2420 return true; |
| 2421 } | 2421 } |
| 2422 | 2422 |
| 2423 void GetFileLocationsFunction::GetLocalPathsResponseOnUIThread( | 2423 void GetFileLocationsFunction::GetLocalPathsResponseOnUIThread( |
| 2424 const SelectedFileInfoList& files) { | 2424 const SelectedFileInfoList& files) { |
| 2425 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2425 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 2426 | 2426 |
| 2427 ListValue* locations = new ListValue; | 2427 ListValue* locations = new ListValue; |
| 2428 for (size_t i = 0; i < files.size(); ++i) { | 2428 for (size_t i = 0; i < files.size(); ++i) { |
| 2429 if (drive::util::IsUnderDriveMountPoint(files[i].file_path)) { | 2429 if (drive::util::IsUnderDriveMountPoint(files[i].file_path)) { |
| 2430 locations->Append(Value::CreateStringValue("drive")); | 2430 locations->Append(new base::StringValue("drive")); |
| 2431 } else { | 2431 } else { |
| 2432 locations->Append(Value::CreateStringValue("local")); | 2432 locations->Append(new base::StringValue("local")); |
| 2433 } | 2433 } |
| 2434 } | 2434 } |
| 2435 | 2435 |
| 2436 SetResult(locations); | 2436 SetResult(locations); |
| 2437 SendResponse(true); | 2437 SendResponse(true); |
| 2438 } | 2438 } |
| 2439 | 2439 |
| 2440 GetDriveFilesFunction::GetDriveFilesFunction() | 2440 GetDriveFilesFunction::GetDriveFilesFunction() |
| 2441 : local_paths_(NULL) { | 2441 : local_paths_(NULL) { |
| 2442 } | 2442 } |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2509 | 2509 |
| 2510 | 2510 |
| 2511 void GetDriveFilesFunction::OnFileReady( | 2511 void GetDriveFilesFunction::OnFileReady( |
| 2512 drive::DriveFileError error, | 2512 drive::DriveFileError error, |
| 2513 const FilePath& local_path, | 2513 const FilePath& local_path, |
| 2514 const std::string& unused_mime_type, | 2514 const std::string& unused_mime_type, |
| 2515 drive::DriveFileType file_type) { | 2515 drive::DriveFileType file_type) { |
| 2516 FilePath drive_path = remaining_drive_paths_.front(); | 2516 FilePath drive_path = remaining_drive_paths_.front(); |
| 2517 | 2517 |
| 2518 if (error == drive::DRIVE_FILE_OK) { | 2518 if (error == drive::DRIVE_FILE_OK) { |
| 2519 local_paths_->Append(Value::CreateStringValue(local_path.value())); | 2519 local_paths_->Append(new base::StringValue(local_path.value())); |
| 2520 DVLOG(1) << "Got " << drive_path.value() << " as " << local_path.value(); | 2520 DVLOG(1) << "Got " << drive_path.value() << " as " << local_path.value(); |
| 2521 | 2521 |
| 2522 // TODO(benchan): If the file is a hosted document, a temporary JSON file | 2522 // TODO(benchan): If the file is a hosted document, a temporary JSON file |
| 2523 // is created to represent the document. The JSON file is not cached and | 2523 // is created to represent the document. The JSON file is not cached and |
| 2524 // should be deleted after use. We need to somehow communicate with | 2524 // should be deleted after use. We need to somehow communicate with |
| 2525 // file_manager.js to manage the lifetime of the temporary file. | 2525 // file_manager.js to manage the lifetime of the temporary file. |
| 2526 // See crosbug.com/28058. | 2526 // See crosbug.com/28058. |
| 2527 } else { | 2527 } else { |
| 2528 local_paths_->Append(Value::CreateStringValue("")); | 2528 local_paths_->Append(new base::StringValue("")); |
| 2529 DVLOG(1) << "Failed to get " << drive_path.value() | 2529 DVLOG(1) << "Failed to get " << drive_path.value() |
| 2530 << " with error code: " << error; | 2530 << " with error code: " << error; |
| 2531 } | 2531 } |
| 2532 | 2532 |
| 2533 remaining_drive_paths_.pop(); | 2533 remaining_drive_paths_.pop(); |
| 2534 | 2534 |
| 2535 // Start getting the next file. | 2535 // Start getting the next file. |
| 2536 GetFileOrSendResponse(); | 2536 GetFileOrSendResponse(); |
| 2537 } | 2537 } |
| 2538 | 2538 |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2890 drive::DriveSystemServiceFactory::GetForProfile(profile_); | 2890 drive::DriveSystemServiceFactory::GetForProfile(profile_); |
| 2891 // |system_service| is NULL if Drive is disabled. | 2891 // |system_service| is NULL if Drive is disabled. |
| 2892 if (!system_service || !system_service->file_system()) | 2892 if (!system_service || !system_service->file_system()) |
| 2893 return false; | 2893 return false; |
| 2894 | 2894 |
| 2895 FilePath directory_path = GetVirtualPathFromURL(GURL(file_url_as_string)); | 2895 FilePath directory_path = GetVirtualPathFromURL(GURL(file_url_as_string)); |
| 2896 system_service->file_system()->RequestDirectoryRefresh(directory_path); | 2896 system_service->file_system()->RequestDirectoryRefresh(directory_path); |
| 2897 | 2897 |
| 2898 return true; | 2898 return true; |
| 2899 } | 2899 } |
| OLD | NEW |