Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Unified Diff: extensions/browser/api/runtime/runtime_api.h

Issue 264743014: Move chrome.runtime to //extensions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: extensions/browser/api/runtime/runtime_api.h
diff --git a/chrome/browser/extensions/api/runtime/runtime_api.h b/extensions/browser/api/runtime/runtime_api.h
similarity index 71%
rename from chrome/browser/extensions/api/runtime/runtime_api.h
rename to extensions/browser/api/runtime/runtime_api.h
index f648be145339a15b6571cbcbfbc9e0fb1e5533ff..4f6591d73947fa5b7d55fcb2c33d3ab76e64f5bf 100644
--- a/chrome/browser/extensions/api/runtime/runtime_api.h
+++ b/extensions/browser/api/runtime/runtime_api.h
@@ -2,20 +2,18 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef CHROME_BROWSER_EXTENSIONS_API_RUNTIME_RUNTIME_API_H_
-#define CHROME_BROWSER_EXTENSIONS_API_RUNTIME_RUNTIME_API_H_
+#ifndef EXTENSIONS_BROWSER_API_RUNTIME_RUNTIME_API_H_
+#define EXTENSIONS_BROWSER_API_RUNTIME_RUNTIME_API_H_
#include <string>
-#include "chrome/browser/extensions/chrome_extension_function.h"
-#include "chrome/common/extensions/api/runtime.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "extensions/browser/browser_context_keyed_api_factory.h"
+#include "extensions/browser/extension_function.h"
#include "extensions/browser/process_manager_observer.h"
#include "extensions/browser/update_observer.h"
-
-class Profile;
+#include "extensions/common/api/runtime.h"
namespace base {
class Version;
@@ -28,6 +26,7 @@ class BrowserContext;
namespace extensions {
class Extension;
class ExtensionHost;
+class RuntimeAPIDelegate;
// Runtime API dispatches onStartup, onInstalled, and similar events to
// extensions. There is one instance shared between a browser context and
@@ -37,6 +36,19 @@ class RuntimeAPI : public BrowserContextKeyedAPI,
public UpdateObserver,
public ProcessManagerObserver {
public:
+ struct UpdateCheckResult {
+ bool success;
+ std::string response;
+ std::string version;
+
+ UpdateCheckResult(bool success,
+ const std::string& response,
+ const std::string& version);
+ };
+
+ // The callback given to RequestUpdateCheck.
+ typedef base::Callback<void(const UpdateCheckResult&)> UpdateCheckCallback;
+
static BrowserContextKeyedAPIFactory<RuntimeAPI>* GetFactoryInstance();
explicit RuntimeAPI(content::BrowserContext* context);
@@ -48,6 +60,13 @@ class RuntimeAPI : public BrowserContextKeyedAPI,
const content::NotificationDetails& details) OVERRIDE;
void MaybeReloadExtension(const std::string& extension_id);
+ void RequestUpdateCheck(const std::string& extension_id,
+ const UpdateCheckCallback& callback);
+ void HandleUninstall(const std::string& extension_id,
+ const GURL& uninstall_url);
+ bool GetPlatformInfo(
+ core_api::runtime::GetPlatformInfo::Results::PlatformInfo* info);
+ bool RequestRestart(std::string* error_message);
private:
friend class BrowserContextKeyedAPIFactory<RuntimeAPI>;
@@ -70,23 +89,16 @@ class RuntimeAPI : public BrowserContextKeyedAPI,
// ProcessManagerObserver implementation:
virtual void OnBackgroundHostStartup(const Extension* extension) OVERRIDE;
+ scoped_ptr<RuntimeAPIDelegate> delegate_;
+
content::BrowserContext* browser_context_;
// True if we should dispatch the chrome.runtime.onInstalled event with
// reason "chrome_update" upon loading each extension.
bool dispatch_chrome_updated_event_;
- // Whether the API registered with the ExtensionService to receive
- // update notifications.
- bool registered_for_updates_;
-
content::NotificationRegistrar registrar_;
- // Map to prevent extensions from getting stuck in reload loops. Maps
- // extension id to the last time it was reloaded and the number of times
- // it was reloaded with not enough time in between reloads.
- std::map<std::string, std::pair<base::TimeTicks, int> > last_reload_time_;
-
DISALLOW_COPY_AND_ASSIGN(RuntimeAPI);
};
@@ -104,25 +116,26 @@ class RuntimeEventRouter {
// Dispatches the onUpdateAvailable event to the given extension.
static void DispatchOnUpdateAvailableEvent(
- Profile* profile,
+ content::BrowserContext* context,
const std::string& extension_id,
const base::DictionaryValue* manifest);
// Dispatches the onBrowserUpdateAvailable event to all extensions.
- static void DispatchOnBrowserUpdateAvailableEvent(Profile* profile);
+ static void DispatchOnBrowserUpdateAvailableEvent(
+ content::BrowserContext* context);
// Dispatches the onRestartRequired event to the given app.
static void DispatchOnRestartRequiredEvent(
- Profile* profile,
+ content::BrowserContext* context,
const std::string& app_id,
- api::runtime::OnRestartRequired::Reason reason);
+ core_api::runtime::OnRestartRequired::Reason reason);
// Does any work needed at extension uninstall (e.g. load uninstall url).
- static void OnExtensionUninstalled(Profile* profile,
+ static void OnExtensionUninstalled(content::BrowserContext* context,
const std::string& extension_id);
};
-class RuntimeGetBackgroundPageFunction : public ChromeAsyncExtensionFunction {
+class RuntimeGetBackgroundPageFunction : public UIThreadExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("runtime.getBackgroundPage",
RUNTIME_GETBACKGROUNDPAGE)
@@ -135,17 +148,16 @@ class RuntimeGetBackgroundPageFunction : public ChromeAsyncExtensionFunction {
void OnPageLoaded(ExtensionHost*);
};
-class RuntimeSetUninstallURLFunction : public ChromeSyncExtensionFunction {
+class RuntimeSetUninstallURLFunction : public SyncExtensionFunction {
public:
- DECLARE_EXTENSION_FUNCTION("runtime.setUninstallURL",
- RUNTIME_SETUNINSTALLURL)
+ DECLARE_EXTENSION_FUNCTION("runtime.setUninstallURL", RUNTIME_SETUNINSTALLURL)
protected:
virtual ~RuntimeSetUninstallURLFunction() {}
virtual bool RunSync() OVERRIDE;
};
-class RuntimeReloadFunction : public ChromeSyncExtensionFunction {
+class RuntimeReloadFunction : public SyncExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("runtime.reload", RUNTIME_RELOAD)
@@ -154,30 +166,20 @@ class RuntimeReloadFunction : public ChromeSyncExtensionFunction {
virtual bool RunSync() OVERRIDE;
};
-class RuntimeRequestUpdateCheckFunction : public ChromeAsyncExtensionFunction,
- public content::NotificationObserver {
+class RuntimeRequestUpdateCheckFunction : public UIThreadExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("runtime.requestUpdateCheck",
RUNTIME_REQUESTUPDATECHECK)
- RuntimeRequestUpdateCheckFunction();
protected:
virtual ~RuntimeRequestUpdateCheckFunction() {}
virtual bool RunAsync() OVERRIDE;
- // Implements content::NotificationObserver interface.
- virtual void Observe(int type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) OVERRIDE;
private:
- void CheckComplete();
- void ReplyUpdateFound(const std::string& version);
-
- content::NotificationRegistrar registrar_;
- bool did_reply_;
+ void CheckComplete(const RuntimeAPI::UpdateCheckResult& result);
};
-class RuntimeRestartFunction : public ChromeSyncExtensionFunction {
+class RuntimeRestartFunction : public SyncExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("runtime.restart", RUNTIME_RESTART)
@@ -186,17 +188,17 @@ class RuntimeRestartFunction : public ChromeSyncExtensionFunction {
virtual bool RunSync() OVERRIDE;
};
-class RuntimeGetPlatformInfoFunction : public ChromeSyncExtensionFunction {
+class RuntimeGetPlatformInfoFunction : public SyncExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("runtime.getPlatformInfo",
RUNTIME_GETPLATFORMINFO);
+
protected:
virtual ~RuntimeGetPlatformInfoFunction() {}
virtual bool RunSync() OVERRIDE;
};
-class RuntimeGetPackageDirectoryEntryFunction
- : public ChromeSyncExtensionFunction {
+class RuntimeGetPackageDirectoryEntryFunction : public SyncExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("runtime.getPackageDirectoryEntry",
RUNTIME_GETPACKAGEDIRECTORYENTRY)
@@ -208,4 +210,4 @@ class RuntimeGetPackageDirectoryEntryFunction
} // namespace extensions
-#endif // CHROME_BROWSER_EXTENSIONS_API_RUNTIME_RUNTIME_API_H_
+#endif // EXTENSIONS_BROWSER_API_RUNTIME_RUNTIME_API_H_

Powered by Google App Engine
This is Rietveld 408576698