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

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

Issue 2669423004: history_api -> UIThreadExtensionFunction. (Closed)
Patch Set: sync 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
« no previous file with comments | « no previous file | chrome/browser/extensions/api/history/history_api.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.
122 // This method calls Release().
123 virtual void SendAsyncResponse();
124
125 // The task tracker for the HistoryService callbacks. 120 // The task tracker for the HistoryService callbacks.
126 base::CancelableTaskTracker task_tracker_; 121 base::CancelableTaskTracker task_tracker_;
127
128 private:
129 // The actual call to SendResponse. This is required since the semantics for
130 // CancelableRequestConsumerT require it to be accessed after the call.
131 void SendResponseToCallback();
132 }; 122 };
133 123
134 class HistoryGetVisitsFunction : public HistoryFunctionWithCallback { 124 class HistoryGetVisitsFunction : public HistoryFunctionWithCallback {
135 public: 125 public:
136 DECLARE_EXTENSION_FUNCTION("history.getVisits", HISTORY_GETVISITS) 126 DECLARE_EXTENSION_FUNCTION("history.getVisits", HISTORY_GETVISITS)
137 127
138 protected: 128 protected:
139 ~HistoryGetVisitsFunction() override {} 129 ~HistoryGetVisitsFunction() override {}
140 130
141 // HistoryFunctionWithCallback: 131 // ExtensionFunction:
142 bool RunAsyncImpl() override; 132 ResponseAction Run() override;
143 133
144 // Callback for the history function to provide results. 134 // Callback for the history function to provide results.
145 void QueryComplete(bool success, 135 void QueryComplete(bool success,
146 const history::URLRow& url_row, 136 const history::URLRow& url_row,
147 const history::VisitVector& visits); 137 const history::VisitVector& visits);
148 }; 138 };
149 139
150 class HistorySearchFunction : public HistoryFunctionWithCallback { 140 class HistorySearchFunction : public HistoryFunctionWithCallback {
151 public: 141 public:
152 DECLARE_EXTENSION_FUNCTION("history.search", HISTORY_SEARCH) 142 DECLARE_EXTENSION_FUNCTION("history.search", HISTORY_SEARCH)
153 143
154 protected: 144 protected:
155 ~HistorySearchFunction() override {} 145 ~HistorySearchFunction() override {}
156 146
157 // HistoryFunctionWithCallback: 147 // ExtensionFunction:
158 bool RunAsyncImpl() override; 148 ResponseAction Run() override;
159 149
160 // Callback for the history function to provide results. 150 // Callback for the history function to provide results.
161 void SearchComplete(history::QueryResults* results); 151 void SearchComplete(history::QueryResults* results);
162 }; 152 };
163 153
164 class HistoryAddUrlFunction : public HistoryFunction { 154 class HistoryAddUrlFunction : public HistoryFunction {
165 public: 155 public:
166 DECLARE_EXTENSION_FUNCTION("history.addUrl", HISTORY_ADDURL) 156 DECLARE_EXTENSION_FUNCTION("history.addUrl", HISTORY_ADDURL)
167 157
168 protected: 158 protected:
169 ~HistoryAddUrlFunction() override {} 159 ~HistoryAddUrlFunction() override {}
170 160
171 // HistoryFunctionWithCallback: 161 // ExtensionFunction:
172 bool RunAsync() override; 162 ResponseAction Run() override;
173 }; 163 };
174 164
175 class HistoryDeleteAllFunction : public HistoryFunctionWithCallback { 165 class HistoryDeleteAllFunction : public HistoryFunctionWithCallback {
176 public: 166 public:
177 DECLARE_EXTENSION_FUNCTION("history.deleteAll", HISTORY_DELETEALL) 167 DECLARE_EXTENSION_FUNCTION("history.deleteAll", HISTORY_DELETEALL)
178 168
179 protected: 169 protected:
180 ~HistoryDeleteAllFunction() override {} 170 ~HistoryDeleteAllFunction() override {}
181 171
182 // HistoryFunctionWithCallback: 172 // ExtensionFunction:
183 bool RunAsyncImpl() override; 173 ResponseAction Run() override;
184 174
185 // Callback for the history service to acknowledge deletion. 175 // Callback for the history service to acknowledge deletion.
186 void DeleteComplete(); 176 void DeleteComplete();
187 }; 177 };
188 178
189 179
190 class HistoryDeleteUrlFunction : public HistoryFunction { 180 class HistoryDeleteUrlFunction : public HistoryFunction {
191 public: 181 public:
192 DECLARE_EXTENSION_FUNCTION("history.deleteUrl", HISTORY_DELETEURL) 182 DECLARE_EXTENSION_FUNCTION("history.deleteUrl", HISTORY_DELETEURL)
193 183
194 protected: 184 protected:
195 ~HistoryDeleteUrlFunction() override {} 185 ~HistoryDeleteUrlFunction() override {}
196 186
197 // HistoryFunctionWithCallback: 187 // ExtensionFunction:
198 bool RunAsync() override; 188 ResponseAction Run() override;
199 }; 189 };
200 190
201 class HistoryDeleteRangeFunction : public HistoryFunctionWithCallback { 191 class HistoryDeleteRangeFunction : public HistoryFunctionWithCallback {
202 public: 192 public:
203 DECLARE_EXTENSION_FUNCTION("history.deleteRange", HISTORY_DELETERANGE) 193 DECLARE_EXTENSION_FUNCTION("history.deleteRange", HISTORY_DELETERANGE)
204 194
205 protected: 195 protected:
206 ~HistoryDeleteRangeFunction() override {} 196 ~HistoryDeleteRangeFunction() override {}
207 197
208 // HistoryFunctionWithCallback: 198 // ExtensionFunction:
209 bool RunAsyncImpl() override; 199 ResponseAction Run() override;
210 200
211 // Callback for the history service to acknowledge deletion. 201 // Callback for the history service to acknowledge deletion.
212 void DeleteComplete(); 202 void DeleteComplete();
213 }; 203 };
214 204
215 } // namespace extensions 205 } // namespace extensions
216 206
217 #endif // CHROME_BROWSER_EXTENSIONS_API_HISTORY_HISTORY_API_H_ 207 #endif // CHROME_BROWSER_EXTENSIONS_API_HISTORY_HISTORY_API_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/api/history/history_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698