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/gdata/gdata_download_observer.h" | 5 #include "chrome/browser/chromeos/gdata/gdata_download_observer.h" |
6 | 6 |
| 7 #include "base/file_util.h" |
7 #include "chrome/browser/chromeos/gdata/gdata_uploader.h" | 8 #include "chrome/browser/chromeos/gdata/gdata_uploader.h" |
8 #include "chrome/browser/chromeos/gdata/gdata_upload_file_info.h" | 9 #include "chrome/browser/chromeos/gdata/gdata_upload_file_info.h" |
9 #include "chrome/browser/chromeos/gdata/gdata_util.h" | 10 #include "chrome/browser/chromeos/gdata/gdata_util.h" |
10 #include "net/base/net_util.h" | 11 #include "net/base/net_util.h" |
11 | 12 |
12 using content::BrowserThread; | 13 using content::BrowserThread; |
13 using content::DownloadManager; | 14 using content::DownloadManager; |
14 using content::DownloadItem; | 15 using content::DownloadItem; |
15 | 16 |
16 namespace gdata { | 17 namespace gdata { |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 // count of received bytes and the size of the download as given by the | 147 // count of received bytes and the size of the download as given by the |
147 // Content-Length header. | 148 // Content-Length header. |
148 int64 total = (download->AllDataSaved() ? download->GetReceivedBytes() : | 149 int64 total = (download->AllDataSaved() ? download->GetReceivedBytes() : |
149 download->GetTotalBytes()); | 150 download->GetTotalBytes()); |
150 DCHECK(total <= 0 || complete < total); | 151 DCHECK(total <= 0 || complete < total); |
151 if (total > 0) | 152 if (total > 0) |
152 return static_cast<int>((complete * 100.0) / total); | 153 return static_cast<int>((complete * 100.0) / total); |
153 return -1; | 154 return -1; |
154 } | 155 } |
155 | 156 |
| 157 // |gdata_tmp_download_path| is set to a temporary local download path in |
| 158 // ~/GCache/v1/tmp/downloads/ |
| 159 // static |
| 160 void GDataDownloadObserver::GetGDataTempDownloadPath( |
| 161 const FilePath& gdata_tmp_download_dir, |
| 162 FilePath* gdata_tmp_download_path) { |
| 163 bool created = file_util::CreateDirectory(gdata_tmp_download_dir); |
| 164 DCHECK(created) << "Can not create temp download directory at " |
| 165 << gdata_tmp_download_dir.value(); |
| 166 created = file_util::CreateTemporaryFileInDir(gdata_tmp_download_dir, |
| 167 gdata_tmp_download_path); |
| 168 DCHECK(created) << "Temporary download file creation failed"; |
| 169 } |
| 170 |
156 void GDataDownloadObserver::ManagerGoingDown( | 171 void GDataDownloadObserver::ManagerGoingDown( |
157 DownloadManager* download_manager) { | 172 DownloadManager* download_manager) { |
158 download_manager->RemoveObserver(this); | 173 download_manager->RemoveObserver(this); |
159 download_manager_ = NULL; | 174 download_manager_ = NULL; |
160 } | 175 } |
161 | 176 |
162 void GDataDownloadObserver::ModelChanged(DownloadManager* download_manager) { | 177 void GDataDownloadObserver::ModelChanged(DownloadManager* download_manager) { |
163 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 178 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
164 | 179 |
165 DownloadManager::DownloadVector downloads; | 180 DownloadManager::DownloadVector downloads; |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 return; | 324 return; |
310 DVLOG(1) << "Completing upload for download ID " << download_id; | 325 DVLOG(1) << "Completing upload for download ID " << download_id; |
311 DownloadItem* download = iter->second; | 326 DownloadItem* download = iter->second; |
312 UploadingExternalData* upload_data = GetUploadingExternalData(download); | 327 UploadingExternalData* upload_data = GetUploadingExternalData(download); |
313 DCHECK(upload_data); | 328 DCHECK(upload_data); |
314 upload_data->MarkAsComplete(); | 329 upload_data->MarkAsComplete(); |
315 download->MaybeCompleteDownload(); | 330 download->MaybeCompleteDownload(); |
316 } | 331 } |
317 | 332 |
318 } // namespace gdata | 333 } // namespace gdata |
OLD | NEW |