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/scoped_observer.h" | 12 #include "base/scoped_observer.h" |
13 #include "base/task/cancelable_task_tracker.h" | 13 #include "base/task/cancelable_task_tracker.h" |
14 #include "chrome/browser/extensions/chrome_extension_function.h" | 14 #include "chrome/browser/extensions/chrome_extension_function.h" |
15 #include "chrome/browser/history/history_notifications.h" | 15 #include "chrome/browser/history/history_notifications.h" |
16 #include "chrome/browser/history/history_service.h" | 16 #include "chrome/browser/history/history_service.h" |
17 #include "chrome/common/extensions/api/history.h" | 17 #include "chrome/common/extensions/api/history.h" |
18 #include "components/history/core/browser/history_service_observer.h" | 18 #include "components/history/core/browser/history_service_observer.h" |
19 #include "content/public/browser/notification_registrar.h" | |
20 #include "extensions/browser/browser_context_keyed_api_factory.h" | 19 #include "extensions/browser/browser_context_keyed_api_factory.h" |
21 #include "extensions/browser/event_router.h" | 20 #include "extensions/browser/event_router.h" |
22 | 21 |
23 namespace base { | 22 namespace base { |
24 class ListValue; | 23 class ListValue; |
25 } | 24 } |
26 | 25 |
27 namespace extensions { | 26 namespace extensions { |
28 | 27 |
29 // Observes History service and routes the notifications as events to the | 28 // Observes History service and routes the notifications as events to the |
30 // extension system. | 29 // extension system. |
31 class HistoryEventRouter : public content::NotificationObserver, | 30 class HistoryEventRouter : public history::HistoryServiceObserver { |
32 public history::HistoryServiceObserver { | |
33 public: | 31 public: |
34 HistoryEventRouter(Profile* profile, HistoryService* history_service); | 32 HistoryEventRouter(Profile* profile, HistoryService* history_service); |
35 ~HistoryEventRouter() override; | 33 ~HistoryEventRouter() override; |
36 | 34 |
37 private: | 35 private: |
38 // content::NotificationObserver::Observe. | |
39 void Observe(int type, | |
40 const content::NotificationSource& source, | |
41 const content::NotificationDetails& details) override; | |
42 | |
43 // history::HistoryServiceObserver. | 36 // history::HistoryServiceObserver. |
44 void OnURLVisited(HistoryService* history_service, | 37 void OnURLVisited(HistoryService* history_service, |
45 ui::PageTransition transition, | 38 ui::PageTransition transition, |
46 const history::URLRow& row, | 39 const history::URLRow& row, |
47 const history::RedirectList& redirects, | 40 const history::RedirectList& redirects, |
48 base::Time visit_time) override; | 41 base::Time visit_time) override; |
| 42 void OnURLsDeleted( |
| 43 HistoryService* history_service, |
| 44 const history::URLsDeletedDetails& deleted_details) override; |
49 | 45 |
50 void HistoryUrlsRemoved(Profile* profile, | 46 void HistoryUrlsRemoved(Profile* profile, |
51 const history::URLsDeletedDetails* details); | 47 const history::URLsDeletedDetails* details); |
52 | 48 |
53 void DispatchEvent(Profile* profile, | 49 void DispatchEvent(Profile* profile, |
54 const std::string& event_name, | 50 const std::string& event_name, |
55 scoped_ptr<base::ListValue> event_args); | 51 scoped_ptr<base::ListValue> event_args); |
56 | 52 |
57 // Used for tracking registrations to history service notifications. | |
58 content::NotificationRegistrar registrar_; | |
59 Profile* profile_; | 53 Profile* profile_; |
60 ScopedObserver<HistoryService, HistoryServiceObserver> | 54 ScopedObserver<HistoryService, HistoryServiceObserver> |
61 history_service_observer_; | 55 history_service_observer_; |
62 | 56 |
63 DISALLOW_COPY_AND_ASSIGN(HistoryEventRouter); | 57 DISALLOW_COPY_AND_ASSIGN(HistoryEventRouter); |
64 }; | 58 }; |
65 | 59 |
66 class HistoryAPI : public BrowserContextKeyedAPI, public EventRouter::Observer { | 60 class HistoryAPI : public BrowserContextKeyedAPI, public EventRouter::Observer { |
67 public: | 61 public: |
68 explicit HistoryAPI(content::BrowserContext* context); | 62 explicit HistoryAPI(content::BrowserContext* context); |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 // HistoryFunctionWithCallback: | 204 // HistoryFunctionWithCallback: |
211 bool RunAsyncImpl() override; | 205 bool RunAsyncImpl() override; |
212 | 206 |
213 // Callback for the history service to acknowledge deletion. | 207 // Callback for the history service to acknowledge deletion. |
214 void DeleteComplete(); | 208 void DeleteComplete(); |
215 }; | 209 }; |
216 | 210 |
217 } // namespace extensions | 211 } // namespace extensions |
218 | 212 |
219 #endif // CHROME_BROWSER_EXTENSIONS_API_HISTORY_HISTORY_API_H_ | 213 #endif // CHROME_BROWSER_EXTENSIONS_API_HISTORY_HISTORY_API_H_ |
OLD | NEW |