Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / component_updater / background_downloader_win.h
blobd1a08f8469b001b2d039a747e24662e98f5e9fb9
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.
5 #ifndef CHROME_BROWSER_COMPONENT_UPDATER_BACKGROUND_DOWNLOADER_WIN_H_
6 #define CHROME_BROWSER_COMPONENT_UPDATER_BACKGROUND_DOWNLOADER_WIN_H_
8 #include "chrome/browser/component_updater/crx_downloader.h"
10 #include <windows.h>
11 #include <bits.h>
13 #include "base/strings/string16.h"
14 #include "base/time/time.h"
15 #include "base/timer/timer.h"
16 #include "base/win/scoped_comptr.h"
18 namespace component_updater {
20 // Implements a downloader in terms of the BITS service. The public interface
21 // of this class and the CrxDownloader overrides are expected to be called
22 // from the UI thread. The rest of the class code runs on the FILE thread in
23 // a single threaded apartment.
24 class BackgroundDownloader : public CrxDownloader {
25 protected:
26 friend class CrxDownloader;
27 BackgroundDownloader(scoped_ptr<CrxDownloader> successor,
28 net::URLRequestContextGetter* context_getter,
29 scoped_refptr<base::SequencedTaskRunner> task_runner,
30 const DownloadCallback& download_callback);
31 virtual ~BackgroundDownloader();
33 private:
34 // Overrides for CrxDownloader.
35 virtual void DoStartDownload(const GURL& url) OVERRIDE;
37 // Called asynchronously on the FILE thread at different stages during
38 // the download. |OnDownloading| can be called multiple times.
39 // |EndDownload| switches the execution flow from the FILE to the UI thread.
40 // Accessing any data members of this object on the FILE thread after
41 // calling |EndDownload| is unsafe.
42 void BeginDownload(const GURL& url);
43 void OnDownloading();
44 void EndDownload(HRESULT hr);
46 // Handles the job state transitions to a final state.
47 void OnStateTransferred();
48 void OnStateError();
49 void OnStateCancelled();
50 void OnStateAcknowledged();
52 // Handles the transition to a transient state where the job is in the
53 // queue but not actively transferring data.
54 void OnStateQueued();
56 // Handles the job state transition to a transient, non-final error state.
57 void OnStateTransientError();
59 // Handles the job state corresponding to transferring data.
60 void OnStateTransferring();
62 HRESULT QueueBitsJob(const GURL& url);
63 HRESULT CreateOrOpenJob(const GURL& url);
64 HRESULT InitializeNewJob(const GURL& url);
66 // Returns true if at the time of the call, it appears that the job
67 // has not been making progress toward completion.
68 bool IsStuck();
70 net::URLRequestContextGetter* context_getter_;
71 scoped_refptr<base::SequencedTaskRunner> task_runner_;
73 scoped_ptr<base::RepeatingTimer<BackgroundDownloader> > timer_;
75 base::win::ScopedComPtr<IBackgroundCopyManager> bits_manager_;
76 base::win::ScopedComPtr<IBackgroundCopyJob> job_;
78 // Contains the time when the download of the current url has started.
79 base::Time download_start_time_;
81 // Contains the time when the BITS job is last seen making progress.
82 base::Time job_stuck_begin_time_;
84 bool is_completed_;
86 DISALLOW_COPY_AND_ASSIGN(BackgroundDownloader);
89 } // namespace component_updater
91 #endif // CHROME_BROWSER_COMPONENT_UPDATER_BACKGROUND_DOWNLOADER_WIN_H_