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.
4
5#ifndef EXTENSIONS_BROWSER_API_RUNTIME_RUNTIME_API_DELEGATE_H
6#define EXTENSIONS_BROWSER_API_RUNTIME_RUNTIME_API_DELEGATE_H
7
8#include "base/callback.h"
9#include "base/version.h"
10
11class GURL;
12
13namespace extensions {
14
15namespace core_api {
16namespace runtime {
17struct PlatformInfo;
18}
19}
20
21class Extension;
22class UpdateObserver;
23
24// This is a delegate interface for chrome.runtime API behavior. Clients must
25// vend some implementation of this interface through
26// ExtensionsBrowserClient::CreateRuntimeAPIDelegate.
27class RuntimeAPIDelegate {
28 public:
29  struct UpdateCheckResult {
30    bool success;
31    std::string response;
32    std::string version;
33
34    UpdateCheckResult(bool success,
35                      const std::string& response,
36                      const std::string& version);
37  };
38
39  virtual ~RuntimeAPIDelegate() {}
40
41  // The callback given to RequestUpdateCheck.
42  typedef base::Callback<void(const UpdateCheckResult&)> UpdateCheckCallback;
43
44  // Registers an UpdateObserver on behalf of the runtime API.
45  virtual void AddUpdateObserver(UpdateObserver* observer) = 0;
46
47  // Unregisters an UpdateObserver on behalf of the runtime API.
48  virtual void RemoveUpdateObserver(UpdateObserver* observer) = 0;
49
50  // Determines an extension's previously installed version if applicable.
51  virtual base::Version GetPreviousExtensionVersion(
52      const Extension* extension) = 0;
53
54  // Reloads an extension.
55  virtual void ReloadExtension(const std::string& extension_id) = 0;
56
57  // Requests an extensions update update check. Returns |false| if updates
58  // are disabled. Otherwise |callback| is called with the result of the
59  // update check.
60  virtual bool CheckForUpdates(const std::string& extension_id,
61                               const UpdateCheckCallback& callback) = 0;
62
63  // Navigates the browser to a URL on behalf of the runtime API.
64  virtual void OpenURL(const GURL& uninstall_url) = 0;
65
66  // Populates platform info to be provided by the getPlatformInfo function.
67  // Returns false iff no info is provided.
68  virtual bool GetPlatformInfo(core_api::runtime::PlatformInfo* info) = 0;
69
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;
73};
74
75}  // namespace extensions
76
77#endif  // EXTENSIONS_BROWSER_API_RUNTIME_RUNTIME_API_DELEGATE_H
78