| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_EXTENSION_HISTORY_API_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_HISTORY_API_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_HISTORY_API_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_HISTORY_API_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | |
| 10 #include <string> | 9 #include <string> |
| 11 | 10 |
| 12 #include "base/memory/singleton.h" | |
| 13 #include "chrome/browser/extensions/extension_function.h" | 11 #include "chrome/browser/extensions/extension_function.h" |
| 14 #include "chrome/browser/history/history.h" | 12 #include "chrome/browser/history/history.h" |
| 15 #include "chrome/browser/history/history_notifications.h" | 13 #include "chrome/browser/history/history_notifications.h" |
| 16 #include "content/common/notification_registrar.h" | 14 #include "content/common/notification_registrar.h" |
| 17 | 15 |
| 18 // Observes History service and routes the notifications as events to the | 16 // Observes History service and routes the notifications as events to the |
| 19 // extension system. | 17 // extension system. |
| 20 class ExtensionHistoryEventRouter : public NotificationObserver { | 18 class ExtensionHistoryEventRouter : public NotificationObserver { |
| 21 public: | 19 public: |
| 22 // Single instance of the event router. | 20 explicit ExtensionHistoryEventRouter(); |
| 23 static ExtensionHistoryEventRouter* GetInstance(); | 21 virtual ~ExtensionHistoryEventRouter(); |
| 24 | 22 |
| 25 // Safe to call multiple times. | |
| 26 void ObserveProfile(Profile* profile); | 23 void ObserveProfile(Profile* profile); |
| 27 | 24 |
| 28 private: | 25 private: |
| 29 friend struct DefaultSingletonTraits<ExtensionHistoryEventRouter>; | |
| 30 | |
| 31 ExtensionHistoryEventRouter(); | |
| 32 virtual ~ExtensionHistoryEventRouter(); | |
| 33 | |
| 34 // NotificationObserver::Observe. | 26 // NotificationObserver::Observe. |
| 35 virtual void Observe(NotificationType type, | 27 virtual void Observe(NotificationType type, |
| 36 const NotificationSource& source, | 28 const NotificationSource& source, |
| 37 const NotificationDetails& details); | 29 const NotificationDetails& details); |
| 38 | 30 |
| 39 void HistoryUrlVisited(Profile* profile, | 31 void HistoryUrlVisited(Profile* profile, |
| 40 const history::URLVisitedDetails* details); | 32 const history::URLVisitedDetails* details); |
| 41 | 33 |
| 42 void HistoryUrlsRemoved(Profile* profile, | 34 void HistoryUrlsRemoved(Profile* profile, |
| 43 const history::URLsDeletedDetails* details); | 35 const history::URLsDeletedDetails* details); |
| 44 | 36 |
| 45 void DispatchEvent(Profile* profile, | 37 void DispatchEvent(Profile* profile, |
| 46 const char* event_name, | 38 const char* event_name, |
| 47 const std::string& json_args); | 39 const std::string& json_args); |
| 48 | 40 |
| 49 // Used for tracking registrations to history service notifications. | 41 // Used for tracking registrations to history service notifications. |
| 50 NotificationRegistrar registrar_; | 42 NotificationRegistrar registrar_; |
| 51 | 43 |
| 52 // Registered profiles. | |
| 53 typedef std::map<uintptr_t, Profile*> ProfileMap; | |
| 54 ProfileMap profiles_; | |
| 55 | |
| 56 DISALLOW_COPY_AND_ASSIGN(ExtensionHistoryEventRouter); | 44 DISALLOW_COPY_AND_ASSIGN(ExtensionHistoryEventRouter); |
| 57 }; | 45 }; |
| 58 | 46 |
| 59 | 47 |
| 60 // Base class for history function APIs. | 48 // Base class for history function APIs. |
| 61 class HistoryFunction : public AsyncExtensionFunction { | 49 class HistoryFunction : public AsyncExtensionFunction { |
| 62 public: | 50 public: |
| 63 virtual void Run(); | 51 virtual void Run(); |
| 64 virtual bool RunImpl() = 0; | 52 virtual bool RunImpl() = 0; |
| 65 | 53 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 class DeleteRangeHistoryFunction : public HistoryFunctionWithCallback { | 130 class DeleteRangeHistoryFunction : public HistoryFunctionWithCallback { |
| 143 public: | 131 public: |
| 144 virtual bool RunAsyncImpl(); | 132 virtual bool RunAsyncImpl(); |
| 145 DECLARE_EXTENSION_FUNCTION_NAME("history.deleteRange"); | 133 DECLARE_EXTENSION_FUNCTION_NAME("history.deleteRange"); |
| 146 | 134 |
| 147 // Callback for the history service to acknowledge deletion. | 135 // Callback for the history service to acknowledge deletion. |
| 148 void DeleteComplete(); | 136 void DeleteComplete(); |
| 149 }; | 137 }; |
| 150 | 138 |
| 151 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_HISTORY_API_H_ | 139 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_HISTORY_API_H_ |
| OLD | NEW |