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

Side by Side Diff: chrome/browser/chromeos/extensions/file_manager/private_api_drive.cc

Issue 22181002: Remove fileBrowserPrivate.transferFile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address review comments. Created 7 years, 4 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_manager/private_api_drive.h" 5 #include "chrome/browser/chromeos/extensions/file_manager/private_api_drive.h"
6 6
7 #include "base/prefs/pref_service.h" 7 #include "base/prefs/pref_service.h"
8 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
9 #include "chrome/browser/chromeos/drive/drive_app_registry.h" 9 #include "chrome/browser/chromeos/drive/drive_app_registry.h"
10 #include "chrome/browser/chromeos/drive/drive_integration_service.h" 10 #include "chrome/browser/chromeos/drive/drive_integration_service.h"
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 // TODO(kinaba): simplify cancelFileTransfer() to take single URL each time, 375 // TODO(kinaba): simplify cancelFileTransfer() to take single URL each time,
376 // and eliminate this field; it is just returning a copy of the argument. 376 // and eliminate this field; it is just returning a copy of the argument.
377 result->SetString("fileUrl", url_as_string); 377 result->SetString("fileUrl", url_as_string);
378 responses->Append(result.release()); 378 responses->Append(result.release());
379 } 379 }
380 SetResult(responses.release()); 380 SetResult(responses.release());
381 SendResponse(true); 381 SendResponse(true);
382 return true; 382 return true;
383 } 383 }
384 384
385 TransferFileFunction::TransferFileFunction() {
386 }
387
388 TransferFileFunction::~TransferFileFunction() {
389 }
390
391 bool TransferFileFunction::RunImpl() {
392 std::string source_file_url;
393 std::string destination_file_url;
394 if (!args_->GetString(0, &source_file_url) ||
395 !args_->GetString(1, &destination_file_url)) {
396 return false;
397 }
398
399 drive::DriveIntegrationService* integration_service =
400 drive::DriveIntegrationServiceFactory::GetForProfile(profile_);
401 // |integration_service| is NULL if Drive is disabled.
402 if (!integration_service)
403 return false;
404
405 base::FilePath source_file = util::GetLocalPathFromURL(
406 render_view_host(), profile(), GURL(source_file_url));
407 base::FilePath destination_file = util::GetLocalPathFromURL(
408 render_view_host(), profile(), GURL(destination_file_url));
409 if (source_file.empty() || destination_file.empty())
410 return false;
411
412 bool source_file_under_drive =
413 drive::util::IsUnderDriveMountPoint(source_file);
414 bool destination_file_under_drive =
415 drive::util::IsUnderDriveMountPoint(destination_file);
416
417 if (source_file_under_drive && !destination_file_under_drive) {
418 // Transfer a file from drive to local file system.
419 source_file = drive::util::ExtractDrivePath(source_file);
420 integration_service->file_system()->TransferFileFromRemoteToLocal(
421 source_file,
422 destination_file,
423 base::Bind(&TransferFileFunction::OnTransferCompleted, this));
424 } else if (!source_file_under_drive && destination_file_under_drive) {
425 // Transfer a file from local to Drive file system
426 destination_file = drive::util::ExtractDrivePath(destination_file);
427 integration_service->file_system()->TransferFileFromLocalToRemote(
428 source_file,
429 destination_file,
430 base::Bind(&TransferFileFunction::OnTransferCompleted, this));
431 } else {
432 // Local-to-local or Drive-to-Drive file transfers should be done via
433 // FileEntry.copyTo in the File API and are thus not supported here.
434 NOTREACHED();
435 SendResponse(false);
436 }
437 return true;
438 }
439
440 void TransferFileFunction::OnTransferCompleted(drive::FileError error) {
441 if (error == drive::FILE_ERROR_OK) {
442 SendResponse(true);
443 } else {
444 error_ = base::StringPrintf("%d", static_cast<int>(
445 fileapi::PlatformFileErrorToWebFileError(
446 drive::FileErrorToPlatformError(error))));
447 SendResponse(false);
448 }
449 }
450
451 SearchDriveFunction::SearchDriveFunction() { 385 SearchDriveFunction::SearchDriveFunction() {
452 } 386 }
453 387
454 SearchDriveFunction::~SearchDriveFunction() { 388 SearchDriveFunction::~SearchDriveFunction() {
455 } 389 }
456 390
457 bool SearchDriveFunction::RunImpl() { 391 bool SearchDriveFunction::RunImpl() {
458 DictionaryValue* search_params; 392 DictionaryValue* search_params;
459 if (!args_->GetDictionary(0, &search_params)) 393 if (!args_->GetDictionary(0, &search_params))
460 return false; 394 return false;
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 error_ = "Share Url for this item is not available."; 688 error_ = "Share Url for this item is not available.";
755 SendResponse(false); 689 SendResponse(false);
756 return; 690 return;
757 } 691 }
758 692
759 SetResult(new base::StringValue(share_url.spec())); 693 SetResult(new base::StringValue(share_url.spec()));
760 SendResponse(true); 694 SendResponse(true);
761 } 695 }
762 696
763 } // namespace file_manager 697 } // namespace file_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698