| 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 "base/base64.h" | 7 #include "base/base64.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/memory/singleton.h" | 11 #include "base/memory/singleton.h" |
| 12 #include "base/string_split.h" | 12 #include "base/string_split.h" |
| 13 #include "base/stringprintf.h" | 13 #include "base/stringprintf.h" |
| 14 #include "base/time.h" | 14 #include "base/time.h" |
| 15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 #include "chrome/browser/chromeos/extensions/file_browser_event_router.h" | 16 #include "chrome/browser/chromeos/extensions/file_browser_event_router.h" |
| 17 #include "chrome/browser/chromeos/extensions/file_handler_util.h" | 17 #include "chrome/browser/chromeos/extensions/file_handler_util.h" |
| 18 #include "chrome/browser/chromeos/extensions/file_manager_util.h" | 18 #include "chrome/browser/chromeos/extensions/file_manager_util.h" |
| 19 #include "chrome/browser/chromeos/gdata/gdata_file_system_proxy.h" | 19 #include "chrome/browser/chromeos/gdata/gdata_file_system_proxy.h" |
| 20 #include "chrome/browser/chromeos/gdata/gdata_operation_registry.h" |
| 20 #include "chrome/browser/chromeos/gdata/gdata_util.h" | 21 #include "chrome/browser/chromeos/gdata/gdata_util.h" |
| 21 #include "chrome/browser/extensions/extension_function_dispatcher.h" | 22 #include "chrome/browser/extensions/extension_function_dispatcher.h" |
| 22 #include "chrome/browser/extensions/extension_process_manager.h" | 23 #include "chrome/browser/extensions/extension_process_manager.h" |
| 23 #include "chrome/browser/extensions/extension_service.h" | 24 #include "chrome/browser/extensions/extension_service.h" |
| 24 #include "chrome/browser/extensions/extension_tab_util.h" | 25 #include "chrome/browser/extensions/extension_tab_util.h" |
| 25 #include "chrome/browser/extensions/process_map.h" | 26 #include "chrome/browser/extensions/process_map.h" |
| 26 #include "chrome/browser/prefs/pref_service.h" | 27 #include "chrome/browser/prefs/pref_service.h" |
| 27 #include "chrome/browser/profiles/profile.h" | 28 #include "chrome/browser/profiles/profile.h" |
| 28 #include "chrome/browser/ui/browser.h" | 29 #include "chrome/browser/ui/browser.h" |
| 29 #include "chrome/browser/ui/browser_window.h" | 30 #include "chrome/browser/ui/browser_window.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 53 #include "chrome/browser/chromeos/disks/disk_mount_manager.h" | 54 #include "chrome/browser/chromeos/disks/disk_mount_manager.h" |
| 54 #endif | 55 #endif |
| 55 | 56 |
| 56 using chromeos::disks::DiskMountManager; | 57 using chromeos::disks::DiskMountManager; |
| 57 using content::BrowserContext; | 58 using content::BrowserContext; |
| 58 using content::BrowserThread; | 59 using content::BrowserThread; |
| 59 using content::ChildProcessSecurityPolicy; | 60 using content::ChildProcessSecurityPolicy; |
| 60 using content::SiteInstance; | 61 using content::SiteInstance; |
| 61 using content::WebContents; | 62 using content::WebContents; |
| 62 using file_handler_util::FileTaskExecutor; | 63 using file_handler_util::FileTaskExecutor; |
| 64 using gdata::GDataOperationRegistry; |
| 63 | 65 |
| 64 namespace { | 66 namespace { |
| 65 | 67 |
| 66 // Error messages. | 68 // Error messages. |
| 67 const char kFileError[] = "File error %d"; | 69 const char kFileError[] = "File error %d"; |
| 68 const char kInvalidFileUrl[] = "Invalid file URL"; | 70 const char kInvalidFileUrl[] = "Invalid file URL"; |
| 69 const char kVolumeDevicePathNotFound[] = "Device path not found"; | 71 const char kVolumeDevicePathNotFound[] = "Device path not found"; |
| 70 | 72 |
| 71 // Unescape rules used for parsing query parameters. | 73 // Unescape rules used for parsing query parameters. |
| 72 const net::UnescapeRule::Type kUnescapeRuleForQueryParameters = | 74 const net::UnescapeRule::Type kUnescapeRuleForQueryParameters = |
| (...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 515 base::Bind( | 517 base::Bind( |
| 516 &FileWatchBrowserFunctionBase::RespondOnUIThread, | 518 &FileWatchBrowserFunctionBase::RespondOnUIThread, |
| 517 this, | 519 this, |
| 518 true)); | 520 true)); |
| 519 } | 521 } |
| 520 | 522 |
| 521 bool AddFileWatchBrowserFunction::PerformFileWatchOperation( | 523 bool AddFileWatchBrowserFunction::PerformFileWatchOperation( |
| 522 const FilePath& local_path, const FilePath& virtual_path, | 524 const FilePath& local_path, const FilePath& virtual_path, |
| 523 const std::string& extension_id) { | 525 const std::string& extension_id) { |
| 524 #if defined(OS_CHROMEOS) | 526 #if defined(OS_CHROMEOS) |
| 525 return profile_->GetExtensionService()->file_browser_event_router()-> | 527 return FileBrowserEventRouterFactory::GetForProfile(profile_)-> |
| 526 AddFileWatch(local_path, virtual_path, extension_id); | 528 AddFileWatch(local_path, virtual_path, extension_id); |
| 527 #else | 529 #else |
| 528 return true; | 530 return true; |
| 529 #endif // defined(OS_CHROMEOS) | 531 #endif // defined(OS_CHROMEOS) |
| 530 } | 532 } |
| 531 | 533 |
| 532 bool RemoveFileWatchBrowserFunction::PerformFileWatchOperation( | 534 bool RemoveFileWatchBrowserFunction::PerformFileWatchOperation( |
| 533 const FilePath& local_path, const FilePath& unused, | 535 const FilePath& local_path, const FilePath& unused, |
| 534 const std::string& extension_id) { | 536 const std::string& extension_id) { |
| 535 #if defined(OS_CHROMEOS) | 537 #if defined(OS_CHROMEOS) |
| 536 profile_->GetExtensionService()->file_browser_event_router()-> | 538 FileBrowserEventRouterFactory::GetForProfile(profile_)-> |
| 537 RemoveFileWatch(local_path, extension_id); | 539 RemoveFileWatch(local_path, extension_id); |
| 538 #endif | 540 #endif |
| 539 return true; | 541 return true; |
| 540 } | 542 } |
| 541 | 543 |
| 542 bool GetFileTasksFileBrowserFunction::RunImpl() { | 544 bool GetFileTasksFileBrowserFunction::RunImpl() { |
| 543 ListValue* files_list = NULL; | 545 ListValue* files_list = NULL; |
| 544 if (!args_->GetList(0, &files_list)) | 546 if (!args_->GetList(0, &files_list)) |
| 545 return false; | 547 return false; |
| 546 | 548 |
| (...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 997 | 999 |
| 998 void AddMountFunction::RaiseGDataMountEvent(gdata::GDataErrorCode error) { | 1000 void AddMountFunction::RaiseGDataMountEvent(gdata::GDataErrorCode error) { |
| 999 chromeos::MountError error_code = error == gdata::HTTP_SUCCESS ? | 1001 chromeos::MountError error_code = error == gdata::HTTP_SUCCESS ? |
| 1000 chromeos::MOUNT_ERROR_NONE : chromeos::MOUNT_ERROR_NOT_AUTHENTICATED; | 1002 chromeos::MOUNT_ERROR_NONE : chromeos::MOUNT_ERROR_NOT_AUTHENTICATED; |
| 1001 DiskMountManager::MountPointInfo mount_info( | 1003 DiskMountManager::MountPointInfo mount_info( |
| 1002 gdata::util::GetGDataMountPointPathAsString(), | 1004 gdata::util::GetGDataMountPointPathAsString(), |
| 1003 gdata::util::GetGDataMountPointPathAsString(), | 1005 gdata::util::GetGDataMountPointPathAsString(), |
| 1004 chromeos::MOUNT_TYPE_GDATA, | 1006 chromeos::MOUNT_TYPE_GDATA, |
| 1005 chromeos::disks::MOUNT_CONDITION_NONE); | 1007 chromeos::disks::MOUNT_CONDITION_NONE); |
| 1006 // Raise mount event | 1008 // Raise mount event |
| 1007 profile_->GetExtensionService()->file_browser_event_router()->MountCompleted( | 1009 FileBrowserEventRouterFactory::GetForProfile(profile_)-> |
| 1008 DiskMountManager::MOUNTING, | 1010 MountCompleted(DiskMountManager::MOUNTING, error_code, mount_info); |
| 1009 error_code, | |
| 1010 mount_info); | |
| 1011 } | 1011 } |
| 1012 | 1012 |
| 1013 void AddMountFunction::OnGDataAuthentication(gdata::GDataErrorCode error, | 1013 void AddMountFunction::OnGDataAuthentication(gdata::GDataErrorCode error, |
| 1014 const std::string& token) { | 1014 const std::string& token) { |
| 1015 if (error == gdata::HTTP_SUCCESS) | 1015 if (error == gdata::HTTP_SUCCESS) |
| 1016 AddGDataMountPoint(); | 1016 AddGDataMountPoint(); |
| 1017 | 1017 |
| 1018 RaiseGDataMountEvent(error); | 1018 RaiseGDataMountEvent(error); |
| 1019 SendResponse(true); | 1019 SendResponse(true); |
| 1020 } | 1020 } |
| (...skipping 686 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1707 local_paths_->Append(Value::CreateStringValue("")); | 1707 local_paths_->Append(Value::CreateStringValue("")); |
| 1708 DVLOG(1) << "Failed to get " << gdata_path.value() | 1708 DVLOG(1) << "Failed to get " << gdata_path.value() |
| 1709 << " with error code: " << error; | 1709 << " with error code: " << error; |
| 1710 } | 1710 } |
| 1711 | 1711 |
| 1712 remaining_gdata_paths_.pop(); | 1712 remaining_gdata_paths_.pop(); |
| 1713 | 1713 |
| 1714 // Start getting the next file. | 1714 // Start getting the next file. |
| 1715 GetFileOrSendResponse(); | 1715 GetFileOrSendResponse(); |
| 1716 } | 1716 } |
| 1717 |
| 1718 GetFileTransfersFunction::GetFileTransfersFunction() {} |
| 1719 |
| 1720 GetFileTransfersFunction::~GetFileTransfersFunction() {} |
| 1721 |
| 1722 ListValue* GetFileTransfersFunction::GetFileTransfersList() { |
| 1723 gdata::GDataFileSystem* file_system = |
| 1724 gdata::GDataFileSystemFactory::GetForProfile(profile_); |
| 1725 if (!file_system) |
| 1726 return NULL; |
| 1727 |
| 1728 std::vector<gdata::GDataOperationRegistry::ProgressStatus> |
| 1729 list = file_system->GetProgressStatusList(); |
| 1730 return file_manager_util::ProgressStatusVectorToListValue( |
| 1731 profile_, source_url_.GetOrigin(), list); |
| 1732 } |
| 1733 |
| 1734 bool GetFileTransfersFunction::RunImpl() { |
| 1735 scoped_ptr<ListValue> progress_status_list(GetFileTransfersList()); |
| 1736 if (!progress_status_list.get()) { |
| 1737 SendResponse(false); |
| 1738 return false; |
| 1739 } |
| 1740 |
| 1741 result_.reset(progress_status_list.release()); |
| 1742 SendResponse(true); |
| 1743 return true; |
| 1744 } |
| 1745 |
| OLD | NEW |