Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(509)

Side by Side Diff: chrome/browser/component_updater/background_downloader_win.h

Issue 385013002: Componentize component_updater: Replace content::BrowserThread usage with task runners (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #ifndef CHROME_BROWSER_COMPONENT_UPDATER_BACKGROUND_DOWNLOADER_WIN_H_ 5 #ifndef CHROME_BROWSER_COMPONENT_UPDATER_BACKGROUND_DOWNLOADER_WIN_H_
6 #define CHROME_BROWSER_COMPONENT_UPDATER_BACKGROUND_DOWNLOADER_WIN_H_ 6 #define CHROME_BROWSER_COMPONENT_UPDATER_BACKGROUND_DOWNLOADER_WIN_H_
7 7
8 #include <windows.h> 8 #include <windows.h>
9 #include <bits.h> 9 #include <bits.h>
10 10
11 #include "base/memory/ref_counted.h"
11 #include "base/strings/string16.h" 12 #include "base/strings/string16.h"
13 #include "base/threading/thread_checker.h"
12 #include "base/time/time.h" 14 #include "base/time/time.h"
13 #include "base/timer/timer.h" 15 #include "base/timer/timer.h"
14 #include "base/win/scoped_comptr.h" 16 #include "base/win/scoped_comptr.h"
15 #include "chrome/browser/component_updater/crx_downloader.h" 17 #include "chrome/browser/component_updater/crx_downloader.h"
16 18
17 namespace base { 19 namespace base {
18 class FilePath; 20 class FilePath;
21 class MessageLoopProxy;
22 class SingleThreadTaskRunner;
19 } 23 }
20 24
21 namespace component_updater { 25 namespace component_updater {
22 26
23 // Implements a downloader in terms of the BITS service. The public interface 27 // Implements a downloader in terms of the BITS service. The public interface
24 // of this class and the CrxDownloader overrides are expected to be called 28 // of this class and the CrxDownloader overrides are expected to be called
25 // from the UI thread. The rest of the class code runs on the FILE thread in 29 // from the main thread. The rest of the class code runs on a single thread
26 // a single threaded apartment. Instances of this class are created and 30 // task runner. This task runner must be initialized to work with COM objects.
27 // destroyed in the UI thread. See the implementation of the class destructor 31 // Instances of this class are created and destroyed in the main thread.
28 // for details regarding the clean up of resources acquired in this class. 32 // See the implementation of the class destructor for details regarding the
33 // clean up of resources acquired in this class.
29 class BackgroundDownloader : public CrxDownloader { 34 class BackgroundDownloader : public CrxDownloader {
30 protected: 35 protected:
31 friend class CrxDownloader; 36 friend class CrxDownloader;
32 BackgroundDownloader(scoped_ptr<CrxDownloader> successor, 37 BackgroundDownloader(
33 net::URLRequestContextGetter* context_getter, 38 scoped_ptr<CrxDownloader> successor,
34 scoped_refptr<base::SequencedTaskRunner> task_runner); 39 net::URLRequestContextGetter* context_getter,
40 scoped_refptr<base::SingleThreadTaskRunner> bits_task_runner);
35 virtual ~BackgroundDownloader(); 41 virtual ~BackgroundDownloader();
36 42
37 private: 43 private:
38 // Overrides for CrxDownloader. 44 // Overrides for CrxDownloader.
39 virtual void DoStartDownload(const GURL& url) OVERRIDE; 45 virtual void DoStartDownload(const GURL& url) OVERRIDE;
40 46
41 // Called asynchronously on the FILE thread at different stages during 47 // Called asynchronously on the |task_runner_| at different stages during
Sorin Jianu 2014/07/21 21:42:13 This should be |bits_task_runner_|, shouldn't it?
tommycli 2014/07/21 22:00:07 Kept it as task_runner_.
42 // the download. |OnDownloading| can be called multiple times. 48 // the download. |OnDownloading| can be called multiple times.
43 // |EndDownload| switches the execution flow from the FILE to the UI thread. 49 // |EndDownload| switches the execution flow from the |task_runner_| to the
44 // Accessing any data members of this object on the FILE thread after 50 // main thread. Accessing any data members of this object from the
45 // calling |EndDownload| is unsafe. 51 // |task_runner_|after calling |EndDownload| is unsafe.
46 void BeginDownload(const GURL& url); 52 void BeginDownload(const GURL& url);
47 void OnDownloading(); 53 void OnDownloading();
48 void EndDownload(HRESULT hr); 54 void EndDownload(HRESULT hr);
49 55
50 // Handles the job state transitions to a final state. 56 // Handles the job state transitions to a final state.
51 void OnStateTransferred(); 57 void OnStateTransferred();
52 void OnStateError(); 58 void OnStateError();
53 void OnStateCancelled(); 59 void OnStateCancelled();
54 void OnStateAcknowledged(); 60 void OnStateAcknowledged();
55 61
(...skipping 12 matching lines...) Expand all
68 HRESULT InitializeNewJob(const GURL& url); 74 HRESULT InitializeNewJob(const GURL& url);
69 75
70 // Returns true if at the time of the call, it appears that the job 76 // Returns true if at the time of the call, it appears that the job
71 // has not been making progress toward completion. 77 // has not been making progress toward completion.
72 bool IsStuck(); 78 bool IsStuck();
73 79
74 // Makes the downloaded file available to the caller by renaming the 80 // Makes the downloaded file available to the caller by renaming the
75 // temporary file to its destination and removing it from the BITS queue. 81 // temporary file to its destination and removing it from the BITS queue.
76 HRESULT CompleteJob(); 82 HRESULT CompleteJob();
77 83
84 // Ensures that we are running on the same thread we created the object on.
85 base::ThreadChecker thread_checker_;
86
87 // Used to post responses back to the main thread. Initialized on the main
88 // loop but accessed from the task runner.
89 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_;
90
78 net::URLRequestContextGetter* context_getter_; 91 net::URLRequestContextGetter* context_getter_;
79 scoped_refptr<base::SequencedTaskRunner> task_runner_; 92 scoped_refptr<base::SingleThreadTaskRunner> bits_task_runner_;
Sorin Jianu 2014/07/21 21:42:13 We could keep the original |task_runner_| name so
tommycli 2014/07/21 22:00:07 Done.
80 93
81 // The timer and the BITS interface pointers have thread affinity. These 94 // The timer and the BITS interface pointers have thread affinity. These
82 // members are initialized on the FILE thread and they must be destroyed 95 // members are initialized on the task runner and they must be destroyed
83 // on the FILE thread. 96 // on the task runner.
84 scoped_ptr<base::RepeatingTimer<BackgroundDownloader> > timer_; 97 scoped_ptr<base::RepeatingTimer<BackgroundDownloader> > timer_;
85 98
86 base::win::ScopedComPtr<IBackgroundCopyManager> bits_manager_; 99 base::win::ScopedComPtr<IBackgroundCopyManager> bits_manager_;
87 base::win::ScopedComPtr<IBackgroundCopyJob> job_; 100 base::win::ScopedComPtr<IBackgroundCopyJob> job_;
88 101
89 // Contains the time when the download of the current url has started. 102 // Contains the time when the download of the current url has started.
90 base::Time download_start_time_; 103 base::Time download_start_time_;
91 104
92 // Contains the time when the BITS job is last seen making progress. 105 // Contains the time when the BITS job is last seen making progress.
93 base::Time job_stuck_begin_time_; 106 base::Time job_stuck_begin_time_;
94 107
95 // True if EndDownload was called. 108 // True if EndDownload was called.
96 bool is_completed_; 109 bool is_completed_;
97 110
98 // Contains the path of the downloaded file if the download was successful. 111 // Contains the path of the downloaded file if the download was successful.
99 base::FilePath response_; 112 base::FilePath response_;
100 113
101 DISALLOW_COPY_AND_ASSIGN(BackgroundDownloader); 114 DISALLOW_COPY_AND_ASSIGN(BackgroundDownloader);
102 }; 115 };
103 116
104 } // namespace component_updater 117 } // namespace component_updater
105 118
106 #endif // CHROME_BROWSER_COMPONENT_UPDATER_BACKGROUND_DOWNLOADER_WIN_H_ 119 #endif // CHROME_BROWSER_COMPONENT_UPDATER_BACKGROUND_DOWNLOADER_WIN_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698