OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_COMPONENT_UPDATER_BACKGROUND_DOWNLOADER_WIN_H_ |
| 6 #define CHROME_BROWSER_COMPONENT_UPDATER_BACKGROUND_DOWNLOADER_WIN_H_ |
| 7 |
| 8 #include "chrome/browser/component_updater/crx_downloader.h" |
| 9 |
| 10 #include <windows.h> |
| 11 #include <bits.h> |
| 12 |
| 13 #include "base/strings/string16.h" |
| 14 #include "base/timer/timer.h" |
| 15 #include "base/win/scoped_comptr.h" |
| 16 |
| 17 namespace component_updater { |
| 18 |
| 19 // Implements a downloader in terms of the BITS service. The public interface |
| 20 // of this class and the CrxDownloader overrides are expected to be called |
| 21 // from the UI thread. The rest of the class code runs on the FILE thread in |
| 22 // a single threaded apartment. |
| 23 class BackgroundDownloader : public CrxDownloader { |
| 24 protected: |
| 25 friend class CrxDownloader; |
| 26 BackgroundDownloader(scoped_ptr<CrxDownloader> successor, |
| 27 net::URLRequestContextGetter* context_getter, |
| 28 scoped_refptr<base::SequencedTaskRunner> task_runner, |
| 29 const DownloadCallback& download_callback); |
| 30 virtual ~BackgroundDownloader(); |
| 31 |
| 32 private: |
| 33 // Overrides for CrxDownloader. |
| 34 virtual void DoStartDownload(const GURL& url) OVERRIDE; |
| 35 |
| 36 // Called asynchronously on the FILE thread at different stages during |
| 37 // the download. |OnDownloading| can be called multiple times. |
| 38 void BeginDownload(const GURL& url); |
| 39 void OnDownloading(); |
| 40 void EndDownload(HRESULT hr); |
| 41 |
| 42 // Handles the job state transitions to a final state. |
| 43 void OnStateTransferred(); |
| 44 void OnStateError(); |
| 45 void OnStateCancelled(); |
| 46 void OnStateAcknowledged(); |
| 47 |
| 48 HRESULT QueueBitsJob(const GURL& url); |
| 49 HRESULT CreateOrOpenJob(const GURL& url); |
| 50 HRESULT InitializeNewJob(const GURL& url); |
| 51 |
| 52 static HRESULT CleanupStaleJobs( |
| 53 base::win::ScopedComPtr<IBackgroundCopyManager> bits_manager); |
| 54 |
| 55 net::URLRequestContextGetter* context_getter_; |
| 56 scoped_refptr<base::SequencedTaskRunner> task_runner_; |
| 57 |
| 58 scoped_ptr<base::RepeatingTimer<BackgroundDownloader> > timer_; |
| 59 |
| 60 base::win::ScopedComPtr<IBackgroundCopyManager> bits_manager_; |
| 61 base::win::ScopedComPtr<IBackgroundCopyJob> job_; |
| 62 |
| 63 bool is_completed_; |
| 64 |
| 65 DISALLOW_COPY_AND_ASSIGN(BackgroundDownloader); |
| 66 }; |
| 67 |
| 68 } // namespace component_updater |
| 69 |
| 70 #endif // CHROME_BROWSER_COMPONENT_UPDATER_BACKGROUND_DOWNLOADER_WIN_H_ |
| 71 |
OLD | NEW |