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.
5 #ifndef EXTENSIONS_BROWSER_UPDATER_EXTENSION_DOWNLOADER_DELEGATE_H_
6 #define EXTENSIONS_BROWSER_UPDATER_EXTENSION_DOWNLOADER_DELEGATE_H_
11 #include "base/callback.h"
12 #include "base/time/time.h"
13 #include "extensions/browser/crx_file_info.h"
14 #include "extensions/browser/updater/manifest_fetch_data.h"
22 namespace extensions
{
24 class ExtensionDownloaderDelegate
{
26 virtual ~ExtensionDownloaderDelegate();
28 // Passed as an argument to ExtensionDownloader::OnExtensionDownloadFailed()
29 // to detail the reason for the failure.
31 // Background networking is disabled.
34 // Failed to fetch the manifest for this extension.
35 MANIFEST_FETCH_FAILED
,
37 // The manifest couldn't be parsed.
40 // The manifest was fetched and parsed, and there are no updates for
44 // There was an update for this extension but the download of the crx
49 // Passed as an argument to the completion callbacks to signal whether
50 // the extension update sent a ping.
55 // Whether a ping was sent.
58 // The start of day, from the server's perspective. This is only valid
59 // when |did_ping| is true.
63 // A callback that is called to indicate if ExtensionDownloader should ignore
64 // the cached entry and download a new .crx file.
65 typedef base::Callback
<void(bool should_download
)> InstallCallback
;
67 // One of the following 3 methods is always invoked for a given extension
68 // id, if AddExtension() or AddPendingExtension() returned true when that
69 // extension was added to the ExtensionDownloader.
70 // To avoid duplicate work, ExtensionDownloader might merge multiple identical
71 // requests, so there is not necessarily a separate invocation of one of these
72 // methods for each call to AddExtension/AddPendingExtension. If it is
73 // important to be able to match up AddExtension calls with
74 // OnExtensionDownload callbacks, you need to make sure that for every call to
75 // AddExtension/AddPendingExtension the combination of extension id and
76 // request id is unique. The OnExtensionDownload related callbacks will then
77 // be called with all request ids that resulted in that extension being
80 // Invoked if the extension couldn't be downloaded. |error| contains the
82 virtual void OnExtensionDownloadFailed(const std::string
& id
,
84 const PingResult
& ping_result
,
85 const std::set
<int>& request_ids
);
87 // Invoked if the extension had an update available and its crx was
88 // successfully downloaded to |path|. |ownership_passed| is true if delegate
89 // should get ownership of the file. The downloader may be able to get the
90 // .crx file both from a locally cached version or by issuing a network
91 // request. If the install attempt by the delegate fails and the source was
92 // the cache, the cached version may be corrupt (or simply not the desired
93 // one), and we'd like to try downloading the .crx from the network and have
94 // the delegate attempt install again. So if the |callback| parameter is
95 // non-null (if the file was taken from the cache), on install failure the
96 // downloader should be notified to try download from network by calling the
97 // callback with true; on successful install it should be called with false so
98 // that downloader could release all downloaded metadata. After downloading
99 // the delegate will be once again called with OnExtensionDownloadFinished (or
100 // OnExtensionDownloadFailed) called again with the same |request_ids|.
101 virtual void OnExtensionDownloadFinished(const CRXFileInfo
& file
,
102 bool file_ownership_passed
,
103 const GURL
& download_url
,
104 const std::string
& version
,
105 const PingResult
& ping_result
,
106 const std::set
<int>& request_ids
,
107 const InstallCallback
& callback
) = 0;
109 // The remaining methods are used by the ExtensionDownloader to retrieve
110 // information about extensions from the delegate.
112 // Invoked to fill the PingData for the given extension id. Returns false
113 // if PingData should not be included for this extension's update check
114 // (this is the default).
115 virtual bool GetPingDataForExtension(const std::string
& id
,
116 ManifestFetchData::PingData
* ping
);
118 // Invoked to get the update url data for this extension's update url, if
119 // there is any. The default implementation returns an empty string.
120 virtual std::string
GetUpdateUrlData(const std::string
& id
);
122 // Invoked to determine whether extension |id| is currently
123 // pending installation.
124 virtual bool IsExtensionPending(const std::string
& id
) = 0;
126 // Invoked to get the current version of extension |id|. Returns false if
127 // that extension is not installed.
128 virtual bool GetExtensionExistingVersion(const std::string
& id
,
129 std::string
* version
) = 0;
131 // Determines if a given extension should be forced to update and (if so)
132 // what the source of this forcing is (i.e. what string will be passed
133 // in |installsource| as part of the update query parameters). The default
134 // implementation always returns |false|.
135 virtual bool ShouldForceUpdate(const std::string
& id
, std::string
* source
);
138 } // namespace extensions
140 #endif // EXTENSIONS_BROWSER_UPDATER_EXTENSION_DOWNLOADER_DELEGATE_H_