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 "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
13 #include "base/supports_user_data.h" | 13 #include "base/supports_user_data.h" |
14 #include "base/thread_task_runner_handle.h" | 14 #include "base/thread_task_runner_handle.h" |
15 #include "base/threading/sequenced_worker_pool.h" | 15 #include "base/threading/sequenced_worker_pool.h" |
16 #include "chrome/browser/chromeos/drive/drive_integration_service.h" | 16 #include "chrome/browser/chromeos/drive/drive_integration_service.h" |
17 #include "chrome/browser/chromeos/drive/file_system_util.h" | 17 #include "chrome/browser/chromeos/drive/file_system_util.h" |
18 #include "chrome/browser/chromeos/drive/write_on_cache_file.h" | 18 #include "chrome/browser/chromeos/drive/write_on_cache_file.h" |
19 #include "chrome/browser/download/download_history.h" | 19 #include "chrome/browser/download/download_history.h" |
20 #include "chrome/browser/download/download_service.h" | 20 #include "chrome/browser/download/download_service.h" |
21 #include "chrome/browser/download/download_service_factory.h" | 21 #include "chrome/browser/download/download_service_factory.h" |
22 #include "components/drive/drive.pb.h" | 22 #include "components/drive/drive.pb.h" |
23 #include "components/drive/file_system_interface.h" | 23 #include "components/drive/file_system_interface.h" |
24 #include "content/public/browser/browser_thread.h" | 24 #include "content/public/browser/browser_thread.h" |
25 | 25 |
26 using content::BrowserThread; | 26 using content::BrowserThread; |
| 27 using content::DownloadItem; |
27 using content::DownloadManager; | 28 using content::DownloadManager; |
28 using content::DownloadItem; | |
29 | 29 |
30 namespace drive { | 30 namespace drive { |
31 namespace { | 31 namespace { |
32 | 32 |
33 // Key for base::SupportsUserData::Data. | 33 // Key for base::SupportsUserData::Data. |
34 const char kDrivePathKey[] = "DrivePath"; | 34 const char kDrivePathKey[] = "DrivePath"; |
35 | 35 |
36 // Mime types that we better not trust. If the file was downloade with these | 36 // Mime types that we better not trust. If the file was downloade with these |
37 // mime types, while uploading to Drive we ignore it at guess by our own logic. | 37 // mime types, while uploading to Drive we ignore it at guess by our own logic. |
38 const char* kGenericMimeTypes[] = {"text/html", "text/plain", | 38 const char* const kGenericMimeTypes[] = {"text/html", "text/plain", |
39 "application/octet-stream"}; | 39 "application/octet-stream"}; |
40 | 40 |
41 // Longer is better. But at the same time, this value should be short enough as | 41 // Longer is better. But at the same time, this value should be short enough as |
42 // drive::internal::kMinFreeSpaceInBytes is not used up by file download in this | 42 // drive::internal::kMinFreeSpaceInBytes is not used up by file download in this |
43 // interval. | 43 // interval. |
44 const base::TimeDelta kFreeDiskSpaceDelay = base::TimeDelta::FromSeconds(3); | 44 const int kFreeDiskSpaceDelayInSeconds = 3; |
45 | 45 |
46 // User Data stored in DownloadItem for drive path. | 46 // User Data stored in DownloadItem for drive path. |
47 class DriveUserData : public base::SupportsUserData::Data { | 47 class DriveUserData : public base::SupportsUserData::Data { |
48 public: | 48 public: |
49 explicit DriveUserData(const base::FilePath& path) : file_path_(path), | 49 explicit DriveUserData(const base::FilePath& path) : file_path_(path), |
50 is_complete_(false) {} | 50 is_complete_(false) {} |
51 ~DriveUserData() override {} | 51 ~DriveUserData() override {} |
52 | 52 |
53 const base::FilePath& file_path() const { return file_path_; } | 53 const base::FilePath& file_path() const { return file_path_; } |
54 const base::FilePath& cache_file_path() const { return cache_file_path_; } | 54 const base::FilePath& cache_file_path() const { return cache_file_path_; } |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 return mime_type; | 134 return mime_type; |
135 } | 135 } |
136 | 136 |
137 void IgnoreFreeDiskSpaceIfNeededForCallback(bool /*result*/) {} | 137 void IgnoreFreeDiskSpaceIfNeededForCallback(bool /*result*/) {} |
138 | 138 |
139 } // namespace | 139 } // namespace |
140 | 140 |
141 DownloadHandler::DownloadHandler(FileSystemInterface* file_system) | 141 DownloadHandler::DownloadHandler(FileSystemInterface* file_system) |
142 : file_system_(file_system), | 142 : file_system_(file_system), |
143 has_pending_free_disk_space_(false), | 143 has_pending_free_disk_space_(false), |
144 free_disk_space_delay_(kFreeDiskSpaceDelay), | 144 free_disk_space_delay_( |
| 145 base::TimeDelta::FromSeconds(kFreeDiskSpaceDelayInSeconds)), |
145 weak_ptr_factory_(this) {} | 146 weak_ptr_factory_(this) {} |
146 | 147 |
147 DownloadHandler::~DownloadHandler() { | 148 DownloadHandler::~DownloadHandler() { |
148 } | 149 } |
149 | 150 |
150 // static | 151 // static |
151 DownloadHandler* DownloadHandler::GetForProfile(Profile* profile) { | 152 DownloadHandler* DownloadHandler::GetForProfile(Profile* profile) { |
152 DriveIntegrationService* service = | 153 DriveIntegrationService* service = |
153 DriveIntegrationServiceFactory::FindForProfile(profile); | 154 DriveIntegrationServiceFactory::FindForProfile(profile); |
154 if (!service || !service->IsMounted()) | 155 if (!service || !service->IsMounted()) |
155 return NULL; | 156 return NULL; |
156 return service->download_handler(); | 157 return service->download_handler(); |
157 } | 158 } |
158 | 159 |
159 void DownloadHandler::Initialize( | 160 void DownloadHandler::Initialize( |
160 DownloadManager* download_manager, | 161 DownloadManager* download_manager, |
161 const base::FilePath& drive_tmp_download_path) { | 162 const base::FilePath& drive_tmp_download_path) { |
162 DCHECK(!drive_tmp_download_path.empty()); | 163 DCHECK(!drive_tmp_download_path.empty()); |
163 | 164 |
164 drive_tmp_download_path_ = drive_tmp_download_path; | 165 drive_tmp_download_path_ = drive_tmp_download_path; |
165 | 166 |
166 if (download_manager) { | 167 if (download_manager) { |
167 notifier_.reset(new AllDownloadItemNotifier(download_manager, this)); | 168 notifier_.reset(new AllDownloadItemNotifier(download_manager, this)); |
168 // Remove any persisted Drive DownloadItem. crbug.com/171384 | 169 // Remove any persisted Drive DownloadItem. crbug.com/171384 |
169 content::DownloadManager::DownloadVector downloads; | 170 DownloadManager::DownloadVector downloads; |
170 download_manager->GetAllDownloads(&downloads); | 171 download_manager->GetAllDownloads(&downloads); |
171 for (size_t i = 0; i < downloads.size(); ++i) { | 172 for (size_t i = 0; i < downloads.size(); ++i) { |
172 if (IsPersistedDriveDownload(drive_tmp_download_path_, downloads[i])) | 173 if (IsPersistedDriveDownload(drive_tmp_download_path_, downloads[i])) |
173 downloads[i]->Remove(); | 174 downloads[i]->Remove(); |
174 } | 175 } |
175 } | 176 } |
176 } | 177 } |
177 | 178 |
178 void DownloadHandler::ObserveIncognitoDownloadManager( | 179 void DownloadHandler::ObserveIncognitoDownloadManager( |
179 DownloadManager* download_manager) { | 180 DownloadManager* download_manager) { |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 | 423 |
423 DownloadManager* DownloadHandler::GetDownloadManager(void* manager_id) { | 424 DownloadManager* DownloadHandler::GetDownloadManager(void* manager_id) { |
424 if (manager_id == notifier_->GetManager()) | 425 if (manager_id == notifier_->GetManager()) |
425 return notifier_->GetManager(); | 426 return notifier_->GetManager(); |
426 if (notifier_incognito_ && manager_id == notifier_incognito_->GetManager()) | 427 if (notifier_incognito_ && manager_id == notifier_incognito_->GetManager()) |
427 return notifier_incognito_->GetManager(); | 428 return notifier_incognito_->GetManager(); |
428 return NULL; | 429 return NULL; |
429 } | 430 } |
430 | 431 |
431 } // namespace drive | 432 } // namespace drive |
OLD | NEW |