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

Side by Side Diff: chrome/browser/extensions/api/history/history_api.h

Issue 666153002: Standardize usage of virtual/override/final in chrome/browser/extensions/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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
OLDNEW
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
(...skipping 14 matching lines...) Expand all
25 } 25 }
26 26
27 namespace extensions { 27 namespace extensions {
28 28
29 // Observes History service and routes the notifications as events to the 29 // Observes History service and routes the notifications as events to the
30 // extension system. 30 // extension system.
31 class HistoryEventRouter : public content::NotificationObserver, 31 class HistoryEventRouter : public content::NotificationObserver,
32 public history::HistoryServiceObserver { 32 public history::HistoryServiceObserver {
33 public: 33 public:
34 HistoryEventRouter(Profile* profile, HistoryService* history_service); 34 HistoryEventRouter(Profile* profile, HistoryService* history_service);
35 virtual ~HistoryEventRouter(); 35 ~HistoryEventRouter() override;
36 36
37 private: 37 private:
38 // content::NotificationObserver::Observe. 38 // content::NotificationObserver::Observe.
39 virtual void Observe(int type, 39 void Observe(int type,
40 const content::NotificationSource& source, 40 const content::NotificationSource& source,
41 const content::NotificationDetails& details) override; 41 const content::NotificationDetails& details) override;
42 42
43 // history::HistoryServiceObserver. 43 // history::HistoryServiceObserver.
44 virtual void OnURLVisited(HistoryService* history_service, 44 void OnURLVisited(HistoryService* history_service,
45 ui::PageTransition transition, 45 ui::PageTransition transition,
46 const history::URLRow& row, 46 const history::URLRow& row,
47 const history::RedirectList& redirects, 47 const history::RedirectList& redirects,
48 base::Time visit_time) override; 48 base::Time visit_time) override;
49 49
50 void HistoryUrlsRemoved(Profile* profile, 50 void HistoryUrlsRemoved(Profile* profile,
51 const history::URLsDeletedDetails* details); 51 const history::URLsDeletedDetails* details);
52 52
53 void DispatchEvent(Profile* profile, 53 void DispatchEvent(Profile* profile,
54 const std::string& event_name, 54 const std::string& event_name,
55 scoped_ptr<base::ListValue> event_args); 55 scoped_ptr<base::ListValue> event_args);
56 56
57 // Used for tracking registrations to history service notifications. 57 // Used for tracking registrations to history service notifications.
58 content::NotificationRegistrar registrar_; 58 content::NotificationRegistrar registrar_;
59 Profile* profile_; 59 Profile* profile_;
60 ScopedObserver<HistoryService, HistoryServiceObserver> 60 ScopedObserver<HistoryService, HistoryServiceObserver>
61 history_service_observer_; 61 history_service_observer_;
62 62
63 DISALLOW_COPY_AND_ASSIGN(HistoryEventRouter); 63 DISALLOW_COPY_AND_ASSIGN(HistoryEventRouter);
64 }; 64 };
65 65
66 class HistoryAPI : public BrowserContextKeyedAPI, public EventRouter::Observer { 66 class HistoryAPI : public BrowserContextKeyedAPI, public EventRouter::Observer {
67 public: 67 public:
68 explicit HistoryAPI(content::BrowserContext* context); 68 explicit HistoryAPI(content::BrowserContext* context);
69 virtual ~HistoryAPI(); 69 ~HistoryAPI() override;
70 70
71 // KeyedService implementation. 71 // KeyedService implementation.
72 virtual void Shutdown() override; 72 void Shutdown() override;
73 73
74 // BrowserContextKeyedAPI implementation. 74 // BrowserContextKeyedAPI implementation.
75 static BrowserContextKeyedAPIFactory<HistoryAPI>* GetFactoryInstance(); 75 static BrowserContextKeyedAPIFactory<HistoryAPI>* GetFactoryInstance();
76 76
77 // EventRouter::Observer implementation. 77 // EventRouter::Observer implementation.
78 virtual void OnListenerAdded(const EventListenerInfo& details) override; 78 void OnListenerAdded(const EventListenerInfo& details) override;
79 79
80 private: 80 private:
81 friend class BrowserContextKeyedAPIFactory<HistoryAPI>; 81 friend class BrowserContextKeyedAPIFactory<HistoryAPI>;
82 82
83 content::BrowserContext* browser_context_; 83 content::BrowserContext* browser_context_;
84 84
85 // BrowserContextKeyedAPI implementation. 85 // BrowserContextKeyedAPI implementation.
86 static const char* service_name() { 86 static const char* service_name() {
87 return "HistoryAPI"; 87 return "HistoryAPI";
88 } 88 }
89 static const bool kServiceIsNULLWhileTesting = true; 89 static const bool kServiceIsNULLWhileTesting = true;
90 90
91 // Created lazily upon OnListenerAdded. 91 // Created lazily upon OnListenerAdded.
92 scoped_ptr<HistoryEventRouter> history_event_router_; 92 scoped_ptr<HistoryEventRouter> history_event_router_;
93 }; 93 };
94 94
95 template <> 95 template <>
96 void BrowserContextKeyedAPIFactory<HistoryAPI>::DeclareFactoryDependencies(); 96 void BrowserContextKeyedAPIFactory<HistoryAPI>::DeclareFactoryDependencies();
97 97
98 // Base class for history function APIs. 98 // Base class for history function APIs.
99 class HistoryFunction : public ChromeAsyncExtensionFunction { 99 class HistoryFunction : public ChromeAsyncExtensionFunction {
100 protected: 100 protected:
101 virtual ~HistoryFunction() {} 101 ~HistoryFunction() override {}
102 102
103 bool ValidateUrl(const std::string& url_string, GURL* url); 103 bool ValidateUrl(const std::string& url_string, GURL* url);
104 bool VerifyDeleteAllowed(); 104 bool VerifyDeleteAllowed();
105 base::Time GetTime(double ms_from_epoch); 105 base::Time GetTime(double ms_from_epoch);
106 }; 106 };
107 107
108 // Base class for history funciton APIs which require async interaction with 108 // Base class for history funciton APIs which require async interaction with
109 // chrome services and the extension thread. 109 // chrome services and the extension thread.
110 class HistoryFunctionWithCallback : public HistoryFunction { 110 class HistoryFunctionWithCallback : public HistoryFunction {
111 public: 111 public:
112 HistoryFunctionWithCallback(); 112 HistoryFunctionWithCallback();
113 113
114 protected: 114 protected:
115 virtual ~HistoryFunctionWithCallback(); 115 ~HistoryFunctionWithCallback() override;
116 116
117 // ExtensionFunction: 117 // ExtensionFunction:
118 virtual bool RunAsync() override; 118 bool RunAsync() override;
119 119
120 // Return true if the async call was completed, false otherwise. 120 // Return true if the async call was completed, false otherwise.
121 virtual bool RunAsyncImpl() = 0; 121 virtual bool RunAsyncImpl() = 0;
122 122
123 // Call this method to report the results of the async method to the caller. 123 // Call this method to report the results of the async method to the caller.
124 // This method calls Release(). 124 // This method calls Release().
125 virtual void SendAsyncResponse(); 125 virtual void SendAsyncResponse();
126 126
127 // The task tracker for the HistoryService callbacks. 127 // The task tracker for the HistoryService callbacks.
128 base::CancelableTaskTracker task_tracker_; 128 base::CancelableTaskTracker task_tracker_;
129 129
130 private: 130 private:
131 // The actual call to SendResponse. This is required since the semantics for 131 // The actual call to SendResponse. This is required since the semantics for
132 // CancelableRequestConsumerT require it to be accessed after the call. 132 // CancelableRequestConsumerT require it to be accessed after the call.
133 void SendResponseToCallback(); 133 void SendResponseToCallback();
134 }; 134 };
135 135
136 class HistoryGetVisitsFunction : public HistoryFunctionWithCallback { 136 class HistoryGetVisitsFunction : public HistoryFunctionWithCallback {
137 public: 137 public:
138 DECLARE_EXTENSION_FUNCTION("history.getVisits", HISTORY_GETVISITS) 138 DECLARE_EXTENSION_FUNCTION("history.getVisits", HISTORY_GETVISITS)
139 139
140 protected: 140 protected:
141 virtual ~HistoryGetVisitsFunction() {} 141 ~HistoryGetVisitsFunction() override {}
142 142
143 // HistoryFunctionWithCallback: 143 // HistoryFunctionWithCallback:
144 virtual bool RunAsyncImpl() override; 144 bool RunAsyncImpl() override;
145 145
146 // Callback for the history function to provide results. 146 // Callback for the history function to provide results.
147 void QueryComplete(bool success, 147 void QueryComplete(bool success,
148 const history::URLRow& url_row, 148 const history::URLRow& url_row,
149 const history::VisitVector& visits); 149 const history::VisitVector& visits);
150 }; 150 };
151 151
152 class HistorySearchFunction : public HistoryFunctionWithCallback { 152 class HistorySearchFunction : public HistoryFunctionWithCallback {
153 public: 153 public:
154 DECLARE_EXTENSION_FUNCTION("history.search", HISTORY_SEARCH) 154 DECLARE_EXTENSION_FUNCTION("history.search", HISTORY_SEARCH)
155 155
156 protected: 156 protected:
157 virtual ~HistorySearchFunction() {} 157 ~HistorySearchFunction() override {}
158 158
159 // HistoryFunctionWithCallback: 159 // HistoryFunctionWithCallback:
160 virtual bool RunAsyncImpl() override; 160 bool RunAsyncImpl() override;
161 161
162 // Callback for the history function to provide results. 162 // Callback for the history function to provide results.
163 void SearchComplete(history::QueryResults* results); 163 void SearchComplete(history::QueryResults* results);
164 }; 164 };
165 165
166 class HistoryAddUrlFunction : public HistoryFunction { 166 class HistoryAddUrlFunction : public HistoryFunction {
167 public: 167 public:
168 DECLARE_EXTENSION_FUNCTION("history.addUrl", HISTORY_ADDURL) 168 DECLARE_EXTENSION_FUNCTION("history.addUrl", HISTORY_ADDURL)
169 169
170 protected: 170 protected:
171 virtual ~HistoryAddUrlFunction() {} 171 ~HistoryAddUrlFunction() override {}
172 172
173 // HistoryFunctionWithCallback: 173 // HistoryFunctionWithCallback:
174 virtual bool RunAsync() override; 174 bool RunAsync() override;
175 }; 175 };
176 176
177 class HistoryDeleteAllFunction : public HistoryFunctionWithCallback { 177 class HistoryDeleteAllFunction : public HistoryFunctionWithCallback {
178 public: 178 public:
179 DECLARE_EXTENSION_FUNCTION("history.deleteAll", HISTORY_DELETEALL) 179 DECLARE_EXTENSION_FUNCTION("history.deleteAll", HISTORY_DELETEALL)
180 180
181 protected: 181 protected:
182 virtual ~HistoryDeleteAllFunction() {} 182 ~HistoryDeleteAllFunction() override {}
183 183
184 // HistoryFunctionWithCallback: 184 // HistoryFunctionWithCallback:
185 virtual bool RunAsyncImpl() override; 185 bool RunAsyncImpl() override;
186 186
187 // Callback for the history service to acknowledge deletion. 187 // Callback for the history service to acknowledge deletion.
188 void DeleteComplete(); 188 void DeleteComplete();
189 }; 189 };
190 190
191 191
192 class HistoryDeleteUrlFunction : public HistoryFunction { 192 class HistoryDeleteUrlFunction : public HistoryFunction {
193 public: 193 public:
194 DECLARE_EXTENSION_FUNCTION("history.deleteUrl", HISTORY_DELETEURL) 194 DECLARE_EXTENSION_FUNCTION("history.deleteUrl", HISTORY_DELETEURL)
195 195
196 protected: 196 protected:
197 virtual ~HistoryDeleteUrlFunction() {} 197 ~HistoryDeleteUrlFunction() override {}
198 198
199 // HistoryFunctionWithCallback: 199 // HistoryFunctionWithCallback:
200 virtual bool RunAsync() override; 200 bool RunAsync() override;
201 }; 201 };
202 202
203 class HistoryDeleteRangeFunction : public HistoryFunctionWithCallback { 203 class HistoryDeleteRangeFunction : public HistoryFunctionWithCallback {
204 public: 204 public:
205 DECLARE_EXTENSION_FUNCTION("history.deleteRange", HISTORY_DELETERANGE) 205 DECLARE_EXTENSION_FUNCTION("history.deleteRange", HISTORY_DELETERANGE)
206 206
207 protected: 207 protected:
208 virtual ~HistoryDeleteRangeFunction() {} 208 ~HistoryDeleteRangeFunction() override {}
209 209
210 // HistoryFunctionWithCallback: 210 // HistoryFunctionWithCallback:
211 virtual bool RunAsyncImpl() override; 211 bool RunAsyncImpl() override;
212 212
213 // Callback for the history service to acknowledge deletion. 213 // Callback for the history service to acknowledge deletion.
214 void DeleteComplete(); 214 void DeleteComplete();
215 }; 215 };
216 216
217 } // namespace extensions 217 } // namespace extensions
218 218
219 #endif // CHROME_BROWSER_EXTENSIONS_API_HISTORY_HISTORY_API_H_ 219 #endif // CHROME_BROWSER_EXTENSIONS_API_HISTORY_HISTORY_API_H_
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/gcm/gcm_apitest.cc ('k') | chrome/browser/extensions/api/history/history_apitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698