1 // Copyright 2014 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_API_RUNTIME_RUNTIME_API_DELEGATE_H
6 #define EXTENSIONS_BROWSER_API_RUNTIME_RUNTIME_API_DELEGATE_H
8 #include "base/callback.h"
9 #include "base/version.h"
13 namespace extensions
{
24 // This is a delegate interface for chrome.runtime API behavior. Clients must
25 // vend some implementation of this interface through
26 // ExtensionsBrowserClient::CreateRuntimeAPIDelegate.
27 class RuntimeAPIDelegate
{
29 struct UpdateCheckResult
{
34 UpdateCheckResult(bool success
,
35 const std::string
& response
,
36 const std::string
& version
);
39 virtual ~RuntimeAPIDelegate() {}
41 // The callback given to RequestUpdateCheck.
42 typedef base::Callback
<void(const UpdateCheckResult
&)> UpdateCheckCallback
;
44 // Registers an UpdateObserver on behalf of the runtime API.
45 virtual void AddUpdateObserver(UpdateObserver
* observer
) = 0;
47 // Unregisters an UpdateObserver on behalf of the runtime API.
48 virtual void RemoveUpdateObserver(UpdateObserver
* observer
) = 0;
50 // Determines an extension's previously installed version if applicable.
51 virtual base::Version
GetPreviousExtensionVersion(
52 const Extension
* extension
) = 0;
54 // Reloads an extension.
55 virtual void ReloadExtension(const std::string
& extension_id
) = 0;
57 // Requests an extensions update update check. Returns |false| if updates
58 // are disabled. Otherwise |callback| is called with the result of the
60 virtual bool CheckForUpdates(const std::string
& extension_id
,
61 const UpdateCheckCallback
& callback
) = 0;
63 // Navigates the browser to a URL on behalf of the runtime API.
64 virtual void OpenURL(const GURL
& uninstall_url
) = 0;
66 // Populates platform info to be provided by the getPlatformInfo function.
67 // Returns false iff no info is provided.
68 virtual bool GetPlatformInfo(api::runtime::PlatformInfo
* info
) = 0;
70 // Request a restart of the host device. Returns false iff the device
71 // will not be restarted.
72 virtual bool RestartDevice(std::string
* error_message
) = 0;
74 // Open |extension|'s options page, if it has one. Returns true if an
75 // options page was opened, false otherwise. See the docs of the
76 // chrome.runtime.openOptionsPage function for the gritty details.
77 virtual bool OpenOptionsPage(const Extension
* extension
);
80 } // namespace extensions
82 #endif // EXTENSIONS_BROWSER_API_RUNTIME_RUNTIME_API_DELEGATE_H