| OLD | NEW | 
|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_RUNTIME_CHROME_RUNTIME_API_DELEGATE_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_RUNTIME_CHROME_RUNTIME_API_DELEGATE_H_ | 
| 6 #define CHROME_BROWSER_EXTENSIONS_API_RUNTIME_CHROME_RUNTIME_API_DELEGATE_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_RUNTIME_CHROME_RUNTIME_API_DELEGATE_H_ | 
| 7 | 7 | 
| 8 #include <map> | 8 #include <map> | 
| 9 #include <vector> | 9 #include <string> | 
|  | 10 #include <utility> | 
| 10 | 11 | 
| 11 #include "base/macros.h" | 12 #include "base/macros.h" | 
|  | 13 #include "base/scoped_observer.h" | 
| 12 #include "content/public/browser/notification_observer.h" | 14 #include "content/public/browser/notification_observer.h" | 
| 13 #include "content/public/browser/notification_registrar.h" | 15 #include "content/public/browser/notification_registrar.h" | 
| 14 #include "extensions/browser/api/runtime/runtime_api.h" | 16 #include "extensions/browser/api/runtime/runtime_api.h" | 
| 15 #include "extensions/browser/api/runtime/runtime_api_delegate.h" | 17 #include "extensions/browser/api/runtime/runtime_api_delegate.h" | 
|  | 18 #include "extensions/browser/extension_registry_observer.h" | 
| 16 | 19 | 
| 17 namespace base { | 20 namespace base { | 
|  | 21 class TickClock; | 
| 18 class TimeTicks; | 22 class TimeTicks; | 
| 19 } | 23 } | 
| 20 | 24 | 
| 21 namespace content { | 25 namespace content { | 
| 22 class BrowserContext; | 26 class BrowserContext; | 
| 23 class NotificationDetails; | 27 class NotificationDetails; | 
| 24 class NotificationSource; | 28 class NotificationSource; | 
| 25 } | 29 } | 
| 26 | 30 | 
| 27 namespace extensions { | 31 namespace extensions { | 
|  | 32 class ExtensionRegistry; | 
| 28 class RuntimeAPI; | 33 class RuntimeAPI; | 
| 29 class UpdateObserver; | 34 class UpdateObserver; | 
| 30 } | 35 } | 
| 31 | 36 | 
| 32 class ChromeRuntimeAPIDelegate : public extensions::RuntimeAPIDelegate, | 37 class ChromeRuntimeAPIDelegate : public extensions::RuntimeAPIDelegate, | 
| 33                                  public content::NotificationObserver { | 38                                  public content::NotificationObserver, | 
|  | 39                                  public extensions::ExtensionRegistryObserver { | 
| 34  public: | 40  public: | 
| 35   explicit ChromeRuntimeAPIDelegate(content::BrowserContext* context); | 41   explicit ChromeRuntimeAPIDelegate(content::BrowserContext* context); | 
| 36   ~ChromeRuntimeAPIDelegate() override; | 42   ~ChromeRuntimeAPIDelegate() override; | 
| 37 | 43 | 
|  | 44   // Sets a custom TickClock to use in tests. | 
|  | 45   static void set_tick_clock_for_tests(base::TickClock* clock); | 
|  | 46 | 
| 38  private: | 47  private: | 
| 39   friend class extensions::RuntimeAPI; | 48   friend class extensions::RuntimeAPI; | 
| 40 | 49 | 
| 41   // extensions::RuntimeAPIDelegate implementation. | 50   // extensions::RuntimeAPIDelegate implementation. | 
| 42   void AddUpdateObserver(extensions::UpdateObserver* observer) override; | 51   void AddUpdateObserver(extensions::UpdateObserver* observer) override; | 
| 43   void RemoveUpdateObserver(extensions::UpdateObserver* observer) override; | 52   void RemoveUpdateObserver(extensions::UpdateObserver* observer) override; | 
| 44   base::Version GetPreviousExtensionVersion( | 53   base::Version GetPreviousExtensionVersion( | 
| 45       const extensions::Extension* extension) override; | 54       const extensions::Extension* extension) override; | 
| 46   void ReloadExtension(const std::string& extension_id) override; | 55   void ReloadExtension(const std::string& extension_id) override; | 
| 47   bool CheckForUpdates(const std::string& extension_id, | 56   bool CheckForUpdates(const std::string& extension_id, | 
| 48                        const UpdateCheckCallback& callback) override; | 57                        const UpdateCheckCallback& callback) override; | 
| 49   void OpenURL(const GURL& uninstall_url) override; | 58   void OpenURL(const GURL& uninstall_url) override; | 
| 50   bool GetPlatformInfo(extensions::api::runtime::PlatformInfo* info) override; | 59   bool GetPlatformInfo(extensions::api::runtime::PlatformInfo* info) override; | 
| 51   bool RestartDevice(std::string* error_message) override; | 60   bool RestartDevice(std::string* error_message) override; | 
| 52   bool OpenOptionsPage(const extensions::Extension* extension) override; | 61   bool OpenOptionsPage(const extensions::Extension* extension) override; | 
| 53 | 62 | 
| 54   // content::NotificationObserver implementation. | 63   // content::NotificationObserver implementation. | 
| 55   void Observe(int type, | 64   void Observe(int type, | 
| 56                const content::NotificationSource& source, | 65                const content::NotificationSource& source, | 
| 57                const content::NotificationDetails& details) override; | 66                const content::NotificationDetails& details) override; | 
| 58 | 67 | 
|  | 68   // ExtensionRegistryObserver implementation. | 
|  | 69   void OnExtensionInstalled(content::BrowserContext* browser_context, | 
|  | 70                             const extensions::Extension* extension, | 
|  | 71                             bool is_update) override; | 
|  | 72 | 
| 59   void UpdateCheckComplete(const std::string& extension_id); | 73   void UpdateCheckComplete(const std::string& extension_id); | 
| 60   void CallUpdateCallbacks(const std::string& extension_id, | 74   void CallUpdateCallbacks(const std::string& extension_id, | 
| 61                            const UpdateCheckResult& result); | 75                            const UpdateCheckResult& result); | 
| 62 | 76 | 
| 63   content::BrowserContext* browser_context_; | 77   content::BrowserContext* browser_context_; | 
| 64 | 78 | 
| 65   content::NotificationRegistrar registrar_; | 79   content::NotificationRegistrar registrar_; | 
| 66 | 80 | 
| 67   // Whether the API registered with the ExtensionService to receive | 81   // Whether the API registered with the ExtensionService to receive | 
| 68   // update notifications. | 82   // update notifications. | 
| 69   bool registered_for_updates_; | 83   bool registered_for_updates_; | 
| 70 | 84 | 
| 71   // Map to prevent extensions from getting stuck in reload loops. Maps | 85   // 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 | 86   // 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. | 87   // it was reloaded with not enough time in between reloads. | 
| 74   std::map<std::string, std::pair<base::TimeTicks, int> > last_reload_time_; | 88   std::map<std::string, std::pair<base::TimeTicks, int> > last_reload_time_; | 
| 75 | 89 | 
| 76   // Pending update checks. | 90   // Information about update checks, keyed by extension id. | 
| 77   typedef std::vector<UpdateCheckCallback> UpdateCallbackList; | 91   struct UpdateCheckInfo; | 
| 78   typedef std::map<std::string, UpdateCallbackList> UpdateCallbackMap; | 92   std::map<std::string, UpdateCheckInfo> update_check_info_; | 
| 79   UpdateCallbackMap pending_update_checks_; |  | 
| 80 | 93 | 
| 81  private: | 94   ScopedObserver<extensions::ExtensionRegistry, | 
|  | 95                  extensions::ExtensionRegistryObserver> | 
|  | 96       extension_registry_observer_; | 
|  | 97 | 
| 82   DISALLOW_COPY_AND_ASSIGN(ChromeRuntimeAPIDelegate); | 98   DISALLOW_COPY_AND_ASSIGN(ChromeRuntimeAPIDelegate); | 
| 83 }; | 99 }; | 
| 84 | 100 | 
| 85 #endif  // CHROME_BROWSER_EXTENSIONS_API_RUNTIME_CHROME_RUNTIME_API_DELEGATE_H_ | 101 #endif  // CHROME_BROWSER_EXTENSIONS_API_RUNTIME_CHROME_RUNTIME_API_DELEGATE_H_ | 
| OLD | NEW | 
|---|