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

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

Issue 6961027: Change event routers from singletons to being owned by the ExtensionService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: asargent and dmazzoni's comments Created 9 years, 7 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> 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 : profile_(profile) {}
25 virtual ~ExtensionHistoryEventRouter() {}
asargent_no_longer_on_chrome 2011/05/24 18:18:00 same inlining nit here
24 26
25 // Safe to call multiple times. 27 void Init();
26 void ObserveProfile(Profile* profile);
27 28
28 private: 29 private:
29 friend struct DefaultSingletonTraits<ExtensionHistoryEventRouter>;
30
31 ExtensionHistoryEventRouter();
32 virtual ~ExtensionHistoryEventRouter();
33
34 // NotificationObserver::Observe. 30 // NotificationObserver::Observe.
35 virtual void Observe(NotificationType type, 31 virtual void Observe(NotificationType type,
36 const NotificationSource& source, 32 const NotificationSource& source,
37 const NotificationDetails& details); 33 const NotificationDetails& details);
38 34
39 void HistoryUrlVisited(Profile* profile, 35 void HistoryUrlVisited(Profile* profile,
40 const history::URLVisitedDetails* details); 36 const history::URLVisitedDetails* details);
41 37
42 void HistoryUrlsRemoved(Profile* profile, 38 void HistoryUrlsRemoved(Profile* profile,
43 const history::URLsDeletedDetails* details); 39 const history::URLsDeletedDetails* details);
44 40
45 void DispatchEvent(Profile* profile, 41 void DispatchEvent(Profile* profile,
46 const char* event_name, 42 const char* event_name,
47 const std::string& json_args); 43 const std::string& json_args);
48 44
49 // Used for tracking registrations to history service notifications. 45 // Used for tracking registrations to history service notifications.
50 NotificationRegistrar registrar_; 46 NotificationRegistrar registrar_;
51 47
52 // Registered profiles. 48 // The associated Profile owns us transitively via ExtensionService.
53 typedef std::map<uintptr_t, Profile*> ProfileMap; 49 Profile* profile_;
54 ProfileMap profiles_;
55 50
56 DISALLOW_COPY_AND_ASSIGN(ExtensionHistoryEventRouter); 51 DISALLOW_COPY_AND_ASSIGN(ExtensionHistoryEventRouter);
57 }; 52 };
58 53
59 54
60 // Base class for history function APIs. 55 // Base class for history function APIs.
61 class HistoryFunction : public AsyncExtensionFunction { 56 class HistoryFunction : public AsyncExtensionFunction {
62 public: 57 public:
63 virtual void Run(); 58 virtual void Run();
64 virtual bool RunImpl() = 0; 59 virtual bool RunImpl() = 0;
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 class DeleteRangeHistoryFunction : public HistoryFunctionWithCallback { 137 class DeleteRangeHistoryFunction : public HistoryFunctionWithCallback {
143 public: 138 public:
144 virtual bool RunAsyncImpl(); 139 virtual bool RunAsyncImpl();
145 DECLARE_EXTENSION_FUNCTION_NAME("history.deleteRange"); 140 DECLARE_EXTENSION_FUNCTION_NAME("history.deleteRange");
146 141
147 // Callback for the history service to acknowledge deletion. 142 // Callback for the history service to acknowledge deletion.
148 void DeleteComplete(); 143 void DeleteComplete();
149 }; 144 };
150 145
151 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_HISTORY_API_H_ 146 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_HISTORY_API_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698