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

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

Issue 550863003: Rename fileBrowserPrivate to fileManagerPrivate (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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
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/command_line.h" 7 #include "base/command_line.h"
8 #include "chrome/browser/browser_process.h" 8 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/chromeos/drive/drive_integration_service.h" 9 #include "chrome/browser/chromeos/drive/drive_integration_service.h"
10 #include "chrome/browser/chromeos/extensions/file_manager/private_api_util.h" 10 #include "chrome/browser/chromeos/extensions/file_manager/private_api_util.h"
(...skipping 17 matching lines...) Expand all
28 #include "webkit/common/fileapi/file_system_util.h" 28 #include "webkit/common/fileapi/file_system_util.h"
29 29
30 using content::BrowserThread; 30 using content::BrowserThread;
31 31
32 using file_manager::util::EntryDefinition; 32 using file_manager::util::EntryDefinition;
33 using file_manager::util::EntryDefinitionCallback; 33 using file_manager::util::EntryDefinitionCallback;
34 using file_manager::util::EntryDefinitionList; 34 using file_manager::util::EntryDefinitionList;
35 using file_manager::util::EntryDefinitionListCallback; 35 using file_manager::util::EntryDefinitionListCallback;
36 using file_manager::util::FileDefinition; 36 using file_manager::util::FileDefinition;
37 using file_manager::util::FileDefinitionList; 37 using file_manager::util::FileDefinitionList;
38 using extensions::api::file_browser_private::EntryProperties; 38 using extensions::api::file_manager_private::EntryProperties;
39 39
40 namespace extensions { 40 namespace extensions {
41 namespace { 41 namespace {
42 42
43 // List of connection types of drive. 43 // List of connection types of drive.
44 // Keep this in sync with the DriveConnectionType in common/js/util.js. 44 // Keep this in sync with the DriveConnectionType in common/js/util.js.
45 const char kDriveConnectionTypeOffline[] = "offline"; 45 const char kDriveConnectionTypeOffline[] = "offline";
46 const char kDriveConnectionTypeMetered[] = "metered"; 46 const char kDriveConnectionTypeMetered[] = "metered";
47 const char kDriveConnectionTypeOnline[] = "online"; 47 const char kDriveConnectionTypeOnline[] = "online";
48 48
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 DCHECK(!callback_.is_null()); 350 DCHECK(!callback_.is_null());
351 351
352 callback_.Run(properties_.Pass(), drive::FileErrorToBaseFileError(error)); 352 callback_.Run(properties_.Pass(), drive::FileErrorToBaseFileError(error));
353 353
354 delete this; 354 delete this;
355 } 355 }
356 }; // class SingleEntryPropertiesGetterForDrive 356 }; // class SingleEntryPropertiesGetterForDrive
357 357
358 } // namespace 358 } // namespace
359 359
360 FileBrowserPrivateGetEntryPropertiesFunction:: 360 FileManagerPrivateGetEntryPropertiesFunction::
361 FileBrowserPrivateGetEntryPropertiesFunction() 361 FileManagerPrivateGetEntryPropertiesFunction()
362 : processed_count_(0) { 362 : processed_count_(0) {
363 } 363 }
364 364
365 FileBrowserPrivateGetEntryPropertiesFunction:: 365 FileManagerPrivateGetEntryPropertiesFunction::
366 ~FileBrowserPrivateGetEntryPropertiesFunction() { 366 ~FileManagerPrivateGetEntryPropertiesFunction() {
367 } 367 }
368 368
369 bool FileBrowserPrivateGetEntryPropertiesFunction::RunAsync() { 369 bool FileManagerPrivateGetEntryPropertiesFunction::RunAsync() {
370 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 370 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
371 371
372 using api::file_browser_private::GetEntryProperties::Params; 372 using api::file_manager_private::GetEntryProperties::Params;
373 const scoped_ptr<Params> params(Params::Create(*args_)); 373 const scoped_ptr<Params> params(Params::Create(*args_));
374 EXTENSION_FUNCTION_VALIDATE(params); 374 EXTENSION_FUNCTION_VALIDATE(params);
375 375
376 scoped_refptr<storage::FileSystemContext> file_system_context = 376 scoped_refptr<storage::FileSystemContext> file_system_context =
377 file_manager::util::GetFileSystemContextForRenderViewHost( 377 file_manager::util::GetFileSystemContextForRenderViewHost(
378 GetProfile(), render_view_host()); 378 GetProfile(), render_view_host());
379 379
380 properties_list_.resize(params->file_urls.size()); 380 properties_list_.resize(params->file_urls.size());
381 for (size_t i = 0; i < params->file_urls.size(); i++) { 381 for (size_t i = 0; i < params->file_urls.size(); i++) {
382 const GURL url = GURL(params->file_urls[i]); 382 const GURL url = GURL(params->file_urls[i]);
383 const storage::FileSystemURL file_system_url = 383 const storage::FileSystemURL file_system_url =
384 file_system_context->CrackURL(url); 384 file_system_context->CrackURL(url);
385 switch (file_system_url.type()) { 385 switch (file_system_url.type()) {
386 case storage::kFileSystemTypeDrive: 386 case storage::kFileSystemTypeDrive:
387 SingleEntryPropertiesGetterForDrive::Start( 387 SingleEntryPropertiesGetterForDrive::Start(
388 file_system_url.path(), 388 file_system_url.path(),
389 GetProfile(), 389 GetProfile(),
390 base::Bind(&FileBrowserPrivateGetEntryPropertiesFunction:: 390 base::Bind(&FileManagerPrivateGetEntryPropertiesFunction::
391 CompleteGetEntryProperties, 391 CompleteGetEntryProperties,
392 this, 392 this,
393 i)); 393 i));
394 break; 394 break;
395 case storage::kFileSystemTypeProvided: 395 case storage::kFileSystemTypeProvided:
396 // TODO(mtomasz): Add support for provided file systems. 396 // TODO(mtomasz): Add support for provided file systems.
397 NOTIMPLEMENTED(); 397 NOTIMPLEMENTED();
398 break; 398 break;
399 default: 399 default:
400 LOG(ERROR) << "Not supported file system type."; 400 LOG(ERROR) << "Not supported file system type.";
401 CompleteGetEntryProperties(i, 401 CompleteGetEntryProperties(i,
402 make_scoped_ptr(new EntryProperties), 402 make_scoped_ptr(new EntryProperties),
403 base::File::FILE_ERROR_INVALID_OPERATION); 403 base::File::FILE_ERROR_INVALID_OPERATION);
404 } 404 }
405 } 405 }
406 406
407 return true; 407 return true;
408 } 408 }
409 409
410 void FileBrowserPrivateGetEntryPropertiesFunction::CompleteGetEntryProperties( 410 void FileManagerPrivateGetEntryPropertiesFunction::CompleteGetEntryProperties(
411 size_t index, 411 size_t index,
412 scoped_ptr<EntryProperties> properties, 412 scoped_ptr<EntryProperties> properties,
413 base::File::Error error) { 413 base::File::Error error) {
414 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 414 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
415 DCHECK(0 <= processed_count_ && processed_count_ < properties_list_.size()); 415 DCHECK(0 <= processed_count_ && processed_count_ < properties_list_.size());
416 416
417 properties_list_[index] = make_linked_ptr(properties.release()); 417 properties_list_[index] = make_linked_ptr(properties.release());
418 418
419 processed_count_++; 419 processed_count_++;
420 if (processed_count_ < properties_list_.size()) 420 if (processed_count_ < properties_list_.size())
421 return; 421 return;
422 422
423 results_ = extensions::api::file_browser_private::GetEntryProperties:: 423 results_ = extensions::api::file_manager_private::GetEntryProperties::
424 Results::Create(properties_list_); 424 Results::Create(properties_list_);
425 SendResponse(true); 425 SendResponse(true);
426 } 426 }
427 427
428 bool FileBrowserPrivatePinDriveFileFunction::RunAsync() { 428 bool FileManagerPrivatePinDriveFileFunction::RunAsync() {
429 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 429 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
430 430
431 using extensions::api::file_browser_private::PinDriveFile::Params; 431 using extensions::api::file_manager_private::PinDriveFile::Params;
432 const scoped_ptr<Params> params(Params::Create(*args_)); 432 const scoped_ptr<Params> params(Params::Create(*args_));
433 EXTENSION_FUNCTION_VALIDATE(params); 433 EXTENSION_FUNCTION_VALIDATE(params);
434 434
435 drive::FileSystemInterface* const file_system = 435 drive::FileSystemInterface* const file_system =
436 drive::util::GetFileSystemByProfile(GetProfile()); 436 drive::util::GetFileSystemByProfile(GetProfile());
437 if (!file_system) // |file_system| is NULL if Drive is disabled. 437 if (!file_system) // |file_system| is NULL if Drive is disabled.
438 return false; 438 return false;
439 439
440 const base::FilePath drive_path = 440 const base::FilePath drive_path =
441 drive::util::ExtractDrivePath(file_manager::util::GetLocalPathFromURL( 441 drive::util::ExtractDrivePath(file_manager::util::GetLocalPathFromURL(
442 render_view_host(), GetProfile(), GURL(params->file_url))); 442 render_view_host(), GetProfile(), GURL(params->file_url)));
443 if (params->pin) { 443 if (params->pin) {
444 file_system->Pin(drive_path, 444 file_system->Pin(drive_path,
445 base::Bind(&FileBrowserPrivatePinDriveFileFunction:: 445 base::Bind(&FileManagerPrivatePinDriveFileFunction::
446 OnPinStateSet, this)); 446 OnPinStateSet, this));
447 } else { 447 } else {
448 file_system->Unpin(drive_path, 448 file_system->Unpin(drive_path,
449 base::Bind(&FileBrowserPrivatePinDriveFileFunction:: 449 base::Bind(&FileManagerPrivatePinDriveFileFunction::
450 OnPinStateSet, this)); 450 OnPinStateSet, this));
451 } 451 }
452 return true; 452 return true;
453 } 453 }
454 454
455 void FileBrowserPrivatePinDriveFileFunction:: 455 void FileManagerPrivatePinDriveFileFunction::
456 OnPinStateSet(drive::FileError error) { 456 OnPinStateSet(drive::FileError error) {
457 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 457 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
458 458
459 if (error == drive::FILE_ERROR_OK) { 459 if (error == drive::FILE_ERROR_OK) {
460 SendResponse(true); 460 SendResponse(true);
461 } else { 461 } else {
462 SetError(drive::FileErrorToString(error)); 462 SetError(drive::FileErrorToString(error));
463 SendResponse(false); 463 SendResponse(false);
464 } 464 }
465 } 465 }
466 466
467 FileBrowserPrivateGetDriveFilesFunction:: 467 FileManagerPrivateGetDriveFilesFunction::
468 FileBrowserPrivateGetDriveFilesFunction() { 468 FileManagerPrivateGetDriveFilesFunction() {
469 } 469 }
470 470
471 FileBrowserPrivateGetDriveFilesFunction:: 471 FileManagerPrivateGetDriveFilesFunction::
472 ~FileBrowserPrivateGetDriveFilesFunction() { 472 ~FileManagerPrivateGetDriveFilesFunction() {
473 } 473 }
474 474
475 bool FileBrowserPrivateGetDriveFilesFunction::RunAsync() { 475 bool FileManagerPrivateGetDriveFilesFunction::RunAsync() {
476 using extensions::api::file_browser_private::GetDriveFiles::Params; 476 using extensions::api::file_manager_private::GetDriveFiles::Params;
477 const scoped_ptr<Params> params(Params::Create(*args_)); 477 const scoped_ptr<Params> params(Params::Create(*args_));
478 EXTENSION_FUNCTION_VALIDATE(params); 478 EXTENSION_FUNCTION_VALIDATE(params);
479 479
480 // Convert the list of strings to a list of GURLs. 480 // Convert the list of strings to a list of GURLs.
481 for (size_t i = 0; i < params->file_urls.size(); ++i) { 481 for (size_t i = 0; i < params->file_urls.size(); ++i) {
482 const base::FilePath path = file_manager::util::GetLocalPathFromURL( 482 const base::FilePath path = file_manager::util::GetLocalPathFromURL(
483 render_view_host(), GetProfile(), GURL(params->file_urls[i])); 483 render_view_host(), GetProfile(), GURL(params->file_urls[i]));
484 DCHECK(drive::util::IsUnderDriveMountPoint(path)); 484 DCHECK(drive::util::IsUnderDriveMountPoint(path));
485 base::FilePath drive_path = drive::util::ExtractDrivePath(path); 485 base::FilePath drive_path = drive::util::ExtractDrivePath(path);
486 remaining_drive_paths_.push(drive_path); 486 remaining_drive_paths_.push(drive_path);
487 } 487 }
488 488
489 GetFileOrSendResponse(); 489 GetFileOrSendResponse();
490 return true; 490 return true;
491 } 491 }
492 492
493 void FileBrowserPrivateGetDriveFilesFunction::GetFileOrSendResponse() { 493 void FileManagerPrivateGetDriveFilesFunction::GetFileOrSendResponse() {
494 // Send the response if all files are obtained. 494 // Send the response if all files are obtained.
495 if (remaining_drive_paths_.empty()) { 495 if (remaining_drive_paths_.empty()) {
496 results_ = extensions::api::file_browser_private:: 496 results_ = extensions::api::file_manager_private::
497 GetDriveFiles::Results::Create(local_paths_); 497 GetDriveFiles::Results::Create(local_paths_);
498 SendResponse(true); 498 SendResponse(true);
499 return; 499 return;
500 } 500 }
501 501
502 // Get the file on the top of the queue. 502 // Get the file on the top of the queue.
503 base::FilePath drive_path = remaining_drive_paths_.front(); 503 base::FilePath drive_path = remaining_drive_paths_.front();
504 504
505 drive::FileSystemInterface* file_system = 505 drive::FileSystemInterface* file_system =
506 drive::util::GetFileSystemByProfile(GetProfile()); 506 drive::util::GetFileSystemByProfile(GetProfile());
507 if (!file_system) { 507 if (!file_system) {
508 // |file_system| is NULL if Drive is disabled or not mounted. 508 // |file_system| is NULL if Drive is disabled or not mounted.
509 OnFileReady(drive::FILE_ERROR_FAILED, drive_path, 509 OnFileReady(drive::FILE_ERROR_FAILED, drive_path,
510 scoped_ptr<drive::ResourceEntry>()); 510 scoped_ptr<drive::ResourceEntry>());
511 return; 511 return;
512 } 512 }
513 513
514 file_system->GetFile( 514 file_system->GetFile(
515 drive_path, 515 drive_path,
516 base::Bind(&FileBrowserPrivateGetDriveFilesFunction::OnFileReady, this)); 516 base::Bind(&FileManagerPrivateGetDriveFilesFunction::OnFileReady, this));
517 } 517 }
518 518
519 519
520 void FileBrowserPrivateGetDriveFilesFunction::OnFileReady( 520 void FileManagerPrivateGetDriveFilesFunction::OnFileReady(
521 drive::FileError error, 521 drive::FileError error,
522 const base::FilePath& local_path, 522 const base::FilePath& local_path,
523 scoped_ptr<drive::ResourceEntry> entry) { 523 scoped_ptr<drive::ResourceEntry> entry) {
524 base::FilePath drive_path = remaining_drive_paths_.front(); 524 base::FilePath drive_path = remaining_drive_paths_.front();
525 525
526 if (error == drive::FILE_ERROR_OK) { 526 if (error == drive::FILE_ERROR_OK) {
527 local_paths_.push_back(local_path.AsUTF8Unsafe()); 527 local_paths_.push_back(local_path.AsUTF8Unsafe());
528 DVLOG(1) << "Got " << drive_path.value() << " as " << local_path.value(); 528 DVLOG(1) << "Got " << drive_path.value() << " as " << local_path.value();
529 } else { 529 } else {
530 local_paths_.push_back(""); 530 local_paths_.push_back("");
531 DVLOG(1) << "Failed to get " << drive_path.value() 531 DVLOG(1) << "Failed to get " << drive_path.value()
532 << " with error code: " << error; 532 << " with error code: " << error;
533 } 533 }
534 534
535 remaining_drive_paths_.pop(); 535 remaining_drive_paths_.pop();
536 536
537 // Start getting the next file. 537 // Start getting the next file.
538 GetFileOrSendResponse(); 538 GetFileOrSendResponse();
539 } 539 }
540 540
541 bool FileBrowserPrivateCancelFileTransfersFunction::RunAsync() { 541 bool FileManagerPrivateCancelFileTransfersFunction::RunAsync() {
542 using extensions::api::file_browser_private::CancelFileTransfers::Params; 542 using extensions::api::file_manager_private::CancelFileTransfers::Params;
543 const scoped_ptr<Params> params(Params::Create(*args_)); 543 const scoped_ptr<Params> params(Params::Create(*args_));
544 EXTENSION_FUNCTION_VALIDATE(params); 544 EXTENSION_FUNCTION_VALIDATE(params);
545 545
546 drive::DriveIntegrationService* integration_service = 546 drive::DriveIntegrationService* integration_service =
547 drive::DriveIntegrationServiceFactory::FindForProfile(GetProfile()); 547 drive::DriveIntegrationServiceFactory::FindForProfile(GetProfile());
548 if (!integration_service || !integration_service->IsMounted()) 548 if (!integration_service || !integration_service->IsMounted())
549 return false; 549 return false;
550 550
551 // Create the mapping from file path to job ID. 551 // Create the mapping from file path to job ID.
552 drive::JobListInterface* job_list = integration_service->job_list(); 552 drive::JobListInterface* job_list = integration_service->job_list();
553 DCHECK(job_list); 553 DCHECK(job_list);
554 std::vector<drive::JobInfo> jobs = job_list->GetJobInfoList(); 554 std::vector<drive::JobInfo> jobs = job_list->GetJobInfoList();
555 555
556 typedef std::map<base::FilePath, std::vector<drive::JobID> > PathToIdMap; 556 typedef std::map<base::FilePath, std::vector<drive::JobID> > PathToIdMap;
557 PathToIdMap path_to_id_map; 557 PathToIdMap path_to_id_map;
558 for (size_t i = 0; i < jobs.size(); ++i) { 558 for (size_t i = 0; i < jobs.size(); ++i) {
559 if (drive::IsActiveFileTransferJobInfo(jobs[i])) 559 if (drive::IsActiveFileTransferJobInfo(jobs[i]))
560 path_to_id_map[jobs[i].file_path].push_back(jobs[i].job_id); 560 path_to_id_map[jobs[i].file_path].push_back(jobs[i].job_id);
561 } 561 }
562 562
563 // Cancel by Job ID. 563 // Cancel by Job ID.
564 std::vector<linked_ptr<api::file_browser_private:: 564 std::vector<linked_ptr<api::file_manager_private::
565 FileTransferCancelStatus> > responses; 565 FileTransferCancelStatus> > responses;
566 for (size_t i = 0; i < params->file_urls.size(); ++i) { 566 for (size_t i = 0; i < params->file_urls.size(); ++i) {
567 base::FilePath file_path = file_manager::util::GetLocalPathFromURL( 567 base::FilePath file_path = file_manager::util::GetLocalPathFromURL(
568 render_view_host(), GetProfile(), GURL(params->file_urls[i])); 568 render_view_host(), GetProfile(), GURL(params->file_urls[i]));
569 if (file_path.empty()) 569 if (file_path.empty())
570 continue; 570 continue;
571 571
572 DCHECK(drive::util::IsUnderDriveMountPoint(file_path)); 572 DCHECK(drive::util::IsUnderDriveMountPoint(file_path));
573 file_path = drive::util::ExtractDrivePath(file_path); 573 file_path = drive::util::ExtractDrivePath(file_path);
574 574
575 // Cancel all the jobs for the file. 575 // Cancel all the jobs for the file.
576 PathToIdMap::iterator it = path_to_id_map.find(file_path); 576 PathToIdMap::iterator it = path_to_id_map.find(file_path);
577 if (it != path_to_id_map.end()) { 577 if (it != path_to_id_map.end()) {
578 for (size_t i = 0; i < it->second.size(); ++i) 578 for (size_t i = 0; i < it->second.size(); ++i)
579 job_list->CancelJob(it->second[i]); 579 job_list->CancelJob(it->second[i]);
580 } 580 }
581 linked_ptr<api::file_browser_private::FileTransferCancelStatus> result( 581 linked_ptr<api::file_manager_private::FileTransferCancelStatus> result(
582 new api::file_browser_private::FileTransferCancelStatus); 582 new api::file_manager_private::FileTransferCancelStatus);
583 result->canceled = it != path_to_id_map.end(); 583 result->canceled = it != path_to_id_map.end();
584 // TODO(kinaba): simplify cancelFileTransfer() to take single URL each time, 584 // TODO(kinaba): simplify cancelFileTransfer() to take single URL each time,
585 // and eliminate this field; it is just returning a copy of the argument. 585 // and eliminate this field; it is just returning a copy of the argument.
586 result->file_url = params->file_urls[i]; 586 result->file_url = params->file_urls[i];
587 responses.push_back(result); 587 responses.push_back(result);
588 } 588 }
589 results_ = api::file_browser_private::CancelFileTransfers::Results::Create( 589 results_ = api::file_manager_private::CancelFileTransfers::Results::Create(
590 responses); 590 responses);
591 SendResponse(true); 591 SendResponse(true);
592 return true; 592 return true;
593 } 593 }
594 594
595 bool FileBrowserPrivateSearchDriveFunction::RunAsync() { 595 bool FileManagerPrivateSearchDriveFunction::RunAsync() {
596 using extensions::api::file_browser_private::SearchDrive::Params; 596 using extensions::api::file_manager_private::SearchDrive::Params;
597 const scoped_ptr<Params> params(Params::Create(*args_)); 597 const scoped_ptr<Params> params(Params::Create(*args_));
598 EXTENSION_FUNCTION_VALIDATE(params); 598 EXTENSION_FUNCTION_VALIDATE(params);
599 599
600 drive::FileSystemInterface* const file_system = 600 drive::FileSystemInterface* const file_system =
601 drive::util::GetFileSystemByProfile(GetProfile()); 601 drive::util::GetFileSystemByProfile(GetProfile());
602 if (!file_system) { 602 if (!file_system) {
603 // |file_system| is NULL if Drive is disabled. 603 // |file_system| is NULL if Drive is disabled.
604 return false; 604 return false;
605 } 605 }
606 606
607 file_system->Search( 607 file_system->Search(
608 params->search_params.query, GURL(params->search_params.next_feed), 608 params->search_params.query, GURL(params->search_params.next_feed),
609 base::Bind(&FileBrowserPrivateSearchDriveFunction::OnSearch, this)); 609 base::Bind(&FileManagerPrivateSearchDriveFunction::OnSearch, this));
610 return true; 610 return true;
611 } 611 }
612 612
613 void FileBrowserPrivateSearchDriveFunction::OnSearch( 613 void FileManagerPrivateSearchDriveFunction::OnSearch(
614 drive::FileError error, 614 drive::FileError error,
615 const GURL& next_link, 615 const GURL& next_link,
616 scoped_ptr<SearchResultInfoList> results) { 616 scoped_ptr<SearchResultInfoList> results) {
617 if (error != drive::FILE_ERROR_OK) { 617 if (error != drive::FILE_ERROR_OK) {
618 SendResponse(false); 618 SendResponse(false);
619 return; 619 return;
620 } 620 }
621 621
622 // Outlives the following conversion, since the pointer is bound to the 622 // Outlives the following conversion, since the pointer is bound to the
623 // callback. 623 // callback.
624 DCHECK(results.get()); 624 DCHECK(results.get());
625 const SearchResultInfoList& results_ref = *results.get(); 625 const SearchResultInfoList& results_ref = *results.get();
626 626
627 ConvertSearchResultInfoListToEntryDefinitionList( 627 ConvertSearchResultInfoListToEntryDefinitionList(
628 GetProfile(), 628 GetProfile(),
629 extension_->id(), 629 extension_->id(),
630 results_ref, 630 results_ref,
631 base::Bind(&FileBrowserPrivateSearchDriveFunction::OnEntryDefinitionList, 631 base::Bind(&FileManagerPrivateSearchDriveFunction::OnEntryDefinitionList,
632 this, 632 this,
633 next_link, 633 next_link,
634 base::Passed(&results))); 634 base::Passed(&results)));
635 } 635 }
636 636
637 void FileBrowserPrivateSearchDriveFunction::OnEntryDefinitionList( 637 void FileManagerPrivateSearchDriveFunction::OnEntryDefinitionList(
638 const GURL& next_link, 638 const GURL& next_link,
639 scoped_ptr<SearchResultInfoList> search_result_info_list, 639 scoped_ptr<SearchResultInfoList> search_result_info_list,
640 scoped_ptr<EntryDefinitionList> entry_definition_list) { 640 scoped_ptr<EntryDefinitionList> entry_definition_list) {
641 DCHECK_EQ(search_result_info_list->size(), entry_definition_list->size()); 641 DCHECK_EQ(search_result_info_list->size(), entry_definition_list->size());
642 base::ListValue* entries = new base::ListValue(); 642 base::ListValue* entries = new base::ListValue();
643 643
644 // Convert Drive files to something File API stack can understand. 644 // Convert Drive files to something File API stack can understand.
645 for (EntryDefinitionList::const_iterator it = entry_definition_list->begin(); 645 for (EntryDefinitionList::const_iterator it = entry_definition_list->begin();
646 it != entry_definition_list->end(); 646 it != entry_definition_list->end();
647 ++it) { 647 ++it) {
648 base::DictionaryValue* entry = new base::DictionaryValue(); 648 base::DictionaryValue* entry = new base::DictionaryValue();
649 entry->SetString("fileSystemName", it->file_system_name); 649 entry->SetString("fileSystemName", it->file_system_name);
650 entry->SetString("fileSystemRoot", it->file_system_root_url); 650 entry->SetString("fileSystemRoot", it->file_system_root_url);
651 entry->SetString("fileFullPath", "/" + it->full_path.AsUTF8Unsafe()); 651 entry->SetString("fileFullPath", "/" + it->full_path.AsUTF8Unsafe());
652 entry->SetBoolean("fileIsDirectory", it->is_directory); 652 entry->SetBoolean("fileIsDirectory", it->is_directory);
653 entries->Append(entry); 653 entries->Append(entry);
654 } 654 }
655 655
656 base::DictionaryValue* result = new base::DictionaryValue(); 656 base::DictionaryValue* result = new base::DictionaryValue();
657 result->Set("entries", entries); 657 result->Set("entries", entries);
658 result->SetString("nextFeed", next_link.spec()); 658 result->SetString("nextFeed", next_link.spec());
659 659
660 SetResult(result); 660 SetResult(result);
661 SendResponse(true); 661 SendResponse(true);
662 } 662 }
663 663
664 bool FileBrowserPrivateSearchDriveMetadataFunction::RunAsync() { 664 bool FileManagerPrivateSearchDriveMetadataFunction::RunAsync() {
665 using api::file_browser_private::SearchDriveMetadata::Params; 665 using api::file_manager_private::SearchDriveMetadata::Params;
666 const scoped_ptr<Params> params(Params::Create(*args_)); 666 const scoped_ptr<Params> params(Params::Create(*args_));
667 EXTENSION_FUNCTION_VALIDATE(params); 667 EXTENSION_FUNCTION_VALIDATE(params);
668 668
669 drive::EventLogger* logger = file_manager::util::GetLogger(GetProfile()); 669 drive::EventLogger* logger = file_manager::util::GetLogger(GetProfile());
670 if (logger) { 670 if (logger) {
671 logger->Log(logging::LOG_INFO, 671 logger->Log(logging::LOG_INFO,
672 "%s[%d] called. (types: '%s', maxResults: '%d')", 672 "%s[%d] called. (types: '%s', maxResults: '%d')",
673 name().c_str(), 673 name().c_str(),
674 request_id(), 674 request_id(),
675 api::file_browser_private::ToString( 675 api::file_manager_private::ToString(
676 params->search_params.types).c_str(), 676 params->search_params.types).c_str(),
677 params->search_params.max_results); 677 params->search_params.max_results);
678 } 678 }
679 set_log_on_completion(true); 679 set_log_on_completion(true);
680 680
681 drive::FileSystemInterface* const file_system = 681 drive::FileSystemInterface* const file_system =
682 drive::util::GetFileSystemByProfile(GetProfile()); 682 drive::util::GetFileSystemByProfile(GetProfile());
683 if (!file_system) { 683 if (!file_system) {
684 // |file_system| is NULL if Drive is disabled. 684 // |file_system| is NULL if Drive is disabled.
685 return false; 685 return false;
686 } 686 }
687 687
688 int options = -1; 688 int options = -1;
689 switch (params->search_params.types) { 689 switch (params->search_params.types) {
690 case api::file_browser_private::SEARCH_TYPE_EXCLUDE_DIRECTORIES: 690 case api::file_manager_private::SEARCH_TYPE_EXCLUDE_DIRECTORIES:
691 options = drive::SEARCH_METADATA_EXCLUDE_DIRECTORIES; 691 options = drive::SEARCH_METADATA_EXCLUDE_DIRECTORIES;
692 break; 692 break;
693 case api::file_browser_private::SEARCH_TYPE_SHARED_WITH_ME: 693 case api::file_manager_private::SEARCH_TYPE_SHARED_WITH_ME:
694 options = drive::SEARCH_METADATA_SHARED_WITH_ME; 694 options = drive::SEARCH_METADATA_SHARED_WITH_ME;
695 break; 695 break;
696 case api::file_browser_private::SEARCH_TYPE_OFFLINE: 696 case api::file_manager_private::SEARCH_TYPE_OFFLINE:
697 options = drive::SEARCH_METADATA_OFFLINE; 697 options = drive::SEARCH_METADATA_OFFLINE;
698 break; 698 break;
699 case api::file_browser_private::SEARCH_TYPE_ALL: 699 case api::file_manager_private::SEARCH_TYPE_ALL:
700 options = drive::SEARCH_METADATA_ALL; 700 options = drive::SEARCH_METADATA_ALL;
701 break; 701 break;
702 case api::file_browser_private::SEARCH_TYPE_NONE: 702 case api::file_manager_private::SEARCH_TYPE_NONE:
703 break; 703 break;
704 } 704 }
705 DCHECK_NE(options, -1); 705 DCHECK_NE(options, -1);
706 706
707 file_system->SearchMetadata( 707 file_system->SearchMetadata(
708 params->search_params.query, 708 params->search_params.query,
709 options, 709 options,
710 params->search_params.max_results, 710 params->search_params.max_results,
711 base::Bind(&FileBrowserPrivateSearchDriveMetadataFunction:: 711 base::Bind(&FileManagerPrivateSearchDriveMetadataFunction::
712 OnSearchMetadata, this)); 712 OnSearchMetadata, this));
713 return true; 713 return true;
714 } 714 }
715 715
716 void FileBrowserPrivateSearchDriveMetadataFunction::OnSearchMetadata( 716 void FileManagerPrivateSearchDriveMetadataFunction::OnSearchMetadata(
717 drive::FileError error, 717 drive::FileError error,
718 scoped_ptr<drive::MetadataSearchResultVector> results) { 718 scoped_ptr<drive::MetadataSearchResultVector> results) {
719 if (error != drive::FILE_ERROR_OK) { 719 if (error != drive::FILE_ERROR_OK) {
720 SendResponse(false); 720 SendResponse(false);
721 return; 721 return;
722 } 722 }
723 723
724 // Outlives the following conversion, since the pointer is bound to the 724 // Outlives the following conversion, since the pointer is bound to the
725 // callback. 725 // callback.
726 DCHECK(results.get()); 726 DCHECK(results.get());
727 const drive::MetadataSearchResultVector& results_ref = *results.get(); 727 const drive::MetadataSearchResultVector& results_ref = *results.get();
728 728
729 ConvertSearchResultInfoListToEntryDefinitionList( 729 ConvertSearchResultInfoListToEntryDefinitionList(
730 GetProfile(), 730 GetProfile(),
731 extension_->id(), 731 extension_->id(),
732 results_ref, 732 results_ref,
733 base::Bind( 733 base::Bind(
734 &FileBrowserPrivateSearchDriveMetadataFunction::OnEntryDefinitionList, 734 &FileManagerPrivateSearchDriveMetadataFunction::OnEntryDefinitionList,
735 this, 735 this,
736 base::Passed(&results))); 736 base::Passed(&results)));
737 } 737 }
738 738
739 void FileBrowserPrivateSearchDriveMetadataFunction::OnEntryDefinitionList( 739 void FileManagerPrivateSearchDriveMetadataFunction::OnEntryDefinitionList(
740 scoped_ptr<drive::MetadataSearchResultVector> search_result_info_list, 740 scoped_ptr<drive::MetadataSearchResultVector> search_result_info_list,
741 scoped_ptr<EntryDefinitionList> entry_definition_list) { 741 scoped_ptr<EntryDefinitionList> entry_definition_list) {
742 DCHECK_EQ(search_result_info_list->size(), entry_definition_list->size()); 742 DCHECK_EQ(search_result_info_list->size(), entry_definition_list->size());
743 base::ListValue* results_list = new base::ListValue(); 743 base::ListValue* results_list = new base::ListValue();
744 744
745 // Convert Drive files to something File API stack can understand. See 745 // Convert Drive files to something File API stack can understand. See
746 // file_browser_handler_custom_bindings.cc and 746 // file_browser_handler_custom_bindings.cc and
747 // file_browser_private_custom_bindings.js for how this is magically 747 // file_manager_private_custom_bindings.js for how this is magically
748 // converted to a FileEntry. 748 // converted to a FileEntry.
749 for (size_t i = 0; i < entry_definition_list->size(); ++i) { 749 for (size_t i = 0; i < entry_definition_list->size(); ++i) {
750 base::DictionaryValue* result_dict = new base::DictionaryValue(); 750 base::DictionaryValue* result_dict = new base::DictionaryValue();
751 751
752 // FileEntry fields. 752 // FileEntry fields.
753 base::DictionaryValue* entry = new base::DictionaryValue(); 753 base::DictionaryValue* entry = new base::DictionaryValue();
754 entry->SetString( 754 entry->SetString(
755 "fileSystemName", entry_definition_list->at(i).file_system_name); 755 "fileSystemName", entry_definition_list->at(i).file_system_name);
756 entry->SetString( 756 entry->SetString(
757 "fileSystemRoot", entry_definition_list->at(i).file_system_root_url); 757 "fileSystemRoot", entry_definition_list->at(i).file_system_root_url);
758 entry->SetString( 758 entry->SetString(
759 "fileFullPath", 759 "fileFullPath",
760 "/" + entry_definition_list->at(i).full_path.AsUTF8Unsafe()); 760 "/" + entry_definition_list->at(i).full_path.AsUTF8Unsafe());
761 entry->SetBoolean("fileIsDirectory", 761 entry->SetBoolean("fileIsDirectory",
762 entry_definition_list->at(i).is_directory); 762 entry_definition_list->at(i).is_directory);
763 763
764 result_dict->Set("entry", entry); 764 result_dict->Set("entry", entry);
765 result_dict->SetString( 765 result_dict->SetString(
766 "highlightedBaseName", 766 "highlightedBaseName",
767 search_result_info_list->at(i).highlighted_base_name); 767 search_result_info_list->at(i).highlighted_base_name);
768 results_list->Append(result_dict); 768 results_list->Append(result_dict);
769 } 769 }
770 770
771 SetResult(results_list); 771 SetResult(results_list);
772 SendResponse(true); 772 SendResponse(true);
773 } 773 }
774 774
775 bool FileBrowserPrivateGetDriveConnectionStateFunction::RunSync() { 775 bool FileManagerPrivateGetDriveConnectionStateFunction::RunSync() {
776 api::file_browser_private::DriveConnectionState result; 776 api::file_manager_private::DriveConnectionState result;
777 777
778 switch (drive::util::GetDriveConnectionStatus(GetProfile())) { 778 switch (drive::util::GetDriveConnectionStatus(GetProfile())) {
779 case drive::util::DRIVE_DISCONNECTED_NOSERVICE: 779 case drive::util::DRIVE_DISCONNECTED_NOSERVICE:
780 result.type = kDriveConnectionTypeOffline; 780 result.type = kDriveConnectionTypeOffline;
781 result.reason.reset(new std::string(kDriveConnectionReasonNoService)); 781 result.reason.reset(new std::string(kDriveConnectionReasonNoService));
782 break; 782 break;
783 case drive::util::DRIVE_DISCONNECTED_NONETWORK: 783 case drive::util::DRIVE_DISCONNECTED_NONETWORK:
784 result.type = kDriveConnectionTypeOffline; 784 result.type = kDriveConnectionTypeOffline;
785 result.reason.reset(new std::string(kDriveConnectionReasonNoNetwork)); 785 result.reason.reset(new std::string(kDriveConnectionReasonNoNetwork));
786 break; 786 break;
787 case drive::util::DRIVE_DISCONNECTED_NOTREADY: 787 case drive::util::DRIVE_DISCONNECTED_NOTREADY:
788 result.type = kDriveConnectionTypeOffline; 788 result.type = kDriveConnectionTypeOffline;
789 result.reason.reset(new std::string(kDriveConnectionReasonNotReady)); 789 result.reason.reset(new std::string(kDriveConnectionReasonNotReady));
790 break; 790 break;
791 case drive::util::DRIVE_CONNECTED_METERED: 791 case drive::util::DRIVE_CONNECTED_METERED:
792 result.type = kDriveConnectionTypeMetered; 792 result.type = kDriveConnectionTypeMetered;
793 break; 793 break;
794 case drive::util::DRIVE_CONNECTED: 794 case drive::util::DRIVE_CONNECTED:
795 result.type = kDriveConnectionTypeOnline; 795 result.type = kDriveConnectionTypeOnline;
796 break; 796 break;
797 } 797 }
798 798
799 results_ = api::file_browser_private::GetDriveConnectionState::Results:: 799 results_ = api::file_manager_private::GetDriveConnectionState::Results::
800 Create(result); 800 Create(result);
801 801
802 drive::EventLogger* logger = file_manager::util::GetLogger(GetProfile()); 802 drive::EventLogger* logger = file_manager::util::GetLogger(GetProfile());
803 if (logger) 803 if (logger)
804 logger->Log(logging::LOG_INFO, "%s succeeded.", name().c_str()); 804 logger->Log(logging::LOG_INFO, "%s succeeded.", name().c_str());
805 return true; 805 return true;
806 } 806 }
807 807
808 bool FileBrowserPrivateRequestAccessTokenFunction::RunAsync() { 808 bool FileManagerPrivateRequestAccessTokenFunction::RunAsync() {
809 using extensions::api::file_browser_private::RequestAccessToken::Params; 809 using extensions::api::file_manager_private::RequestAccessToken::Params;
810 const scoped_ptr<Params> params(Params::Create(*args_)); 810 const scoped_ptr<Params> params(Params::Create(*args_));
811 EXTENSION_FUNCTION_VALIDATE(params); 811 EXTENSION_FUNCTION_VALIDATE(params);
812 812
813 drive::DriveServiceInterface* const drive_service = 813 drive::DriveServiceInterface* const drive_service =
814 drive::util::GetDriveServiceByProfile(GetProfile()); 814 drive::util::GetDriveServiceByProfile(GetProfile());
815 815
816 if (!drive_service) { 816 if (!drive_service) {
817 // DriveService is not available. 817 // DriveService is not available.
818 SetResult(new base::StringValue("")); 818 SetResult(new base::StringValue(""));
819 SendResponse(true); 819 SendResponse(true);
820 return true; 820 return true;
821 } 821 }
822 822
823 // If refreshing is requested, then clear the token to refetch it. 823 // If refreshing is requested, then clear the token to refetch it.
824 if (params->refresh) 824 if (params->refresh)
825 drive_service->ClearAccessToken(); 825 drive_service->ClearAccessToken();
826 826
827 // Retrieve the cached auth token (if available), otherwise the AuthService 827 // Retrieve the cached auth token (if available), otherwise the AuthService
828 // instance will try to refetch it. 828 // instance will try to refetch it.
829 drive_service->RequestAccessToken( 829 drive_service->RequestAccessToken(
830 base::Bind(&FileBrowserPrivateRequestAccessTokenFunction:: 830 base::Bind(&FileManagerPrivateRequestAccessTokenFunction::
831 OnAccessTokenFetched, this)); 831 OnAccessTokenFetched, this));
832 return true; 832 return true;
833 } 833 }
834 834
835 void FileBrowserPrivateRequestAccessTokenFunction::OnAccessTokenFetched( 835 void FileManagerPrivateRequestAccessTokenFunction::OnAccessTokenFetched(
836 google_apis::GDataErrorCode code, 836 google_apis::GDataErrorCode code,
837 const std::string& access_token) { 837 const std::string& access_token) {
838 SetResult(new base::StringValue(access_token)); 838 SetResult(new base::StringValue(access_token));
839 SendResponse(true); 839 SendResponse(true);
840 } 840 }
841 841
842 bool FileBrowserPrivateGetShareUrlFunction::RunAsync() { 842 bool FileManagerPrivateGetShareUrlFunction::RunAsync() {
843 using extensions::api::file_browser_private::GetShareUrl::Params; 843 using extensions::api::file_manager_private::GetShareUrl::Params;
844 const scoped_ptr<Params> params(Params::Create(*args_)); 844 const scoped_ptr<Params> params(Params::Create(*args_));
845 EXTENSION_FUNCTION_VALIDATE(params); 845 EXTENSION_FUNCTION_VALIDATE(params);
846 846
847 const base::FilePath path = file_manager::util::GetLocalPathFromURL( 847 const base::FilePath path = file_manager::util::GetLocalPathFromURL(
848 render_view_host(), GetProfile(), GURL(params->url)); 848 render_view_host(), GetProfile(), GURL(params->url));
849 DCHECK(drive::util::IsUnderDriveMountPoint(path)); 849 DCHECK(drive::util::IsUnderDriveMountPoint(path));
850 850
851 const base::FilePath drive_path = drive::util::ExtractDrivePath(path); 851 const base::FilePath drive_path = drive::util::ExtractDrivePath(path);
852 852
853 drive::FileSystemInterface* const file_system = 853 drive::FileSystemInterface* const file_system =
854 drive::util::GetFileSystemByProfile(GetProfile()); 854 drive::util::GetFileSystemByProfile(GetProfile());
855 if (!file_system) { 855 if (!file_system) {
856 // |file_system| is NULL if Drive is disabled. 856 // |file_system| is NULL if Drive is disabled.
857 return false; 857 return false;
858 } 858 }
859 859
860 file_system->GetShareUrl( 860 file_system->GetShareUrl(
861 drive_path, 861 drive_path,
862 GURL("chrome-extension://" + extension_id()), // embed origin 862 GURL("chrome-extension://" + extension_id()), // embed origin
863 base::Bind(&FileBrowserPrivateGetShareUrlFunction::OnGetShareUrl, this)); 863 base::Bind(&FileManagerPrivateGetShareUrlFunction::OnGetShareUrl, this));
864 return true; 864 return true;
865 } 865 }
866 866
867 void FileBrowserPrivateGetShareUrlFunction::OnGetShareUrl( 867 void FileManagerPrivateGetShareUrlFunction::OnGetShareUrl(
868 drive::FileError error, 868 drive::FileError error,
869 const GURL& share_url) { 869 const GURL& share_url) {
870 if (error != drive::FILE_ERROR_OK) { 870 if (error != drive::FILE_ERROR_OK) {
871 SetError("Share Url for this item is not available."); 871 SetError("Share Url for this item is not available.");
872 SendResponse(false); 872 SendResponse(false);
873 return; 873 return;
874 } 874 }
875 875
876 SetResult(new base::StringValue(share_url.spec())); 876 SetResult(new base::StringValue(share_url.spec()));
877 SendResponse(true); 877 SendResponse(true);
878 } 878 }
879 879
880 bool FileBrowserPrivateRequestDriveShareFunction::RunAsync() { 880 bool FileManagerPrivateRequestDriveShareFunction::RunAsync() {
881 using extensions::api::file_browser_private::RequestDriveShare::Params; 881 using extensions::api::file_manager_private::RequestDriveShare::Params;
882 const scoped_ptr<Params> params(Params::Create(*args_)); 882 const scoped_ptr<Params> params(Params::Create(*args_));
883 EXTENSION_FUNCTION_VALIDATE(params); 883 EXTENSION_FUNCTION_VALIDATE(params);
884 884
885 const base::FilePath path = file_manager::util::GetLocalPathFromURL( 885 const base::FilePath path = file_manager::util::GetLocalPathFromURL(
886 render_view_host(), GetProfile(), GURL(params->url)); 886 render_view_host(), GetProfile(), GURL(params->url));
887 const base::FilePath drive_path = drive::util::ExtractDrivePath(path); 887 const base::FilePath drive_path = drive::util::ExtractDrivePath(path);
888 Profile* const owner_profile = drive::util::ExtractProfileFromPath(path); 888 Profile* const owner_profile = drive::util::ExtractProfileFromPath(path);
889 889
890 if (!owner_profile) 890 if (!owner_profile)
891 return false; 891 return false;
892 892
893 drive::FileSystemInterface* const owner_file_system = 893 drive::FileSystemInterface* const owner_file_system =
894 drive::util::GetFileSystemByProfile(owner_profile); 894 drive::util::GetFileSystemByProfile(owner_profile);
895 if (!owner_file_system) 895 if (!owner_file_system)
896 return false; 896 return false;
897 897
898 const user_manager::User* const user = 898 const user_manager::User* const user =
899 chromeos::ProfileHelper::Get()->GetUserByProfile(GetProfile()); 899 chromeos::ProfileHelper::Get()->GetUserByProfile(GetProfile());
900 if (!user || !user->is_logged_in()) 900 if (!user || !user->is_logged_in())
901 return false; 901 return false;
902 902
903 google_apis::drive::PermissionRole role = 903 google_apis::drive::PermissionRole role =
904 google_apis::drive::PERMISSION_ROLE_READER; 904 google_apis::drive::PERMISSION_ROLE_READER;
905 switch (params->share_type) { 905 switch (params->share_type) {
906 case api::file_browser_private::DRIVE_SHARE_TYPE_NONE: 906 case api::file_manager_private::DRIVE_SHARE_TYPE_NONE:
907 NOTREACHED(); 907 NOTREACHED();
908 return false; 908 return false;
909 case api::file_browser_private::DRIVE_SHARE_TYPE_CAN_EDIT: 909 case api::file_manager_private::DRIVE_SHARE_TYPE_CAN_EDIT:
910 role = google_apis::drive::PERMISSION_ROLE_WRITER; 910 role = google_apis::drive::PERMISSION_ROLE_WRITER;
911 break; 911 break;
912 case api::file_browser_private::DRIVE_SHARE_TYPE_CAN_COMMENT: 912 case api::file_manager_private::DRIVE_SHARE_TYPE_CAN_COMMENT:
913 role = google_apis::drive::PERMISSION_ROLE_COMMENTER; 913 role = google_apis::drive::PERMISSION_ROLE_COMMENTER;
914 break; 914 break;
915 case api::file_browser_private::DRIVE_SHARE_TYPE_CAN_VIEW: 915 case api::file_manager_private::DRIVE_SHARE_TYPE_CAN_VIEW:
916 role = google_apis::drive::PERMISSION_ROLE_READER; 916 role = google_apis::drive::PERMISSION_ROLE_READER;
917 break; 917 break;
918 } 918 }
919 919
920 // Share |drive_path| in |owner_file_system| to |user->email()|. 920 // Share |drive_path| in |owner_file_system| to |user->email()|.
921 owner_file_system->AddPermission( 921 owner_file_system->AddPermission(
922 drive_path, 922 drive_path,
923 user->email(), 923 user->email(),
924 role, 924 role,
925 base::Bind(&FileBrowserPrivateRequestDriveShareFunction::OnAddPermission, 925 base::Bind(&FileManagerPrivateRequestDriveShareFunction::OnAddPermission,
926 this)); 926 this));
927 return true; 927 return true;
928 } 928 }
929 929
930 void FileBrowserPrivateRequestDriveShareFunction::OnAddPermission( 930 void FileManagerPrivateRequestDriveShareFunction::OnAddPermission(
931 drive::FileError error) { 931 drive::FileError error) {
932 SendResponse(error == drive::FILE_ERROR_OK); 932 SendResponse(error == drive::FILE_ERROR_OK);
933 } 933 }
934 934
935 FileBrowserPrivateGetDownloadUrlFunction:: 935 FileManagerPrivateGetDownloadUrlFunction::
936 FileBrowserPrivateGetDownloadUrlFunction() { 936 FileManagerPrivateGetDownloadUrlFunction() {
937 } 937 }
938 938
939 FileBrowserPrivateGetDownloadUrlFunction:: 939 FileManagerPrivateGetDownloadUrlFunction::
940 ~FileBrowserPrivateGetDownloadUrlFunction() { 940 ~FileManagerPrivateGetDownloadUrlFunction() {
941 } 941 }
942 942
943 bool FileBrowserPrivateGetDownloadUrlFunction::RunAsync() { 943 bool FileManagerPrivateGetDownloadUrlFunction::RunAsync() {
944 using extensions::api::file_browser_private::GetShareUrl::Params; 944 using extensions::api::file_manager_private::GetShareUrl::Params;
945 const scoped_ptr<Params> params(Params::Create(*args_)); 945 const scoped_ptr<Params> params(Params::Create(*args_));
946 EXTENSION_FUNCTION_VALIDATE(params); 946 EXTENSION_FUNCTION_VALIDATE(params);
947 947
948 // Start getting the file info. 948 // Start getting the file info.
949 drive::FileSystemInterface* const file_system = 949 drive::FileSystemInterface* const file_system =
950 drive::util::GetFileSystemByProfile(GetProfile()); 950 drive::util::GetFileSystemByProfile(GetProfile());
951 if (!file_system) { 951 if (!file_system) {
952 // |file_system| is NULL if Drive is disabled or not mounted. 952 // |file_system| is NULL if Drive is disabled or not mounted.
953 SetError("Drive is disabled or not mounted."); 953 SetError("Drive is disabled or not mounted.");
954 SetResult(new base::StringValue("")); // Intentionally returns a blank. 954 SetResult(new base::StringValue("")); // Intentionally returns a blank.
955 return false; 955 return false;
956 } 956 }
957 957
958 const base::FilePath path = file_manager::util::GetLocalPathFromURL( 958 const base::FilePath path = file_manager::util::GetLocalPathFromURL(
959 render_view_host(), GetProfile(), GURL(params->url)); 959 render_view_host(), GetProfile(), GURL(params->url));
960 if (!drive::util::IsUnderDriveMountPoint(path)) { 960 if (!drive::util::IsUnderDriveMountPoint(path)) {
961 SetError("The given file is not in Drive."); 961 SetError("The given file is not in Drive.");
962 SetResult(new base::StringValue("")); // Intentionally returns a blank. 962 SetResult(new base::StringValue("")); // Intentionally returns a blank.
963 return false; 963 return false;
964 } 964 }
965 base::FilePath file_path = drive::util::ExtractDrivePath(path); 965 base::FilePath file_path = drive::util::ExtractDrivePath(path);
966 966
967 file_system->GetResourceEntry( 967 file_system->GetResourceEntry(
968 file_path, 968 file_path,
969 base::Bind(&FileBrowserPrivateGetDownloadUrlFunction::OnGetResourceEntry, 969 base::Bind(&FileManagerPrivateGetDownloadUrlFunction::OnGetResourceEntry,
970 this)); 970 this));
971 return true; 971 return true;
972 } 972 }
973 973
974 void FileBrowserPrivateGetDownloadUrlFunction::OnGetResourceEntry( 974 void FileManagerPrivateGetDownloadUrlFunction::OnGetResourceEntry(
975 drive::FileError error, 975 drive::FileError error,
976 scoped_ptr<drive::ResourceEntry> entry) { 976 scoped_ptr<drive::ResourceEntry> entry) {
977 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 977 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
978 978
979 if (error != drive::FILE_ERROR_OK) { 979 if (error != drive::FILE_ERROR_OK) {
980 SetError("Download Url for this item is not available."); 980 SetError("Download Url for this item is not available.");
981 SetResult(new base::StringValue("")); // Intentionally returns a blank. 981 SetResult(new base::StringValue("")); // Intentionally returns a blank.
982 SendResponse(false); 982 SendResponse(false);
983 return; 983 return;
984 } 984 }
985 985
986 download_url_ = 986 download_url_ =
987 google_apis::DriveApiUrlGenerator::kBaseDownloadUrlForProduction + 987 google_apis::DriveApiUrlGenerator::kBaseDownloadUrlForProduction +
988 entry->resource_id(); 988 entry->resource_id();
989 989
990 ProfileOAuth2TokenService* oauth2_token_service = 990 ProfileOAuth2TokenService* oauth2_token_service =
991 ProfileOAuth2TokenServiceFactory::GetForProfile(GetProfile()); 991 ProfileOAuth2TokenServiceFactory::GetForProfile(GetProfile());
992 SigninManagerBase* signin_manager = 992 SigninManagerBase* signin_manager =
993 SigninManagerFactory::GetForProfile(GetProfile()); 993 SigninManagerFactory::GetForProfile(GetProfile());
994 const std::string& account_id = signin_manager->GetAuthenticatedAccountId(); 994 const std::string& account_id = signin_manager->GetAuthenticatedAccountId();
995 std::vector<std::string> scopes; 995 std::vector<std::string> scopes;
996 scopes.push_back("https://www.googleapis.com/auth/drive.readonly"); 996 scopes.push_back("https://www.googleapis.com/auth/drive.readonly");
997 997
998 auth_service_.reset( 998 auth_service_.reset(
999 new google_apis::AuthService(oauth2_token_service, 999 new google_apis::AuthService(oauth2_token_service,
1000 account_id, 1000 account_id,
1001 GetProfile()->GetRequestContext(), 1001 GetProfile()->GetRequestContext(),
1002 scopes)); 1002 scopes));
1003 auth_service_->StartAuthentication(base::Bind( 1003 auth_service_->StartAuthentication(base::Bind(
1004 &FileBrowserPrivateGetDownloadUrlFunction::OnTokenFetched, this)); 1004 &FileManagerPrivateGetDownloadUrlFunction::OnTokenFetched, this));
1005 } 1005 }
1006 1006
1007 void FileBrowserPrivateGetDownloadUrlFunction::OnTokenFetched( 1007 void FileManagerPrivateGetDownloadUrlFunction::OnTokenFetched(
1008 google_apis::GDataErrorCode code, 1008 google_apis::GDataErrorCode code,
1009 const std::string& access_token) { 1009 const std::string& access_token) {
1010 if (code != google_apis::HTTP_SUCCESS) { 1010 if (code != google_apis::HTTP_SUCCESS) {
1011 SetError("Not able to fetch the token."); 1011 SetError("Not able to fetch the token.");
1012 SetResult(new base::StringValue("")); // Intentionally returns a blank. 1012 SetResult(new base::StringValue("")); // Intentionally returns a blank.
1013 SendResponse(false); 1013 SendResponse(false);
1014 return; 1014 return;
1015 } 1015 }
1016 1016
1017 const std::string url = download_url_ + "?access_token=" + access_token; 1017 const std::string url = download_url_ + "?access_token=" + access_token;
1018 SetResult(new base::StringValue(url)); 1018 SetResult(new base::StringValue(url));
1019 1019
1020 SendResponse(true); 1020 SendResponse(true);
1021 } 1021 }
1022 1022
1023 } // namespace extensions 1023 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698