| OLD | NEW |
| 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" |
| 11 #include "chrome/browser/chromeos/drive/logging.h" | 11 #include "chrome/browser/chromeos/drive/logging.h" |
| 12 #include "chrome/browser/chromeos/extensions/file_manager/file_tasks.h" | 12 #include "chrome/browser/chromeos/extensions/file_manager/file_tasks.h" |
| 13 #include "chrome/browser/chromeos/extensions/file_manager/private_api_util.h" | 13 #include "chrome/browser/chromeos/extensions/file_manager/private_api_util.h" |
| 14 #include "chrome/browser/chromeos/extensions/file_manager/url_util.h" | 14 #include "chrome/browser/chromeos/extensions/file_manager/url_util.h" |
| 15 #include "chrome/browser/chromeos/fileapi/file_system_backend.h" | 15 #include "chrome/browser/chromeos/fileapi/file_system_backend.h" |
| 16 #include "chrome/browser/extensions/api/file_handlers/app_file_handler_util.h" | 16 #include "chrome/browser/extensions/api/file_handlers/app_file_handler_util.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
| 19 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
| 20 #include "content/public/browser/render_view_host.h" | 20 #include "content/public/browser/render_view_host.h" |
| 21 #include "webkit/common/fileapi/file_system_util.h" | 21 #include "webkit/common/fileapi/file_system_util.h" |
| 22 | 22 |
| 23 using content::BrowserThread; | 23 using content::BrowserThread; |
| 24 | 24 |
| 25 namespace file_manager { | 25 namespace extensions { |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 // List of connection types of drive. | 28 // List of connection types of drive. |
| 29 // Keep this in sync with the DriveConnectionType in volume_manager.js. | 29 // Keep this in sync with the DriveConnectionType in volume_manager.js. |
| 30 const char kDriveConnectionTypeOffline[] = "offline"; | 30 const char kDriveConnectionTypeOffline[] = "offline"; |
| 31 const char kDriveConnectionTypeMetered[] = "metered"; | 31 const char kDriveConnectionTypeMetered[] = "metered"; |
| 32 const char kDriveConnectionTypeOnline[] = "online"; | 32 const char kDriveConnectionTypeOnline[] = "online"; |
| 33 | 33 |
| 34 | 34 |
| 35 // List of reasons of kDriveConnectionType*. | 35 // List of reasons of kDriveConnectionType*. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 | 73 |
| 74 bool GetDriveEntryPropertiesFunction::RunImpl() { | 74 bool GetDriveEntryPropertiesFunction::RunImpl() { |
| 75 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 75 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 76 | 76 |
| 77 std::string file_url_str; | 77 std::string file_url_str; |
| 78 if (args_->GetSize() != 1 || !args_->GetString(0, &file_url_str)) | 78 if (args_->GetSize() != 1 || !args_->GetString(0, &file_url_str)) |
| 79 return false; | 79 return false; |
| 80 | 80 |
| 81 GURL file_url = GURL(file_url_str); | 81 GURL file_url = GURL(file_url_str); |
| 82 file_path_ = drive::util::ExtractDrivePath( | 82 file_path_ = drive::util::ExtractDrivePath( |
| 83 util::GetLocalPathFromURL(render_view_host(), profile(), file_url)); | 83 file_manager::util::GetLocalPathFromURL( |
| 84 render_view_host(), profile(), file_url)); |
| 84 | 85 |
| 85 properties_.reset(new base::DictionaryValue); | 86 properties_.reset(new base::DictionaryValue); |
| 86 properties_->SetString("fileUrl", file_url.spec()); | 87 properties_->SetString("fileUrl", file_url.spec()); |
| 87 | 88 |
| 88 // Start getting the file info. | 89 // Start getting the file info. |
| 89 drive::DriveIntegrationService* integration_service = | 90 drive::DriveIntegrationService* integration_service = |
| 90 drive::DriveIntegrationServiceFactory::GetForProfile(profile_); | 91 drive::DriveIntegrationServiceFactory::GetForProfile(profile_); |
| 91 // |integration_service| is NULL if Drive is disabled. | 92 // |integration_service| is NULL if Drive is disabled. |
| 92 if (!integration_service) { | 93 if (!integration_service) { |
| 93 CompleteGetFileProperties(drive::FILE_ERROR_FAILED); | 94 CompleteGetFileProperties(drive::FILE_ERROR_FAILED); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 | 131 |
| 131 const drive::FileSpecificInfo& file_specific_info = | 132 const drive::FileSpecificInfo& file_specific_info = |
| 132 entry->file_specific_info(); | 133 entry->file_specific_info(); |
| 133 | 134 |
| 134 // Get drive WebApps that can accept this file. We just need to extract the | 135 // Get drive WebApps that can accept this file. We just need to extract the |
| 135 // doc icon for the drive app, which is set as default. | 136 // doc icon for the drive app, which is set as default. |
| 136 ScopedVector<drive::DriveAppInfo> drive_apps; | 137 ScopedVector<drive::DriveAppInfo> drive_apps; |
| 137 integration_service->drive_app_registry()->GetAppsForFile( | 138 integration_service->drive_app_registry()->GetAppsForFile( |
| 138 file_path_, file_specific_info.content_mime_type(), &drive_apps); | 139 file_path_, file_specific_info.content_mime_type(), &drive_apps); |
| 139 if (!drive_apps.empty()) { | 140 if (!drive_apps.empty()) { |
| 140 std::string default_task_id = file_tasks::GetDefaultTaskIdFromPrefs( | 141 std::string default_task_id = |
| 141 profile_, | 142 file_manager::file_tasks::GetDefaultTaskIdFromPrefs( |
| 142 file_specific_info.content_mime_type(), | 143 profile_, |
| 143 file_path_.Extension()); | 144 file_specific_info.content_mime_type(), |
| 144 file_tasks::TaskDescriptor default_task; | 145 file_path_.Extension()); |
| 145 file_tasks::ParseTaskID(default_task_id, &default_task); | 146 file_manager::file_tasks::TaskDescriptor default_task; |
| 147 file_manager::file_tasks::ParseTaskID(default_task_id, &default_task); |
| 146 DCHECK(default_task_id.empty() || !default_task.app_id.empty()); | 148 DCHECK(default_task_id.empty() || !default_task.app_id.empty()); |
| 147 for (size_t i = 0; i < drive_apps.size(); ++i) { | 149 for (size_t i = 0; i < drive_apps.size(); ++i) { |
| 148 const drive::DriveAppInfo* app_info = drive_apps[i]; | 150 const drive::DriveAppInfo* app_info = drive_apps[i]; |
| 149 if (default_task.app_id == app_info->app_id) { | 151 if (default_task.app_id == app_info->app_id) { |
| 150 // The drive app is set as default. Files.app should use the doc icon. | 152 // The drive app is set as default. Files.app should use the doc icon. |
| 151 const GURL doc_icon = util::FindPreferredIcon(app_info->document_icons, | 153 const GURL doc_icon = file_manager::util::FindPreferredIcon( |
| 152 util::kPreferredIconSize); | 154 app_info->document_icons, |
| 155 file_manager::util::kPreferredIconSize); |
| 153 properties_->SetString("customIconUrl", doc_icon.spec()); | 156 properties_->SetString("customIconUrl", doc_icon.spec()); |
| 154 } | 157 } |
| 155 } | 158 } |
| 156 } | 159 } |
| 157 | 160 |
| 158 integration_service->file_system()->GetCacheEntryByPath( | 161 integration_service->file_system()->GetCacheEntryByPath( |
| 159 file_path_, | 162 file_path_, |
| 160 base::Bind(&GetDriveEntryPropertiesFunction::CacheStateReceived, this)); | 163 base::Bind(&GetDriveEntryPropertiesFunction::CacheStateReceived, this)); |
| 161 } | 164 } |
| 162 | 165 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 return false; | 199 return false; |
| 197 | 200 |
| 198 drive::DriveIntegrationService* integration_service = | 201 drive::DriveIntegrationService* integration_service = |
| 199 drive::DriveIntegrationServiceFactory::GetForProfile(profile_); | 202 drive::DriveIntegrationServiceFactory::GetForProfile(profile_); |
| 200 drive::FileSystemInterface* file_system = | 203 drive::FileSystemInterface* file_system = |
| 201 integration_service ? integration_service->file_system() : NULL; | 204 integration_service ? integration_service->file_system() : NULL; |
| 202 if (!file_system) // |file_system| is NULL if Drive is disabled. | 205 if (!file_system) // |file_system| is NULL if Drive is disabled. |
| 203 return false; | 206 return false; |
| 204 | 207 |
| 205 base::FilePath drive_path = | 208 base::FilePath drive_path = |
| 206 drive::util::ExtractDrivePath( | 209 drive::util::ExtractDrivePath(file_manager::util::GetLocalPathFromURL( |
| 207 util::GetLocalPathFromURL(render_view_host(), profile(), GURL(url))); | 210 render_view_host(), profile(), GURL(url))); |
| 208 if (set_pin) { | 211 if (set_pin) { |
| 209 file_system->Pin(drive_path, | 212 file_system->Pin(drive_path, |
| 210 base::Bind(&PinDriveFileFunction::OnPinStateSet, this)); | 213 base::Bind(&PinDriveFileFunction::OnPinStateSet, this)); |
| 211 } else { | 214 } else { |
| 212 file_system->Unpin(drive_path, | 215 file_system->Unpin(drive_path, |
| 213 base::Bind(&PinDriveFileFunction::OnPinStateSet, this)); | 216 base::Bind(&PinDriveFileFunction::OnPinStateSet, this)); |
| 214 } | 217 } |
| 215 return true; | 218 return true; |
| 216 } | 219 } |
| 217 | 220 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 236 bool GetDriveFilesFunction::RunImpl() { | 239 bool GetDriveFilesFunction::RunImpl() { |
| 237 ListValue* file_urls_as_strings = NULL; | 240 ListValue* file_urls_as_strings = NULL; |
| 238 if (!args_->GetList(0, &file_urls_as_strings)) | 241 if (!args_->GetList(0, &file_urls_as_strings)) |
| 239 return false; | 242 return false; |
| 240 | 243 |
| 241 // Convert the list of strings to a list of GURLs. | 244 // Convert the list of strings to a list of GURLs. |
| 242 for (size_t i = 0; i < file_urls_as_strings->GetSize(); ++i) { | 245 for (size_t i = 0; i < file_urls_as_strings->GetSize(); ++i) { |
| 243 std::string file_url_as_string; | 246 std::string file_url_as_string; |
| 244 if (!file_urls_as_strings->GetString(i, &file_url_as_string)) | 247 if (!file_urls_as_strings->GetString(i, &file_url_as_string)) |
| 245 return false; | 248 return false; |
| 246 const base::FilePath path = util::GetLocalPathFromURL( | 249 const base::FilePath path = file_manager::util::GetLocalPathFromURL( |
| 247 render_view_host(), profile(), GURL(file_url_as_string)); | 250 render_view_host(), profile(), GURL(file_url_as_string)); |
| 248 DCHECK(drive::util::IsUnderDriveMountPoint(path)); | 251 DCHECK(drive::util::IsUnderDriveMountPoint(path)); |
| 249 base::FilePath drive_path = drive::util::ExtractDrivePath(path); | 252 base::FilePath drive_path = drive::util::ExtractDrivePath(path); |
| 250 remaining_drive_paths_.push(drive_path); | 253 remaining_drive_paths_.push(drive_path); |
| 251 } | 254 } |
| 252 | 255 |
| 253 local_paths_ = new ListValue; | 256 local_paths_ = new ListValue; |
| 254 GetFileOrSendResponse(); | 257 GetFileOrSendResponse(); |
| 255 return true; | 258 return true; |
| 256 } | 259 } |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 if (drive::IsActiveFileTransferJobInfo(jobs[i])) | 339 if (drive::IsActiveFileTransferJobInfo(jobs[i])) |
| 337 path_to_id_map[jobs[i].file_path].push_back(jobs[i].job_id); | 340 path_to_id_map[jobs[i].file_path].push_back(jobs[i].job_id); |
| 338 } | 341 } |
| 339 | 342 |
| 340 // Cancel by Job ID. | 343 // Cancel by Job ID. |
| 341 scoped_ptr<ListValue> responses(new ListValue()); | 344 scoped_ptr<ListValue> responses(new ListValue()); |
| 342 for (size_t i = 0; i < url_list->GetSize(); ++i) { | 345 for (size_t i = 0; i < url_list->GetSize(); ++i) { |
| 343 std::string url_as_string; | 346 std::string url_as_string; |
| 344 url_list->GetString(i, &url_as_string); | 347 url_list->GetString(i, &url_as_string); |
| 345 | 348 |
| 346 base::FilePath file_path = util::GetLocalPathFromURL( | 349 base::FilePath file_path = file_manager::util::GetLocalPathFromURL( |
| 347 render_view_host(), profile(), GURL(url_as_string)); | 350 render_view_host(), profile(), GURL(url_as_string)); |
| 348 if (file_path.empty()) | 351 if (file_path.empty()) |
| 349 continue; | 352 continue; |
| 350 | 353 |
| 351 DCHECK(drive::util::IsUnderDriveMountPoint(file_path)); | 354 DCHECK(drive::util::IsUnderDriveMountPoint(file_path)); |
| 352 file_path = drive::util::ExtractDrivePath(file_path); | 355 file_path = drive::util::ExtractDrivePath(file_path); |
| 353 scoped_ptr<DictionaryValue> result(new DictionaryValue()); | 356 scoped_ptr<DictionaryValue> result(new DictionaryValue()); |
| 354 | 357 |
| 355 // Cancel all the jobs for the file. | 358 // Cancel all the jobs for the file. |
| 356 PathToIdMap::iterator it = path_to_id_map.find(file_path); | 359 PathToIdMap::iterator it = path_to_id_map.find(file_path); |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 642 } | 645 } |
| 643 | 646 |
| 644 GetShareUrlFunction::~GetShareUrlFunction() { | 647 GetShareUrlFunction::~GetShareUrlFunction() { |
| 645 } | 648 } |
| 646 | 649 |
| 647 bool GetShareUrlFunction::RunImpl() { | 650 bool GetShareUrlFunction::RunImpl() { |
| 648 std::string file_url; | 651 std::string file_url; |
| 649 if (!args_->GetString(0, &file_url)) | 652 if (!args_->GetString(0, &file_url)) |
| 650 return false; | 653 return false; |
| 651 | 654 |
| 652 const base::FilePath path = util::GetLocalPathFromURL( | 655 const base::FilePath path = file_manager::util::GetLocalPathFromURL( |
| 653 render_view_host(), profile(), GURL(file_url)); | 656 render_view_host(), profile(), GURL(file_url)); |
| 654 DCHECK(drive::util::IsUnderDriveMountPoint(path)); | 657 DCHECK(drive::util::IsUnderDriveMountPoint(path)); |
| 655 | 658 |
| 656 base::FilePath drive_path = drive::util::ExtractDrivePath(path); | 659 base::FilePath drive_path = drive::util::ExtractDrivePath(path); |
| 657 | 660 |
| 658 drive::DriveIntegrationService* integration_service = | 661 drive::DriveIntegrationService* integration_service = |
| 659 drive::DriveIntegrationServiceFactory::GetForProfile(profile_); | 662 drive::DriveIntegrationServiceFactory::GetForProfile(profile_); |
| 660 // |integration_service| is NULL if Drive is disabled. | 663 // |integration_service| is NULL if Drive is disabled. |
| 661 if (!integration_service) | 664 if (!integration_service) |
| 662 return false; | 665 return false; |
| 663 | 666 |
| 664 integration_service->file_system()->GetShareUrl( | 667 integration_service->file_system()->GetShareUrl( |
| 665 drive_path, | 668 drive_path, |
| 666 util::GetFileManagerBaseUrl(), // embed origin | 669 file_manager::util::GetFileManagerBaseUrl(), // embed origin |
| 667 base::Bind(&GetShareUrlFunction::OnGetShareUrl, this)); | 670 base::Bind(&GetShareUrlFunction::OnGetShareUrl, this)); |
| 668 return true; | 671 return true; |
| 669 } | 672 } |
| 670 | 673 |
| 671 | 674 |
| 672 void GetShareUrlFunction::OnGetShareUrl(drive::FileError error, | 675 void GetShareUrlFunction::OnGetShareUrl(drive::FileError error, |
| 673 const GURL& share_url) { | 676 const GURL& share_url) { |
| 674 if (error != drive::FILE_ERROR_OK) { | 677 if (error != drive::FILE_ERROR_OK) { |
| 675 error_ = "Share Url for this item is not available."; | 678 error_ = "Share Url for this item is not available."; |
| 676 SendResponse(false); | 679 SendResponse(false); |
| 677 return; | 680 return; |
| 678 } | 681 } |
| 679 | 682 |
| 680 SetResult(new base::StringValue(share_url.spec())); | 683 SetResult(new base::StringValue(share_url.spec())); |
| 681 SendResponse(true); | 684 SendResponse(true); |
| 682 } | 685 } |
| 683 | 686 |
| 684 } // namespace file_manager | 687 } // namespace extensions |
| OLD | NEW |