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/time/time.h"
12 #include "extensions/browser/crx_file_info.h"
13 #include "extensions/browser/updater/manifest_fetch_data.h"
21 namespace extensions
{
23 class ExtensionDownloaderDelegate
{
25 virtual ~ExtensionDownloaderDelegate();
27 // Passed as an argument to ExtensionDownloader::OnExtensionDownloadFailed()
28 // to detail the reason for the failure.
30 // Background networking is disabled.
33 // Failed to fetch the manifest for this extension.
34 MANIFEST_FETCH_FAILED
,
36 // The manifest couldn't be parsed.
39 // The manifest was fetched and parsed, and there are no updates for
43 // There was an update for this extension but the download of the crx
48 // Passed as an argument to the completion callbacks to signal whether
49 // the extension update sent a ping.
54 // Whether a ping was sent.
57 // The start of day, from the server's perspective. This is only valid
58 // when |did_ping| is true.
62 // One of the following 3 methods is always invoked for a given extension
63 // id, if AddExtension() or AddPendingExtension() returned true when that
64 // extension was added to the ExtensionDownloader.
65 // To avoid duplicate work, ExtensionDownloader might merge multiple identical
66 // requests, so there is not necessarily a separate invocation of one of these
67 // methods for each call to AddExtension/AddPendingExtension. If it is
68 // important to be able to match up AddExtension calls with
69 // OnExtensionDownload callbacks, you need to make sure that for every call to
70 // AddExtension/AddPendingExtension the combination of extension id and
71 // request id is unique. The OnExtensionDownload related callbacks will then
72 // be called with all request ids that resulted in that extension being
75 // Invoked if the extension couldn't be downloaded. |error| contains the
77 virtual void OnExtensionDownloadFailed(const std::string
& id
,
79 const PingResult
& ping_result
,
80 const std::set
<int>& request_ids
);
82 // Invoked if the extension had an update available and its crx was
83 // successfully downloaded to |path|. |ownership_passed| is true if delegate
84 // should get ownership of the file.
85 virtual void OnExtensionDownloadFinished(
86 const CRXFileInfo
& file
,
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;
93 // The remaining methods are used by the ExtensionDownloader to retrieve
94 // information about extensions from the delegate.
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
);
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
);
106 // Invoked to determine whether extension |id| is currently
107 // pending installation.
108 virtual bool IsExtensionPending(const std::string
& id
) = 0;
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;
115 // Determines if a given extension should be forced to update and (if so)
116 // what the source of this forcing is (i.e. what string will be passed
117 // in |installsource| as part of the update query parameters). The default
118 // implementation always returns |false|.
119 virtual bool ShouldForceUpdate(const std::string
& id
, std::string
* source
);
122 } // namespace extensions
124 #endif // EXTENSIONS_BROWSER_UPDATER_EXTENSION_DOWNLOADER_DELEGATE_H_