Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / extensions / updater / extension_downloader_delegate.h
blobacc239b67dc73ffec1f36eb1121580bdc992b312
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 CHROME_BROWSER_EXTENSIONS_UPDATER_EXTENSION_DOWNLOADER_DELEGATE_H_
6 #define CHROME_BROWSER_EXTENSIONS_UPDATER_EXTENSION_DOWNLOADER_DELEGATE_H_
8 #include <set>
9 #include <string>
11 #include "base/time/time.h"
12 #include "chrome/browser/extensions/updater/manifest_fetch_data.h"
14 class GURL;
16 namespace base {
17 class FilePath;
20 namespace extensions {
22 class ExtensionDownloaderDelegate {
23 public:
24 virtual ~ExtensionDownloaderDelegate();
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,
32 // Failed to fetch the manifest for this extension.
33 MANIFEST_FETCH_FAILED,
35 // The manifest couldn't be parsed.
36 MANIFEST_INVALID,
38 // The manifest was fetched and parsed, and there are no updates for
39 // this extension.
40 NO_UPDATE_AVAILABLE,
42 // There was an update for this extension but the download of the crx
43 // failed.
44 CRX_FETCH_FAILED,
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();
53 // Whether a ping was sent.
54 bool did_ping;
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;
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.
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);
81 // Invoked if the extension had an update available and its crx was
82 // successfully downloaded to |path|. Ownership of that file is transferred
83 // to the delegate.
84 virtual void OnExtensionDownloadFinished(
85 const std::string& id,
86 const base::FilePath& path,
87 const GURL& download_url,
88 const std::string& version,
89 const PingResult& ping_result,
90 const std::set<int>& request_ids) = 0;
92 // The remaining methods are used by the ExtensionDownloader to retrieve
93 // information about extensions from the delegate.
95 // Invoked to fill the PingData for the given extension id. Returns false
96 // if PingData should not be included for this extension's update check
97 // (this is the default).
98 virtual bool GetPingDataForExtension(const std::string& id,
99 ManifestFetchData::PingData* ping);
101 // Invoked to get the update url data for this extension's update url, if
102 // there is any. The default implementation returns an empty string.
103 virtual std::string GetUpdateUrlData(const std::string& id);
105 // Invoked to determine whether extension |id| is currently
106 // pending installation.
107 virtual bool IsExtensionPending(const std::string& id) = 0;
109 // Invoked to get the current version of extension |id|. Returns false if
110 // that extension is not installed.
111 virtual bool GetExtensionExistingVersion(const std::string& id,
112 std::string* version) = 0;
115 } // namespace extensions
117 #endif // CHROME_BROWSER_EXTENSIONS_UPDATER_EXTENSION_DOWNLOADER_DELEGATE_H_