| 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" | |
| 16 #include "chrome/browser/history/history_service.h" | |
| 17 #include "chrome/common/extensions/api/history.h" | 15 #include "chrome/common/extensions/api/history.h" |
| 18 #include "components/history/core/browser/history_service_observer.h" | 16 #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" | 17 #include "extensions/browser/browser_context_keyed_api_factory.h" |
| 21 #include "extensions/browser/event_router.h" | 18 #include "extensions/browser/event_router.h" |
| 22 | 19 |
| 20 class HistoryService; |
| 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; |
| 49 | 42 void OnURLsDeleted(HistoryService* history_service, |
| 50 void HistoryUrlsRemoved(Profile* profile, | 43 bool all_history, |
| 51 const history::URLsDeletedDetails* details); | 44 bool expired, |
| 45 const history::URLRows& deleted_rows, |
| 46 const std::set<GURL>& favicon_urls) override; |
| 52 | 47 |
| 53 void DispatchEvent(Profile* profile, | 48 void DispatchEvent(Profile* profile, |
| 54 const std::string& event_name, | 49 const std::string& event_name, |
| 55 scoped_ptr<base::ListValue> event_args); | 50 scoped_ptr<base::ListValue> event_args); |
| 56 | 51 |
| 57 // Used for tracking registrations to history service notifications. | |
| 58 content::NotificationRegistrar registrar_; | |
| 59 Profile* profile_; | 52 Profile* profile_; |
| 60 ScopedObserver<HistoryService, HistoryServiceObserver> | 53 ScopedObserver<HistoryService, HistoryServiceObserver> |
| 61 history_service_observer_; | 54 history_service_observer_; |
| 62 | 55 |
| 63 DISALLOW_COPY_AND_ASSIGN(HistoryEventRouter); | 56 DISALLOW_COPY_AND_ASSIGN(HistoryEventRouter); |
| 64 }; | 57 }; |
| 65 | 58 |
| 66 class HistoryAPI : public BrowserContextKeyedAPI, public EventRouter::Observer { | 59 class HistoryAPI : public BrowserContextKeyedAPI, public EventRouter::Observer { |
| 67 public: | 60 public: |
| 68 explicit HistoryAPI(content::BrowserContext* context); | 61 explicit HistoryAPI(content::BrowserContext* context); |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 // HistoryFunctionWithCallback: | 203 // HistoryFunctionWithCallback: |
| 211 bool RunAsyncImpl() override; | 204 bool RunAsyncImpl() override; |
| 212 | 205 |
| 213 // Callback for the history service to acknowledge deletion. | 206 // Callback for the history service to acknowledge deletion. |
| 214 void DeleteComplete(); | 207 void DeleteComplete(); |
| 215 }; | 208 }; |
| 216 | 209 |
| 217 } // namespace extensions | 210 } // namespace extensions |
| 218 | 211 |
| 219 #endif // CHROME_BROWSER_EXTENSIONS_API_HISTORY_HISTORY_API_H_ | 212 #endif // CHROME_BROWSER_EXTENSIONS_API_HISTORY_HISTORY_API_H_ |
| OLD | NEW |