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/drive/file_system/download_operation.h" | 5 #include "chrome/browser/chromeos/drive/file_system/download_operation.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/task_runner_util.h" | 10 #include "base/task_runner_util.h" |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 | 231 |
232 private: | 232 private: |
233 const GetFileContentInitializedCallback initialized_callback_; | 233 const GetFileContentInitializedCallback initialized_callback_; |
234 const google_apis::GetContentCallback get_content_callback_; | 234 const google_apis::GetContentCallback get_content_callback_; |
235 const GetFileCallback completion_callback_; | 235 const GetFileCallback completion_callback_; |
236 | 236 |
237 // This class is copiable. | 237 // This class is copiable. |
238 }; | 238 }; |
239 | 239 |
240 struct DownloadOperation::DownloadParams { | 240 struct DownloadOperation::DownloadParams { |
241 DownloadParams(const DriveClientContext& context, | 241 DownloadParams(const ClientContext& context, |
242 const GURL& download_url) | 242 const GURL& download_url) |
243 : context(context), | 243 : context(context), |
244 download_url(download_url), | 244 download_url(download_url), |
245 entry(new ResourceEntry) { | 245 entry(new ResourceEntry) { |
246 } | 246 } |
247 | 247 |
248 DriveClientContext context; | 248 ClientContext context; |
249 GURL download_url; | 249 GURL download_url; |
250 scoped_ptr<ResourceEntry> entry; | 250 scoped_ptr<ResourceEntry> entry; |
251 base::FilePath drive_file_path; | 251 base::FilePath drive_file_path; |
252 base::FilePath temp_download_file_path; | 252 base::FilePath temp_download_file_path; |
253 }; | 253 }; |
254 | 254 |
255 DownloadOperation::DownloadOperation( | 255 DownloadOperation::DownloadOperation( |
256 base::SequencedTaskRunner* blocking_task_runner, | 256 base::SequencedTaskRunner* blocking_task_runner, |
257 OperationObserver* observer, | 257 OperationObserver* observer, |
258 JobScheduler* scheduler, | 258 JobScheduler* scheduler, |
259 internal::ResourceMetadata* metadata, | 259 internal::ResourceMetadata* metadata, |
260 internal::FileCache* cache) | 260 internal::FileCache* cache) |
261 : blocking_task_runner_(blocking_task_runner), | 261 : blocking_task_runner_(blocking_task_runner), |
262 observer_(observer), | 262 observer_(observer), |
263 scheduler_(scheduler), | 263 scheduler_(scheduler), |
264 metadata_(metadata), | 264 metadata_(metadata), |
265 cache_(cache), | 265 cache_(cache), |
266 weak_ptr_factory_(this) { | 266 weak_ptr_factory_(this) { |
267 } | 267 } |
268 | 268 |
269 DownloadOperation::~DownloadOperation() { | 269 DownloadOperation::~DownloadOperation() { |
270 } | 270 } |
271 | 271 |
272 void DownloadOperation::EnsureFileDownloaded( | 272 void DownloadOperation::EnsureFileDownloaded( |
273 const base::FilePath& file_path, | 273 const base::FilePath& file_path, |
274 DriveClientContext context, | 274 const ClientContext& context, |
275 const GetFileContentInitializedCallback& initialized_callback, | 275 const GetFileContentInitializedCallback& initialized_callback, |
276 const google_apis::GetContentCallback& get_content_callback, | 276 const google_apis::GetContentCallback& get_content_callback, |
277 const GetFileCallback& completion_callback) { | 277 const GetFileCallback& completion_callback) { |
278 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 278 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
279 DCHECK(!completion_callback.is_null()); | 279 DCHECK(!completion_callback.is_null()); |
280 | 280 |
281 DownloadCallback callback( | 281 DownloadCallback callback( |
282 initialized_callback, get_content_callback, completion_callback); | 282 initialized_callback, get_content_callback, completion_callback); |
283 | 283 |
284 ResourceEntry* entry = new ResourceEntry; | 284 ResourceEntry* entry = new ResourceEntry; |
(...skipping 11 matching lines...) Expand all Loading... |
296 weak_ptr_factory_.GetWeakPtr(), | 296 weak_ptr_factory_.GetWeakPtr(), |
297 file_path, | 297 file_path, |
298 context, | 298 context, |
299 callback, | 299 callback, |
300 base::Passed(make_scoped_ptr(entry)), | 300 base::Passed(make_scoped_ptr(entry)), |
301 base::Owned(cache_file_path))); | 301 base::Owned(cache_file_path))); |
302 } | 302 } |
303 | 303 |
304 void DownloadOperation::EnsureFileDownloadedAfterCheckPreCondition( | 304 void DownloadOperation::EnsureFileDownloadedAfterCheckPreCondition( |
305 const base::FilePath& file_path, | 305 const base::FilePath& file_path, |
306 DriveClientContext context, | 306 const ClientContext& context, |
307 const DownloadCallback& callback, | 307 const DownloadCallback& callback, |
308 scoped_ptr<ResourceEntry> entry, | 308 scoped_ptr<ResourceEntry> entry, |
309 base::FilePath* cache_file_path, | 309 base::FilePath* cache_file_path, |
310 FileError error) { | 310 FileError error) { |
311 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 311 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
312 DCHECK(entry); | 312 DCHECK(entry); |
313 DCHECK(cache_file_path); | 313 DCHECK(cache_file_path); |
314 | 314 |
315 if (error != FILE_ERROR_OK) { | 315 if (error != FILE_ERROR_OK) { |
316 // During precondition check, an error is found. | 316 // During precondition check, an error is found. |
(...skipping 21 matching lines...) Expand all Loading... |
338 scheduler_->GetResourceEntry( | 338 scheduler_->GetResourceEntry( |
339 entry->resource_id(), | 339 entry->resource_id(), |
340 context, | 340 context, |
341 base::Bind(&DownloadOperation::EnsureFileDownloadedAfterGetResourceEntry, | 341 base::Bind(&DownloadOperation::EnsureFileDownloadedAfterGetResourceEntry, |
342 weak_ptr_factory_.GetWeakPtr(), | 342 weak_ptr_factory_.GetWeakPtr(), |
343 context, | 343 context, |
344 callback)); | 344 callback)); |
345 } | 345 } |
346 | 346 |
347 void DownloadOperation::EnsureFileDownloadedAfterGetResourceEntry( | 347 void DownloadOperation::EnsureFileDownloadedAfterGetResourceEntry( |
348 DriveClientContext context, | 348 const ClientContext& context, |
349 const DownloadCallback& callback, | 349 const DownloadCallback& callback, |
350 google_apis::GDataErrorCode gdata_error, | 350 google_apis::GDataErrorCode gdata_error, |
351 scoped_ptr<google_apis::ResourceEntry> resource_entry) { | 351 scoped_ptr<google_apis::ResourceEntry> resource_entry) { |
352 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 352 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
353 | 353 |
354 FileError error = util::GDataToFileError(gdata_error); | 354 FileError error = util::GDataToFileError(gdata_error); |
355 if (error != FILE_ERROR_OK) { | 355 if (error != FILE_ERROR_OK) { |
356 callback.OnError(error); | 356 callback.OnError(error); |
357 return; | 357 return; |
358 } | 358 } |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
468 observer_->OnDirectoryChangedByOperation(file_path.DirName()); | 468 observer_->OnDirectoryChangedByOperation(file_path.DirName()); |
469 callback.OnComplete(*cache_file_path, entry.Pass()); | 469 callback.OnComplete(*cache_file_path, entry.Pass()); |
470 } | 470 } |
471 | 471 |
472 void DownloadOperation::CancelJob(JobID job_id) { | 472 void DownloadOperation::CancelJob(JobID job_id) { |
473 scheduler_->CancelJob(job_id); | 473 scheduler_->CancelJob(job_id); |
474 } | 474 } |
475 | 475 |
476 } // namespace file_system | 476 } // namespace file_system |
477 } // namespace drive | 477 } // namespace drive |
OLD | NEW |