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

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

Issue 250383008: Refactor the interface for the CrxDownloader to take a callback. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 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_CRX_DOWNLOADER_H_ 5 #ifndef CHROME_BROWSER_COMPONENT_UPDATER_CRX_DOWNLOADER_H_
6 #define CHROME_BROWSER_COMPONENT_UPDATER_CRX_DOWNLOADER_H_ 6 #define CHROME_BROWSER_COMPONENT_UPDATER_CRX_DOWNLOADER_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 // more visibility into how the download has been handled, including 71 // more visibility into how the download has been handled, including
72 // specific error codes and download metrics. 72 // specific error codes and download metrics.
73 typedef base::Callback<void (const Result& result)> DownloadCallback; 73 typedef base::Callback<void (const Result& result)> DownloadCallback;
74 74
75 // Factory method to create an instance of this class and build the 75 // Factory method to create an instance of this class and build the
76 // chain of responsibility. |is_background_download| specifies that a 76 // chain of responsibility. |is_background_download| specifies that a
77 // background downloader be used, if the platform supports it. 77 // background downloader be used, if the platform supports it.
78 static CrxDownloader* Create( 78 static CrxDownloader* Create(
79 bool is_background_download, 79 bool is_background_download,
80 net::URLRequestContextGetter* context_getter, 80 net::URLRequestContextGetter* context_getter,
81 scoped_refptr<base::SequencedTaskRunner> task_runner, 81 scoped_refptr<base::SequencedTaskRunner> task_runner);
82 const DownloadCallback& download_callback);
83 virtual ~CrxDownloader(); 82 virtual ~CrxDownloader();
84 83
85 // Starts the download. One instance of the class handles one download only. 84 // Starts the download. One instance of the class handles one download only.
86 // One instance of CrxDownloader can only be started once, otherwise the 85 // One instance of CrxDownloader can only be started once, otherwise the
87 // behavior is undefined. The callback gets invoked if the download can't 86 // behavior is undefined. The callback gets invoked if the download can't
88 // be started. 87 // be started.
89 void StartDownloadFromUrl(const GURL& url); 88 void StartDownloadFromUrl(const GURL& url,
90 void StartDownload(const std::vector<GURL>& urls); 89 const DownloadCallback& download_callback);
90 void StartDownload(const std::vector<GURL>& urls,
91 const DownloadCallback& download_callback);
91 92
92 const std::vector<DownloadMetrics> download_metrics() const; 93 const std::vector<DownloadMetrics> download_metrics() const;
93 94
94 protected: 95 protected:
95 CrxDownloader(scoped_ptr<CrxDownloader> successor, 96 explicit CrxDownloader(scoped_ptr<CrxDownloader> successor);
96 const DownloadCallback& download_callback);
97 97
98 // Handles the fallback in the case of multiple urls and routing of the 98 // Handles the fallback in the case of multiple urls and routing of the
99 // download to the following successor in the chain. Derived classes must call 99 // download to the following successor in the chain. Derived classes must call
100 // this function after each attempt at downloading the urls provided 100 // this function after each attempt at downloading the urls provided
101 // in the StartDownload function. 101 // in the StartDownload function.
102 // In case of errors, |is_handled| indicates that a server side error has 102 // In case of errors, |is_handled| indicates that a server side error has
103 // occured for the current url and the url should not be retried down 103 // occured for the current url and the url should not be retried down
104 // the chain to avoid DDOS of the server. This url will be removed from the 104 // the chain to avoid DDOS of the server. This url will be removed from the
105 // list of url and never tried again. 105 // list of url and never tried again.
106 void OnDownloadComplete(bool is_handled, 106 void OnDownloadComplete(bool is_handled,
(...skipping 14 matching lines...) Expand all
121 121
122 std::vector<DownloadMetrics> download_metrics_; 122 std::vector<DownloadMetrics> download_metrics_;
123 123
124 DISALLOW_COPY_AND_ASSIGN(CrxDownloader); 124 DISALLOW_COPY_AND_ASSIGN(CrxDownloader);
125 }; 125 };
126 126
127 } // namespace component_updater 127 } // namespace component_updater
128 128
129 #endif // CHROME_BROWSER_COMPONENT_UPDATER_CRX_DOWNLOADER_H_ 129 #endif // CHROME_BROWSER_COMPONENT_UPDATER_CRX_DOWNLOADER_H_
130 130
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698