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/component_updater/background_downloader_win.h" | 5 #include "chrome/browser/component_updater/background_downloader_win.h" |
6 | 6 |
7 #include <atlbase.h> | 7 #include <atlbase.h> |
8 #include <atlcom.h> | 8 #include <atlcom.h> |
9 | 9 |
10 #include <functional> | 10 #include <functional> |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 url)); | 382 url)); |
383 } | 383 } |
384 | 384 |
385 // Called once when this class is asked to do a download. Creates or opens | 385 // Called once when this class is asked to do a download. Creates or opens |
386 // an existing bits job, hooks up the notifications, and starts the timer. | 386 // an existing bits job, hooks up the notifications, and starts the timer. |
387 void BackgroundDownloader::BeginDownload(const GURL& url) { | 387 void BackgroundDownloader::BeginDownload(const GURL& url) { |
388 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 388 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
389 | 389 |
390 DCHECK(!timer_); | 390 DCHECK(!timer_); |
391 | 391 |
| 392 is_completed_ = false; |
| 393 download_start_time_ = base::Time::Now(); |
| 394 job_stuck_begin_time_ = download_start_time_; |
| 395 |
392 HRESULT hr = QueueBitsJob(url); | 396 HRESULT hr = QueueBitsJob(url); |
393 if (FAILED(hr)) { | 397 if (FAILED(hr)) { |
394 EndDownload(hr); | 398 EndDownload(hr); |
395 return; | 399 return; |
396 } | 400 } |
397 | 401 |
398 // A repeating timer retains the user task. This timer can be stopped and | 402 // A repeating timer retains the user task. This timer can be stopped and |
399 // reset multiple times. | 403 // reset multiple times. |
400 timer_.reset(new base::RepeatingTimer<BackgroundDownloader>); | 404 timer_.reset(new base::RepeatingTimer<BackgroundDownloader>); |
401 timer_->Start(FROM_HERE, | 405 timer_->Start(FROM_HERE, |
402 base::TimeDelta::FromSeconds(kJobPollingIntervalSec), | 406 base::TimeDelta::FromSeconds(kJobPollingIntervalSec), |
403 this, | 407 this, |
404 &BackgroundDownloader::OnDownloading); | 408 &BackgroundDownloader::OnDownloading); |
405 | |
406 download_start_time_ = base::Time::Now(); | |
407 job_stuck_begin_time_ = download_start_time_; | |
408 } | 409 } |
409 | 410 |
410 // Called any time the timer fires. | 411 // Called any time the timer fires. |
411 void BackgroundDownloader::OnDownloading() { | 412 void BackgroundDownloader::OnDownloading() { |
412 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 413 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
413 | 414 |
414 DCHECK(job_); | 415 DCHECK(job_); |
415 | 416 |
416 DCHECK(!is_completed_); | 417 DCHECK(!is_completed_); |
417 if (is_completed_) | 418 if (is_completed_) |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
693 } | 694 } |
694 | 695 |
695 bool BackgroundDownloader::IsStuck() { | 696 bool BackgroundDownloader::IsStuck() { |
696 const base::TimeDelta job_stuck_timeout( | 697 const base::TimeDelta job_stuck_timeout( |
697 base::TimeDelta::FromMinutes(kJobStuckTimeoutMin)); | 698 base::TimeDelta::FromMinutes(kJobStuckTimeoutMin)); |
698 return job_stuck_begin_time_ + job_stuck_timeout < base::Time::Now(); | 699 return job_stuck_begin_time_ + job_stuck_timeout < base::Time::Now(); |
699 } | 700 } |
700 | 701 |
701 } // namespace component_updater | 702 } // namespace component_updater |
702 | 703 |
OLD | NEW |