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 CHROME_BROWSER_EXTENSIONS_API_RUNTIME_CHROME_RUNTIME_API_DELEGATE_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_RUNTIME_CHROME_RUNTIME_API_DELEGATE_H_
11 #include "base/macros.h"
12 #include "content/public/browser/notification_observer.h"
13 #include "content/public/browser/notification_registrar.h"
14 #include "extensions/browser/api/runtime/runtime_api.h"
15 #include "extensions/browser/api/runtime/runtime_api_delegate.h"
23 class NotificationDetails
;
24 class NotificationSource
;
27 namespace extensions
{
32 class ChromeRuntimeAPIDelegate
: public extensions::RuntimeAPIDelegate
,
33 public content::NotificationObserver
{
35 explicit ChromeRuntimeAPIDelegate(content::BrowserContext
* context
);
36 ~ChromeRuntimeAPIDelegate() override
;
39 friend class extensions::RuntimeAPI
;
41 // extensions::RuntimeAPIDelegate implementation.
42 void AddUpdateObserver(extensions::UpdateObserver
* observer
) override
;
43 void RemoveUpdateObserver(extensions::UpdateObserver
* observer
) override
;
44 base::Version
GetPreviousExtensionVersion(
45 const extensions::Extension
* extension
) override
;
46 void ReloadExtension(const std::string
& extension_id
) override
;
47 bool CheckForUpdates(const std::string
& extension_id
,
48 const UpdateCheckCallback
& callback
) override
;
49 void OpenURL(const GURL
& uninstall_url
) override
;
50 bool GetPlatformInfo(extensions::api::runtime::PlatformInfo
* info
) override
;
51 bool RestartDevice(std::string
* error_message
) override
;
52 bool OpenOptionsPage(const extensions::Extension
* extension
) override
;
54 // content::NotificationObserver implementation.
55 void Observe(int type
,
56 const content::NotificationSource
& source
,
57 const content::NotificationDetails
& details
) override
;
59 void UpdateCheckComplete(const std::string
& extension_id
);
60 void CallUpdateCallbacks(const std::string
& extension_id
,
61 const UpdateCheckResult
& result
);
63 content::BrowserContext
* browser_context_
;
65 content::NotificationRegistrar registrar_
;
67 // Whether the API registered with the ExtensionService to receive
68 // update notifications.
69 bool registered_for_updates_
;
71 // Map to prevent extensions from getting stuck in reload loops. Maps
72 // extension id to the last time it was reloaded and the number of times
73 // it was reloaded with not enough time in between reloads.
74 std::map
<std::string
, std::pair
<base::TimeTicks
, int> > last_reload_time_
;
76 // Pending update checks.
77 typedef std::vector
<UpdateCheckCallback
> UpdateCallbackList
;
78 typedef std::map
<std::string
, UpdateCallbackList
> UpdateCallbackMap
;
79 UpdateCallbackMap pending_update_checks_
;
82 DISALLOW_COPY_AND_ASSIGN(ChromeRuntimeAPIDelegate
);
85 #endif // CHROME_BROWSER_EXTENSIONS_API_RUNTIME_CHROME_RUNTIME_API_DELEGATE_H_