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_URL_FETCHER_DOWNLOADER_H_
6#define CHROME_BROWSER_COMPONENT_UPDATER_URL_FETCHER_DOWNLOADER_H_
7
8#include "base/basictypes.h"
9#include "base/memory/ref_counted.h"
10#include "base/memory/scoped_ptr.h"
11#include "base/time/time.h"
12#include "chrome/browser/component_updater/crx_downloader.h"
13#include "net/url_request/url_fetcher_delegate.h"
14
15namespace net {
16class URLFetcher;
17class URLRequestContextGetter;
18}
19
20namespace component_updater {
21
22// Implements a CRX downloader in top of the URLFetcher.
23class UrlFetcherDownloader : public CrxDownloader,
24                             public net::URLFetcherDelegate {
25 protected:
26  friend class CrxDownloader;
27  UrlFetcherDownloader(scoped_ptr<CrxDownloader> successor,
28                       net::URLRequestContextGetter* context_getter,
29                       scoped_refptr<base::SequencedTaskRunner> task_runner,
30                       const DownloadCallback& download_callback);
31  virtual ~UrlFetcherDownloader();
32
33 private:
34  // Overrides for CrxDownloader.
35  virtual void DoStartDownload(const GURL& url) OVERRIDE;
36
37  // Overrides for URLFetcherDelegate.
38  virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
39  virtual void OnURLFetchDownloadProgress(const net::URLFetcher* source,
40                                          int64 current,
41                                          int64 total) OVERRIDE;
42  scoped_ptr<net::URLFetcher> url_fetcher_;
43  net::URLRequestContextGetter* context_getter_;
44  scoped_refptr<base::SequencedTaskRunner> task_runner_;
45
46  base::Time download_start_time_;
47
48  int64 downloaded_bytes_;
49  int64 total_bytes_;
50
51  DISALLOW_COPY_AND_ASSIGN(UrlFetcherDownloader);
52};
53
54}  // namespace component_updater
55
56#endif  // CHROME_BROWSER_COMPONENT_UPDATER_URL_FETCHER_DOWNLOADER_H_
57
58