Home | History | Annotate | Download | only in component_updater
      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 
     15 namespace net {
     16 class URLFetcher;
     17 class URLRequestContextGetter;
     18 }
     19 
     20 namespace component_updater {
     21 
     22 // Implements a CRX downloader in top of the URLFetcher.
     23 class 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   virtual ~UrlFetcherDownloader();
     31 
     32  private:
     33   // Overrides for CrxDownloader.
     34   virtual void DoStartDownload(const GURL& url) OVERRIDE;
     35 
     36   // Overrides for URLFetcherDelegate.
     37   virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
     38   virtual void OnURLFetchDownloadProgress(const net::URLFetcher* source,
     39                                           int64 current,
     40                                           int64 total) OVERRIDE;
     41   scoped_ptr<net::URLFetcher> url_fetcher_;
     42   net::URLRequestContextGetter* context_getter_;
     43   scoped_refptr<base::SequencedTaskRunner> task_runner_;
     44 
     45   base::Time download_start_time_;
     46 
     47   int64 downloaded_bytes_;
     48   int64 total_bytes_;
     49 
     50   DISALLOW_COPY_AND_ASSIGN(UrlFetcherDownloader);
     51 };
     52 
     53 }  // namespace component_updater
     54 
     55 #endif  // CHROME_BROWSER_COMPONENT_UPDATER_URL_FETCHER_DOWNLOADER_H_
     56