| 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/drive/download_handler.h" | 5 #include "chrome/browser/chromeos/drive/download_handler.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <utility> |
| 10 |
| 9 #include "base/bind.h" | 11 #include "base/bind.h" |
| 10 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
| 11 #include "base/macros.h" | 13 #include "base/macros.h" |
| 12 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
| 13 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 14 #include "base/supports_user_data.h" | 16 #include "base/supports_user_data.h" |
| 15 #include "base/task_scheduler/post_task.h" | 17 #include "base/task_scheduler/post_task.h" |
| 16 #include "base/threading/sequenced_worker_pool.h" | 18 #include "base/threading/sequenced_worker_pool.h" |
| 17 #include "base/threading/thread_task_runner_handle.h" | 19 #include "base/threading/thread_task_runner_handle.h" |
| 18 #include "chrome/browser/chromeos/drive/drive_integration_service.h" | 20 #include "chrome/browser/chromeos/drive/drive_integration_service.h" |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 FileError error, | 99 FileError error, |
| 98 const base::FilePath& dest_path) { | 100 const base::FilePath& dest_path) { |
| 99 if (error != FILE_ERROR_OK || | 101 if (error != FILE_ERROR_OK || |
| 100 !base::Move(downloaded_file, dest_path)) | 102 !base::Move(downloaded_file, dest_path)) |
| 101 return; | 103 return; |
| 102 *cache_file_path = dest_path; | 104 *cache_file_path = dest_path; |
| 103 } | 105 } |
| 104 | 106 |
| 105 // Used to implement CheckForFileExistence(). | 107 // Used to implement CheckForFileExistence(). |
| 106 void ContinueCheckingForFileExistence( | 108 void ContinueCheckingForFileExistence( |
| 107 const content::CheckForFileExistenceCallback& callback, | 109 content::CheckForFileExistenceCallback callback, |
| 108 FileError error, | 110 FileError error, |
| 109 std::unique_ptr<ResourceEntry> entry) { | 111 std::unique_ptr<ResourceEntry> entry) { |
| 110 callback.Run(error == FILE_ERROR_OK); | 112 std::move(callback).Run(error == FILE_ERROR_OK); |
| 111 } | 113 } |
| 112 | 114 |
| 113 // Returns true if |download| is a Drive download created from data persisted | 115 // Returns true if |download| is a Drive download created from data persisted |
| 114 // on the download history DB. | 116 // on the download history DB. |
| 115 bool IsPersistedDriveDownload(const base::FilePath& drive_tmp_download_path, | 117 bool IsPersistedDriveDownload(const base::FilePath& drive_tmp_download_path, |
| 116 DownloadItem* download) { | 118 DownloadItem* download) { |
| 117 if (!drive_tmp_download_path.IsParent(download->GetTargetFilePath())) | 119 if (!drive_tmp_download_path.IsParent(download->GetTargetFilePath())) |
| 118 return false; | 120 return false; |
| 119 | 121 |
| 120 DownloadCoreService* download_core_service = | 122 DownloadCoreService* download_core_service = |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 } | 242 } |
| 241 | 243 |
| 242 bool DownloadHandler::IsDriveDownload(const DownloadItem* download) { | 244 bool DownloadHandler::IsDriveDownload(const DownloadItem* download) { |
| 243 // We use the existence of the DriveUserData object in download as a | 245 // We use the existence of the DriveUserData object in download as a |
| 244 // signal that this is a download to Drive. | 246 // signal that this is a download to Drive. |
| 245 return GetDriveUserData(download) != NULL; | 247 return GetDriveUserData(download) != NULL; |
| 246 } | 248 } |
| 247 | 249 |
| 248 void DownloadHandler::CheckForFileExistence( | 250 void DownloadHandler::CheckForFileExistence( |
| 249 const DownloadItem* download, | 251 const DownloadItem* download, |
| 250 const content::CheckForFileExistenceCallback& callback) { | 252 content::CheckForFileExistenceCallback callback) { |
| 251 file_system_->GetResourceEntry( | 253 file_system_->GetResourceEntry( |
| 252 util::ExtractDrivePath(GetTargetPath(download)), | 254 util::ExtractDrivePath(GetTargetPath(download)), |
| 253 base::Bind(&ContinueCheckingForFileExistence, | 255 base::Bind(&ContinueCheckingForFileExistence, |
| 254 callback)); | 256 base::Passed(std::move(callback)))); |
| 255 } | 257 } |
| 256 | 258 |
| 257 void DownloadHandler::SetFreeDiskSpaceDelayForTesting( | 259 void DownloadHandler::SetFreeDiskSpaceDelayForTesting( |
| 258 const base::TimeDelta& delay) { | 260 const base::TimeDelta& delay) { |
| 259 free_disk_space_delay_ = delay; | 261 free_disk_space_delay_ = delay; |
| 260 } | 262 } |
| 261 | 263 |
| 262 int64_t DownloadHandler::CalculateRequestSpace( | 264 int64_t DownloadHandler::CalculateRequestSpace( |
| 263 const DownloadManager::DownloadVector& downloads) { | 265 const DownloadManager::DownloadVector& downloads) { |
| 264 int64_t request_space = 0; | 266 int64_t request_space = 0; |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 426 | 428 |
| 427 DownloadManager* DownloadHandler::GetDownloadManager(void* manager_id) { | 429 DownloadManager* DownloadHandler::GetDownloadManager(void* manager_id) { |
| 428 if (manager_id == notifier_->GetManager()) | 430 if (manager_id == notifier_->GetManager()) |
| 429 return notifier_->GetManager(); | 431 return notifier_->GetManager(); |
| 430 if (notifier_incognito_ && manager_id == notifier_incognito_->GetManager()) | 432 if (notifier_incognito_ && manager_id == notifier_incognito_->GetManager()) |
| 431 return notifier_incognito_->GetManager(); | 433 return notifier_incognito_->GetManager(); |
| 432 return NULL; | 434 return NULL; |
| 433 } | 435 } |
| 434 | 436 |
| 435 } // namespace drive | 437 } // namespace drive |
| OLD | NEW |