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

Side by Side Diff: chrome/browser/extensions/extension_history_api.h

Issue 7243012: Change many extension event routers to not be singletons and to be more profile-aware. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: bookmark remove observer Created 9 years, 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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_
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_cookies_api.cc ('k') | chrome/browser/extensions/extension_history_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698