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

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

Issue 2669423004: history_api -> UIThreadExtensionFunction. (Closed)
Patch Set: Created 3 years, 10 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
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/scoped_observer.h" 13 #include "base/scoped_observer.h"
14 #include "base/task/cancelable_task_tracker.h" 14 #include "base/task/cancelable_task_tracker.h"
15 #include "chrome/browser/extensions/chrome_extension_function.h"
16 #include "chrome/common/extensions/api/history.h" 15 #include "chrome/common/extensions/api/history.h"
17 #include "components/history/core/browser/history_service_observer.h" 16 #include "components/history/core/browser/history_service_observer.h"
18 #include "extensions/browser/browser_context_keyed_api_factory.h" 17 #include "extensions/browser/browser_context_keyed_api_factory.h"
19 #include "extensions/browser/event_router.h" 18 #include "extensions/browser/event_router.h"
19 #include "extensions/browser/extension_function.h"
20
21 class Profile;
20 22
21 namespace base { 23 namespace base {
22 class ListValue; 24 class ListValue;
23 } 25 }
24 26
25 namespace history { 27 namespace history {
26 class HistoryService; 28 class HistoryService;
27 } 29 }
28 30
29 namespace extensions { 31 namespace extensions {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 static const bool kServiceIsNULLWhileTesting = true; 89 static const bool kServiceIsNULLWhileTesting = true;
88 90
89 // Created lazily upon OnListenerAdded. 91 // Created lazily upon OnListenerAdded.
90 std::unique_ptr<HistoryEventRouter> history_event_router_; 92 std::unique_ptr<HistoryEventRouter> history_event_router_;
91 }; 93 };
92 94
93 template <> 95 template <>
94 void BrowserContextKeyedAPIFactory<HistoryAPI>::DeclareFactoryDependencies(); 96 void BrowserContextKeyedAPIFactory<HistoryAPI>::DeclareFactoryDependencies();
95 97
96 // Base class for history function APIs. 98 // Base class for history function APIs.
97 class HistoryFunction : public ChromeAsyncExtensionFunction { 99 class HistoryFunction : public UIThreadExtensionFunction {
98 protected: 100 protected:
99 ~HistoryFunction() override {} 101 ~HistoryFunction() override {}
100 102
101 bool ValidateUrl(const std::string& url_string, GURL* url); 103 bool ValidateUrl(const std::string& url_string,
102 bool VerifyDeleteAllowed(); 104 GURL* url,
105 std::string* error);
106 bool VerifyDeleteAllowed(std::string* error);
103 base::Time GetTime(double ms_from_epoch); 107 base::Time GetTime(double ms_from_epoch);
108 Profile* GetProfile() const;
104 }; 109 };
105 110
106 // Base class for history funciton APIs which require async interaction with 111 // Base class for history funciton APIs which require async interaction with
107 // chrome services and the extension thread. 112 // chrome services and the extension thread.
108 class HistoryFunctionWithCallback : public HistoryFunction { 113 class HistoryFunctionWithCallback : public HistoryFunction {
109 public: 114 public:
110 HistoryFunctionWithCallback(); 115 HistoryFunctionWithCallback();
111 116
112 protected: 117 protected:
113 ~HistoryFunctionWithCallback() override; 118 ~HistoryFunctionWithCallback() override;
114 119
115 // ExtensionFunction:
116 bool RunAsync() override;
117
118 // Return true if the async call was completed, false otherwise.
119 virtual bool RunAsyncImpl() = 0;
120
121 // Call this method to report the results of the async method to the caller. 120 // Call this method to report the results of the async method to the caller.
122 // This method calls Release(). 121 // This method calls Release().
123 virtual void SendAsyncResponse(); 122 virtual void SendAsyncResponse(ResponseValue response_value);
124 123
125 // The task tracker for the HistoryService callbacks. 124 // The task tracker for the HistoryService callbacks.
126 base::CancelableTaskTracker task_tracker_; 125 base::CancelableTaskTracker task_tracker_;
127 126
128 private: 127 private:
129 // The actual call to SendResponse. This is required since the semantics for 128 // The actual call to SendResponse. This is required since the semantics for
130 // CancelableRequestConsumerT require it to be accessed after the call. 129 // CancelableRequestConsumerT require it to be accessed after the call.
131 void SendResponseToCallback(); 130 void SendResponseToCallback(ResponseValue response_value);
132 }; 131 };
133 132
134 class HistoryGetVisitsFunction : public HistoryFunctionWithCallback { 133 class HistoryGetVisitsFunction : public HistoryFunctionWithCallback {
135 public: 134 public:
136 DECLARE_EXTENSION_FUNCTION("history.getVisits", HISTORY_GETVISITS) 135 DECLARE_EXTENSION_FUNCTION("history.getVisits", HISTORY_GETVISITS)
137 136
138 protected: 137 protected:
139 ~HistoryGetVisitsFunction() override {} 138 ~HistoryGetVisitsFunction() override {}
140 139
141 // HistoryFunctionWithCallback: 140 // ExtensionFunction:
142 bool RunAsyncImpl() override; 141 ResponseAction Run() override;
143 142
144 // Callback for the history function to provide results. 143 // Callback for the history function to provide results.
145 void QueryComplete(bool success, 144 void QueryComplete(bool success,
146 const history::URLRow& url_row, 145 const history::URLRow& url_row,
147 const history::VisitVector& visits); 146 const history::VisitVector& visits);
148 }; 147 };
149 148
150 class HistorySearchFunction : public HistoryFunctionWithCallback { 149 class HistorySearchFunction : public HistoryFunctionWithCallback {
151 public: 150 public:
152 DECLARE_EXTENSION_FUNCTION("history.search", HISTORY_SEARCH) 151 DECLARE_EXTENSION_FUNCTION("history.search", HISTORY_SEARCH)
153 152
154 protected: 153 protected:
155 ~HistorySearchFunction() override {} 154 ~HistorySearchFunction() override {}
156 155
157 // HistoryFunctionWithCallback: 156 // ExtensionFunction:
158 bool RunAsyncImpl() override; 157 ResponseAction Run() override;
159 158
160 // Callback for the history function to provide results. 159 // Callback for the history function to provide results.
161 void SearchComplete(history::QueryResults* results); 160 void SearchComplete(history::QueryResults* results);
162 }; 161 };
163 162
164 class HistoryAddUrlFunction : public HistoryFunction { 163 class HistoryAddUrlFunction : public HistoryFunction {
165 public: 164 public:
166 DECLARE_EXTENSION_FUNCTION("history.addUrl", HISTORY_ADDURL) 165 DECLARE_EXTENSION_FUNCTION("history.addUrl", HISTORY_ADDURL)
167 166
168 protected: 167 protected:
169 ~HistoryAddUrlFunction() override {} 168 ~HistoryAddUrlFunction() override {}
170 169
171 // HistoryFunctionWithCallback: 170 // ExtensionFunction:
172 bool RunAsync() override; 171 ResponseAction Run() override;
173 }; 172 };
174 173
175 class HistoryDeleteAllFunction : public HistoryFunctionWithCallback { 174 class HistoryDeleteAllFunction : public HistoryFunctionWithCallback {
176 public: 175 public:
177 DECLARE_EXTENSION_FUNCTION("history.deleteAll", HISTORY_DELETEALL) 176 DECLARE_EXTENSION_FUNCTION("history.deleteAll", HISTORY_DELETEALL)
178 177
179 protected: 178 protected:
180 ~HistoryDeleteAllFunction() override {} 179 ~HistoryDeleteAllFunction() override {}
181 180
182 // HistoryFunctionWithCallback: 181 // ExtensionFunction:
183 bool RunAsyncImpl() override; 182 ResponseAction Run() override;
184 183
185 // Callback for the history service to acknowledge deletion. 184 // Callback for the history service to acknowledge deletion.
186 void DeleteComplete(); 185 void DeleteComplete();
187 }; 186 };
188 187
189 188
190 class HistoryDeleteUrlFunction : public HistoryFunction { 189 class HistoryDeleteUrlFunction : public HistoryFunction {
191 public: 190 public:
192 DECLARE_EXTENSION_FUNCTION("history.deleteUrl", HISTORY_DELETEURL) 191 DECLARE_EXTENSION_FUNCTION("history.deleteUrl", HISTORY_DELETEURL)
193 192
194 protected: 193 protected:
195 ~HistoryDeleteUrlFunction() override {} 194 ~HistoryDeleteUrlFunction() override {}
196 195
197 // HistoryFunctionWithCallback: 196 // ExtensionFunction:
198 bool RunAsync() override; 197 ResponseAction Run() override;
199 }; 198 };
200 199
201 class HistoryDeleteRangeFunction : public HistoryFunctionWithCallback { 200 class HistoryDeleteRangeFunction : public HistoryFunctionWithCallback {
202 public: 201 public:
203 DECLARE_EXTENSION_FUNCTION("history.deleteRange", HISTORY_DELETERANGE) 202 DECLARE_EXTENSION_FUNCTION("history.deleteRange", HISTORY_DELETERANGE)
204 203
205 protected: 204 protected:
206 ~HistoryDeleteRangeFunction() override {} 205 ~HistoryDeleteRangeFunction() override {}
207 206
208 // HistoryFunctionWithCallback: 207 // ExtensionFunction:
209 bool RunAsyncImpl() override; 208 ResponseAction Run() override;
210 209
211 // Callback for the history service to acknowledge deletion. 210 // Callback for the history service to acknowledge deletion.
212 void DeleteComplete(); 211 void DeleteComplete();
213 }; 212 };
214 213
215 } // namespace extensions 214 } // namespace extensions
216 215
217 #endif // CHROME_BROWSER_EXTENSIONS_API_HISTORY_HISTORY_API_H_ 216 #endif // CHROME_BROWSER_EXTENSIONS_API_HISTORY_HISTORY_API_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698