| 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/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/string_split.h" | 13 #include "base/string_split.h" |
| 14 #include "base/stringprintf.h" | 14 #include "base/stringprintf.h" |
| 15 #include "base/time.h" | 15 #include "base/time.h" |
| 16 #include "base/values.h" | 16 #include "base/values.h" |
| 17 #include "chrome/browser/chromeos/extensions/file_browser_event_router.h" | 17 #include "chrome/browser/chromeos/extensions/file_browser_event_router.h" |
| 18 #include "chrome/browser/chromeos/extensions/file_handler_util.h" | 18 #include "chrome/browser/chromeos/extensions/file_handler_util.h" |
| 19 #include "chrome/browser/chromeos/extensions/file_manager_util.h" | 19 #include "chrome/browser/chromeos/extensions/file_manager_util.h" |
| 20 #include "chrome/browser/chromeos/gdata/gdata_file_system_proxy.h" | 20 #include "chrome/browser/chromeos/gdata/gdata_file_system_proxy.h" |
| 21 #include "chrome/browser/chromeos/gdata/gdata_operation_registry.h" | |
| 22 #include "chrome/browser/chromeos/gdata/gdata_util.h" | 21 #include "chrome/browser/chromeos/gdata/gdata_util.h" |
| 23 #include "chrome/browser/extensions/extension_function_dispatcher.h" | 22 #include "chrome/browser/extensions/extension_function_dispatcher.h" |
| 24 #include "chrome/browser/extensions/extension_process_manager.h" | 23 #include "chrome/browser/extensions/extension_process_manager.h" |
| 25 #include "chrome/browser/extensions/extension_service.h" | 24 #include "chrome/browser/extensions/extension_service.h" |
| 26 #include "chrome/browser/extensions/extension_tab_util.h" | 25 #include "chrome/browser/extensions/extension_tab_util.h" |
| 27 #include "chrome/browser/extensions/process_map.h" | 26 #include "chrome/browser/extensions/process_map.h" |
| 28 #include "chrome/browser/prefs/pref_service.h" | 27 #include "chrome/browser/prefs/pref_service.h" |
| 29 #include "chrome/browser/profiles/profile.h" | 28 #include "chrome/browser/profiles/profile.h" |
| 30 #include "chrome/browser/ui/browser.h" | 29 #include "chrome/browser/ui/browser.h" |
| 31 #include "chrome/browser/ui/browser_window.h" | 30 #include "chrome/browser/ui/browser_window.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 55 #include "chrome/browser/chromeos/disks/disk_mount_manager.h" | 54 #include "chrome/browser/chromeos/disks/disk_mount_manager.h" |
| 56 #endif | 55 #endif |
| 57 | 56 |
| 58 using chromeos::disks::DiskMountManager; | 57 using chromeos::disks::DiskMountManager; |
| 59 using content::BrowserContext; | 58 using content::BrowserContext; |
| 60 using content::BrowserThread; | 59 using content::BrowserThread; |
| 61 using content::ChildProcessSecurityPolicy; | 60 using content::ChildProcessSecurityPolicy; |
| 62 using content::SiteInstance; | 61 using content::SiteInstance; |
| 63 using content::WebContents; | 62 using content::WebContents; |
| 64 using file_handler_util::FileTaskExecutor; | 63 using file_handler_util::FileTaskExecutor; |
| 65 using gdata::GDataOperationRegistry; | |
| 66 | 64 |
| 67 namespace { | 65 namespace { |
| 68 | 66 |
| 69 // Error messages. | 67 // Error messages. |
| 70 const char kFileError[] = "File error %d"; | 68 const char kFileError[] = "File error %d"; |
| 71 const char kInvalidFileUrl[] = "Invalid file URL"; | 69 const char kInvalidFileUrl[] = "Invalid file URL"; |
| 72 const char kVolumeDevicePathNotFound[] = "Device path not found"; | 70 const char kVolumeDevicePathNotFound[] = "Device path not found"; |
| 73 | 71 |
| 74 // Unescape rules used for parsing query parameters. | 72 // Unescape rules used for parsing query parameters. |
| 75 const net::UnescapeRule::Type kUnescapeRuleForQueryParameters = | 73 const net::UnescapeRule::Type kUnescapeRuleForQueryParameters = |
| (...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 base::Bind( | 556 base::Bind( |
| 559 &FileWatchBrowserFunctionBase::RespondOnUIThread, | 557 &FileWatchBrowserFunctionBase::RespondOnUIThread, |
| 560 this, | 558 this, |
| 561 true)); | 559 true)); |
| 562 } | 560 } |
| 563 | 561 |
| 564 bool AddFileWatchBrowserFunction::PerformFileWatchOperation( | 562 bool AddFileWatchBrowserFunction::PerformFileWatchOperation( |
| 565 const FilePath& local_path, const FilePath& virtual_path, | 563 const FilePath& local_path, const FilePath& virtual_path, |
| 566 const std::string& extension_id) { | 564 const std::string& extension_id) { |
| 567 #if defined(OS_CHROMEOS) | 565 #if defined(OS_CHROMEOS) |
| 568 return FileBrowserEventRouterFactory::GetForProfile(profile_)-> | 566 return profile_->GetExtensionService()->file_browser_event_router()-> |
| 569 AddFileWatch(local_path, virtual_path, extension_id); | 567 AddFileWatch(local_path, virtual_path, extension_id); |
| 570 #else | 568 #else |
| 571 return true; | 569 return true; |
| 572 #endif // defined(OS_CHROMEOS) | 570 #endif // defined(OS_CHROMEOS) |
| 573 } | 571 } |
| 574 | 572 |
| 575 bool RemoveFileWatchBrowserFunction::PerformFileWatchOperation( | 573 bool RemoveFileWatchBrowserFunction::PerformFileWatchOperation( |
| 576 const FilePath& local_path, const FilePath& unused, | 574 const FilePath& local_path, const FilePath& unused, |
| 577 const std::string& extension_id) { | 575 const std::string& extension_id) { |
| 578 #if defined(OS_CHROMEOS) | 576 #if defined(OS_CHROMEOS) |
| 579 FileBrowserEventRouterFactory::GetForProfile(profile_)-> | 577 profile_->GetExtensionService()->file_browser_event_router()-> |
| 580 RemoveFileWatch(local_path, extension_id); | 578 RemoveFileWatch(local_path, extension_id); |
| 581 #endif | 579 #endif |
| 582 return true; | 580 return true; |
| 583 } | 581 } |
| 584 | 582 |
| 585 bool GetFileTasksFileBrowserFunction::RunImpl() { | 583 bool GetFileTasksFileBrowserFunction::RunImpl() { |
| 586 ListValue* files_list = NULL; | 584 ListValue* files_list = NULL; |
| 587 if (!args_->GetList(0, &files_list)) | 585 if (!args_->GetList(0, &files_list)) |
| 588 return false; | 586 return false; |
| 589 | 587 |
| (...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1040 | 1038 |
| 1041 void AddMountFunction::RaiseGDataMountEvent(gdata::GDataErrorCode error) { | 1039 void AddMountFunction::RaiseGDataMountEvent(gdata::GDataErrorCode error) { |
| 1042 chromeos::MountError error_code = error == gdata::HTTP_SUCCESS ? | 1040 chromeos::MountError error_code = error == gdata::HTTP_SUCCESS ? |
| 1043 chromeos::MOUNT_ERROR_NONE : chromeos::MOUNT_ERROR_NOT_AUTHENTICATED; | 1041 chromeos::MOUNT_ERROR_NONE : chromeos::MOUNT_ERROR_NOT_AUTHENTICATED; |
| 1044 DiskMountManager::MountPointInfo mount_info( | 1042 DiskMountManager::MountPointInfo mount_info( |
| 1045 gdata::util::GetGDataMountPointPathAsString(), | 1043 gdata::util::GetGDataMountPointPathAsString(), |
| 1046 gdata::util::GetGDataMountPointPathAsString(), | 1044 gdata::util::GetGDataMountPointPathAsString(), |
| 1047 chromeos::MOUNT_TYPE_GDATA, | 1045 chromeos::MOUNT_TYPE_GDATA, |
| 1048 chromeos::disks::MOUNT_CONDITION_NONE); | 1046 chromeos::disks::MOUNT_CONDITION_NONE); |
| 1049 // Raise mount event | 1047 // Raise mount event |
| 1050 FileBrowserEventRouterFactory::GetForProfile(profile_)-> | 1048 profile_->GetExtensionService()->file_browser_event_router()->MountCompleted( |
| 1051 MountCompleted(DiskMountManager::MOUNTING, error_code, mount_info); | 1049 DiskMountManager::MOUNTING, |
| 1050 error_code, |
| 1051 mount_info); |
| 1052 } | 1052 } |
| 1053 | 1053 |
| 1054 void AddMountFunction::OnGDataAuthentication(gdata::GDataErrorCode error, | 1054 void AddMountFunction::OnGDataAuthentication(gdata::GDataErrorCode error, |
| 1055 const std::string& token) { | 1055 const std::string& token) { |
| 1056 if (error == gdata::HTTP_SUCCESS) | 1056 if (error == gdata::HTTP_SUCCESS) |
| 1057 AddGDataMountPoint(); | 1057 AddGDataMountPoint(); |
| 1058 | 1058 |
| 1059 RaiseGDataMountEvent(error); | 1059 RaiseGDataMountEvent(error); |
| 1060 SendResponse(true); | 1060 SendResponse(true); |
| 1061 } | 1061 } |
| (...skipping 686 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1748 local_paths_->Append(Value::CreateStringValue("")); | 1748 local_paths_->Append(Value::CreateStringValue("")); |
| 1749 DVLOG(1) << "Failed to get " << gdata_path.value() | 1749 DVLOG(1) << "Failed to get " << gdata_path.value() |
| 1750 << " with error code: " << error; | 1750 << " with error code: " << error; |
| 1751 } | 1751 } |
| 1752 | 1752 |
| 1753 remaining_gdata_paths_.pop(); | 1753 remaining_gdata_paths_.pop(); |
| 1754 | 1754 |
| 1755 // Start getting the next file. | 1755 // Start getting the next file. |
| 1756 GetFileOrSendResponse(); | 1756 GetFileOrSendResponse(); |
| 1757 } | 1757 } |
| 1758 | |
| 1759 GetFileTransfersFunction::GetFileTransfersFunction() {} | |
| 1760 | |
| 1761 GetFileTransfersFunction::~GetFileTransfersFunction() {} | |
| 1762 | |
| 1763 ListValue* GetFileTransfersFunction::GetFileTransfersList() { | |
| 1764 gdata::GDataFileSystem* file_system = | |
| 1765 gdata::GDataFileSystemFactory::GetForProfile(profile_); | |
| 1766 if (!file_system) | |
| 1767 return NULL; | |
| 1768 | |
| 1769 std::vector<gdata::GDataOperationRegistry::ProgressStatus> | |
| 1770 list = file_system->GetProgressStatusList(); | |
| 1771 return file_manager_util::ProgressStatusVectorToListValue( | |
| 1772 profile_, source_url_.GetOrigin(), list); | |
| 1773 } | |
| 1774 | |
| 1775 bool GetFileTransfersFunction::RunImpl() { | |
| 1776 scoped_ptr<ListValue> progress_status_list(GetFileTransfersList()); | |
| 1777 if (!progress_status_list.get()) { | |
| 1778 SendResponse(false); | |
| 1779 return false; | |
| 1780 } | |
| 1781 | |
| 1782 result_.reset(progress_status_list.release()); | |
| 1783 SendResponse(true); | |
| 1784 return true; | |
| 1785 } | |
| 1786 | |
| OLD | NEW |