OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_HISTORY_HISTORY_API_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_HISTORY_HISTORY_API_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_API_HISTORY_HISTORY_API_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_HISTORY_HISTORY_API_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/task/cancelable_task_tracker.h" | 12 #include "base/task/cancelable_task_tracker.h" |
13 #include "chrome/browser/extensions/api/profile_keyed_api_factory.h" | |
14 #include "chrome/browser/extensions/chrome_extension_function.h" | 13 #include "chrome/browser/extensions/chrome_extension_function.h" |
15 #include "chrome/browser/history/history_notifications.h" | 14 #include "chrome/browser/history/history_notifications.h" |
16 #include "chrome/browser/history/history_service.h" | 15 #include "chrome/browser/history/history_service.h" |
17 #include "chrome/common/extensions/api/history.h" | 16 #include "chrome/common/extensions/api/history.h" |
18 #include "content/public/browser/notification_registrar.h" | 17 #include "content/public/browser/notification_registrar.h" |
| 18 #include "extensions/browser/browser_context_keyed_api_factory.h" |
19 #include "extensions/browser/event_router.h" | 19 #include "extensions/browser/event_router.h" |
20 | 20 |
21 namespace base { | 21 namespace base { |
22 class ListValue; | 22 class ListValue; |
23 } | 23 } |
24 | 24 |
25 namespace extensions { | 25 namespace extensions { |
26 | 26 |
27 // Observes History service and routes the notifications as events to the | 27 // Observes History service and routes the notifications as events to the |
28 // extension system. | 28 // extension system. |
(...skipping 17 matching lines...) Expand all Loading... |
46 void DispatchEvent(Profile* profile, | 46 void DispatchEvent(Profile* profile, |
47 const std::string& event_name, | 47 const std::string& event_name, |
48 scoped_ptr<base::ListValue> event_args); | 48 scoped_ptr<base::ListValue> event_args); |
49 | 49 |
50 // Used for tracking registrations to history service notifications. | 50 // Used for tracking registrations to history service notifications. |
51 content::NotificationRegistrar registrar_; | 51 content::NotificationRegistrar registrar_; |
52 | 52 |
53 DISALLOW_COPY_AND_ASSIGN(HistoryEventRouter); | 53 DISALLOW_COPY_AND_ASSIGN(HistoryEventRouter); |
54 }; | 54 }; |
55 | 55 |
56 class HistoryAPI : public ProfileKeyedAPI, | 56 class HistoryAPI : public BrowserContextKeyedAPI, public EventRouter::Observer { |
57 public EventRouter::Observer { | |
58 public: | 57 public: |
59 explicit HistoryAPI(content::BrowserContext* context); | 58 explicit HistoryAPI(content::BrowserContext* context); |
60 virtual ~HistoryAPI(); | 59 virtual ~HistoryAPI(); |
61 | 60 |
62 // BrowserContextKeyedService implementation. | 61 // BrowserContextKeyedService implementation. |
63 virtual void Shutdown() OVERRIDE; | 62 virtual void Shutdown() OVERRIDE; |
64 | 63 |
65 // ProfileKeyedAPI implementation. | 64 // BrowserContextKeyedAPI implementation. |
66 static ProfileKeyedAPIFactory<HistoryAPI>* GetFactoryInstance(); | 65 static BrowserContextKeyedAPIFactory<HistoryAPI>* GetFactoryInstance(); |
67 | 66 |
68 // EventRouter::Observer implementation. | 67 // EventRouter::Observer implementation. |
69 virtual void OnListenerAdded(const EventListenerInfo& details) OVERRIDE; | 68 virtual void OnListenerAdded(const EventListenerInfo& details) OVERRIDE; |
70 | 69 |
71 private: | 70 private: |
72 friend class ProfileKeyedAPIFactory<HistoryAPI>; | 71 friend class BrowserContextKeyedAPIFactory<HistoryAPI>; |
73 | 72 |
74 content::BrowserContext* browser_context_; | 73 content::BrowserContext* browser_context_; |
75 | 74 |
76 // ProfileKeyedAPI implementation. | 75 // BrowserContextKeyedAPI implementation. |
77 static const char* service_name() { | 76 static const char* service_name() { |
78 return "HistoryAPI"; | 77 return "HistoryAPI"; |
79 } | 78 } |
80 static const bool kServiceIsNULLWhileTesting = true; | 79 static const bool kServiceIsNULLWhileTesting = true; |
81 | 80 |
82 // Created lazily upon OnListenerAdded. | 81 // Created lazily upon OnListenerAdded. |
83 scoped_ptr<HistoryEventRouter> history_event_router_; | 82 scoped_ptr<HistoryEventRouter> history_event_router_; |
84 }; | 83 }; |
85 | 84 |
86 template<> | 85 template <> |
87 void ProfileKeyedAPIFactory<HistoryAPI>::DeclareFactoryDependencies(); | 86 void BrowserContextKeyedAPIFactory<HistoryAPI>::DeclareFactoryDependencies(); |
88 | 87 |
89 // Base class for history function APIs. | 88 // Base class for history function APIs. |
90 class HistoryFunction : public ChromeAsyncExtensionFunction { | 89 class HistoryFunction : public ChromeAsyncExtensionFunction { |
91 protected: | 90 protected: |
92 virtual ~HistoryFunction() {} | 91 virtual ~HistoryFunction() {} |
93 virtual void Run() OVERRIDE; | 92 virtual void Run() OVERRIDE; |
94 | 93 |
95 bool ValidateUrl(const std::string& url_string, GURL* url); | 94 bool ValidateUrl(const std::string& url_string, GURL* url); |
96 bool VerifyDeleteAllowed(); | 95 bool VerifyDeleteAllowed(); |
97 base::Time GetTime(double ms_from_epoch); | 96 base::Time GetTime(double ms_from_epoch); |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 // HistoryFunctionWithCallback: | 204 // HistoryFunctionWithCallback: |
206 virtual bool RunAsyncImpl() OVERRIDE; | 205 virtual bool RunAsyncImpl() OVERRIDE; |
207 | 206 |
208 // Callback for the history service to acknowledge deletion. | 207 // Callback for the history service to acknowledge deletion. |
209 void DeleteComplete(); | 208 void DeleteComplete(); |
210 }; | 209 }; |
211 | 210 |
212 } // namespace extensions | 211 } // namespace extensions |
213 | 212 |
214 #endif // CHROME_BROWSER_EXTENSIONS_API_HISTORY_HISTORY_API_H_ | 213 #endif // CHROME_BROWSER_EXTENSIONS_API_HISTORY_HISTORY_API_H_ |
OLD | NEW |