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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/supports_user_data.h" | 9 #include "base/supports_user_data.h" |
10 #include "base/threading/sequenced_worker_pool.h" | 10 #include "base/threading/sequenced_worker_pool.h" |
11 #include "chrome/browser/chromeos/drive/drive.pb.h" | 11 #include "chrome/browser/chromeos/drive/drive.pb.h" |
12 #include "chrome/browser/chromeos/drive/drive_integration_service.h" | 12 #include "chrome/browser/chromeos/drive/drive_integration_service.h" |
13 #include "chrome/browser/chromeos/drive/file_system_interface.h" | 13 #include "chrome/browser/chromeos/drive/file_system_interface.h" |
14 #include "chrome/browser/chromeos/drive/file_system_util.h" | 14 #include "chrome/browser/chromeos/drive/file_system_util.h" |
15 #include "chrome/browser/chromeos/drive/write_on_cache_file.h" | 15 #include "chrome/browser/chromeos/drive/write_on_cache_file.h" |
| 16 #include "chrome/browser/download/download_history.h" |
| 17 #include "chrome/browser/download/download_service.h" |
| 18 #include "chrome/browser/download/download_service_factory.h" |
16 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
17 | 20 |
18 using content::BrowserThread; | 21 using content::BrowserThread; |
19 using content::DownloadManager; | 22 using content::DownloadManager; |
20 using content::DownloadItem; | 23 using content::DownloadItem; |
21 | 24 |
22 namespace drive { | 25 namespace drive { |
23 namespace { | 26 namespace { |
24 | 27 |
25 // Key for base::SupportsUserData::Data. | 28 // Key for base::SupportsUserData::Data. |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 const content::CheckForFileExistenceCallback& callback, | 90 const content::CheckForFileExistenceCallback& callback, |
88 FileError error, | 91 FileError error, |
89 scoped_ptr<ResourceEntry> entry) { | 92 scoped_ptr<ResourceEntry> entry) { |
90 callback.Run(error == FILE_ERROR_OK); | 93 callback.Run(error == FILE_ERROR_OK); |
91 } | 94 } |
92 | 95 |
93 // Returns true if |download| is a Drive download created from data persisted | 96 // Returns true if |download| is a Drive download created from data persisted |
94 // on the download history DB. | 97 // on the download history DB. |
95 bool IsPersistedDriveDownload(const base::FilePath& drive_tmp_download_path, | 98 bool IsPersistedDriveDownload(const base::FilePath& drive_tmp_download_path, |
96 DownloadItem* download) { | 99 DownloadItem* download) { |
97 // Persisted downloads are not in IN_PROGRESS state when created, while newly | 100 if (!drive_tmp_download_path.IsParent(download->GetTargetFilePath())) |
98 // created downloads are. | 101 return false; |
99 return drive_tmp_download_path.IsParent(download->GetTargetFilePath()) && | 102 |
100 download->GetState() != DownloadItem::IN_PROGRESS; | 103 DownloadService* download_service = |
| 104 DownloadServiceFactory::GetForBrowserContext( |
| 105 download->GetBrowserContext()); |
| 106 DownloadHistory* download_history = download_service->GetDownloadHistory(); |
| 107 |
| 108 return download_history && download_history->WasRestoredFromHistory(download); |
101 } | 109 } |
102 | 110 |
103 } // namespace | 111 } // namespace |
104 | 112 |
105 DownloadHandler::DownloadHandler(FileSystemInterface* file_system) | 113 DownloadHandler::DownloadHandler(FileSystemInterface* file_system) |
106 : file_system_(file_system), | 114 : file_system_(file_system), |
107 weak_ptr_factory_(this) { | 115 weak_ptr_factory_(this) { |
108 } | 116 } |
109 | 117 |
110 DownloadHandler::~DownloadHandler() { | 118 DownloadHandler::~DownloadHandler() { |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 if (!download) | 316 if (!download) |
309 return; | 317 return; |
310 DriveUserData* data = GetDriveUserData(download); | 318 DriveUserData* data = GetDriveUserData(download); |
311 if (!data) | 319 if (!data) |
312 return; | 320 return; |
313 data->set_cache_file_path(*cache_file_path); | 321 data->set_cache_file_path(*cache_file_path); |
314 } | 322 } |
315 | 323 |
316 | 324 |
317 } // namespace drive | 325 } // namespace drive |
OLD | NEW |