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