Home | History | Annotate | Download | only in updater
      1 // Copyright (c) 2012 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_EXTENSIONS_UPDATER_EXTENSION_DOWNLOADER_DELEGATE_H_
      6 #define CHROME_BROWSER_EXTENSIONS_UPDATER_EXTENSION_DOWNLOADER_DELEGATE_H_
      7 
      8 #include <set>
      9 #include <string>
     10 
     11 #include "base/time/time.h"
     12 #include "chrome/browser/extensions/updater/manifest_fetch_data.h"
     13 
     14 class GURL;
     15 
     16 namespace base {
     17 class FilePath;
     18 }
     19 
     20 namespace extensions {
     21 
     22 class ExtensionDownloaderDelegate {
     23  public:
     24   virtual ~ExtensionDownloaderDelegate();
     25 
     26   // Passed as an argument to ExtensionDownloader::OnExtensionDownloadFailed()
     27   // to detail the reason for the failure.
     28   enum Error {
     29     // Background networking is disabled.
     30     DISABLED,
     31 
     32     // Failed to fetch the manifest for this extension.
     33     MANIFEST_FETCH_FAILED,
     34 
     35     // The manifest couldn't be parsed.
     36     MANIFEST_INVALID,
     37 
     38     // The manifest was fetched and parsed, and there are no updates for
     39     // this extension.
     40     NO_UPDATE_AVAILABLE,
     41 
     42     // There was an update for this extension but the download of the crx
     43     // failed.
     44     CRX_FETCH_FAILED,
     45   };
     46 
     47   // Passed as an argument to the completion callbacks to signal whether
     48   // the extension update sent a ping.
     49   struct PingResult {
     50     PingResult();
     51     ~PingResult();
     52 
     53     // Whether a ping was sent.
     54     bool did_ping;
     55 
     56     // The start of day, from the server's perspective. This is only valid
     57     // when |did_ping| is true.
     58     base::Time day_start;
     59   };
     60 
     61   // One of the following 3 methods is always invoked for a given extension
     62   // id, if AddExtension() or AddPendingExtension() returned true when that
     63   // extension was added to the ExtensionDownloader.
     64   // To avoid duplicate work, ExtensionDownloader might merge multiple identical
     65   // requests, so there is not necessarily a separate invocation of one of these
     66   // methods for each call to AddExtension/AddPendingExtension. If it is
     67   // important to be able to match up AddExtension calls with
     68   // OnExtensionDownload callbacks, you need to make sure that for every call to
     69   // AddExtension/AddPendingExtension the combination of extension id and
     70   // request id is unique. The OnExtensionDownload related callbacks will then
     71   // be called with all request ids that resulted in that extension being
     72   // checked.
     73 
     74   // Invoked if the extension couldn't be downloaded. |error| contains the
     75   // failure reason.
     76   virtual void OnExtensionDownloadFailed(const std::string& id,
     77                                          Error error,
     78                                          const PingResult& ping_result,
     79                                          const std::set<int>& request_ids);
     80 
     81   // Invoked if the extension had an update available and its crx was
     82   // successfully downloaded to |path|. |ownership_passed| is true if delegate
     83   // should get ownership of the file.
     84   virtual void OnExtensionDownloadFinished(
     85       const std::string& id,
     86       const base::FilePath& path,
     87       bool file_ownership_passed,
     88       const GURL& download_url,
     89       const std::string& version,
     90       const PingResult& ping_result,
     91       const std::set<int>& request_ids) = 0;
     92 
     93   // The remaining methods are used by the ExtensionDownloader to retrieve
     94   // information about extensions from the delegate.
     95 
     96   // Invoked to fill the PingData for the given extension id. Returns false
     97   // if PingData should not be included for this extension's update check
     98   // (this is the default).
     99   virtual bool GetPingDataForExtension(const std::string& id,
    100                                        ManifestFetchData::PingData* ping);
    101 
    102   // Invoked to get the update url data for this extension's update url, if
    103   // there is any. The default implementation returns an empty string.
    104   virtual std::string GetUpdateUrlData(const std::string& id);
    105 
    106   // Invoked to determine whether extension |id| is currently
    107   // pending installation.
    108   virtual bool IsExtensionPending(const std::string& id) = 0;
    109 
    110   // Invoked to get the current version of extension |id|. Returns false if
    111   // that extension is not installed.
    112   virtual bool GetExtensionExistingVersion(const std::string& id,
    113                                            std::string* version) = 0;
    114 };
    115 
    116 }  // namespace extensions
    117 
    118 #endif  // CHROME_BROWSER_EXTENSIONS_UPDATER_EXTENSION_DOWNLOADER_DELEGATE_H_
    119