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

Side by Side Diff: chrome/browser/webdata/web_data_service.cc

Issue 11761016: Separate WebDataRequest functionality from WebDataService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add second ctor Created 7 years, 11 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 | Annotate | Revision Log
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 #include "chrome/browser/webdata/web_data_service.h" 5 #include "chrome/browser/webdata/web_data_service.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "base/threading/thread.h" 10 #include "base/threading/thread.h"
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 77
78 WDKeywordsResult::~WDKeywordsResult() {} 78 WDKeywordsResult::~WDKeywordsResult() {}
79 79
80 WebDataService::WebDataService() 80 WebDataService::WebDataService()
81 : is_running_(false), 81 : is_running_(false),
82 db_(NULL), 82 db_(NULL),
83 autocomplete_syncable_service_(NULL), 83 autocomplete_syncable_service_(NULL),
84 autofill_profile_syncable_service_(NULL), 84 autofill_profile_syncable_service_(NULL),
85 failed_init_(false), 85 failed_init_(false),
86 should_commit_(false), 86 should_commit_(false),
87 next_request_handle_(1),
88 main_loop_(MessageLoop::current()) { 87 main_loop_(MessageLoop::current()) {
89 // WebDataService requires DB thread if instantiated. 88 // WebDataService requires DB thread if instantiated.
90 // Set WebDataServiceFactory::GetInstance()->SetTestingFactory(&profile, NULL) 89 // Set WebDataServiceFactory::GetInstance()->SetTestingFactory(&profile, NULL)
91 // if you do not want to instantiate WebDataService in your test. 90 // if you do not want to instantiate WebDataService in your test.
92 DCHECK(BrowserThread::IsWellKnownThread(BrowserThread::DB)); 91 DCHECK(BrowserThread::IsWellKnownThread(BrowserThread::DB));
92
93 request_manager_.reset(new WebDataRequestManager());
93 } 94 }
94 95
95 // static 96 // static
96 void WebDataService::NotifyOfMultipleAutofillChanges( 97 void WebDataService::NotifyOfMultipleAutofillChanges(
97 WebDataService* web_data_service) { 98 WebDataService* web_data_service) {
98 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 99 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
99 100
100 if (!web_data_service) 101 if (!web_data_service)
101 return; 102 return;
102 103
(...skipping 17 matching lines...) Expand all
120 121
121 bool WebDataService::IsRunning() const { 122 bool WebDataService::IsRunning() const {
122 return is_running_; 123 return is_running_;
123 } 124 }
124 125
125 void WebDataService::UnloadDatabase() { 126 void WebDataService::UnloadDatabase() {
126 ScheduleTask(FROM_HERE, Bind(&WebDataService::ShutdownDatabase, this)); 127 ScheduleTask(FROM_HERE, Bind(&WebDataService::ShutdownDatabase, this));
127 } 128 }
128 129
129 void WebDataService::CancelRequest(Handle h) { 130 void WebDataService::CancelRequest(Handle h) {
130 base::AutoLock l(pending_lock_); 131 request_manager_->CancelRequest(h);
131 RequestMap::iterator i = pending_requests_.find(h);
132 if (i == pending_requests_.end()) {
133 NOTREACHED() << "Canceling a nonexistent web data service request";
134 return;
135 }
136 i->second->Cancel();
137 } 132 }
138 133
139 content::NotificationSource WebDataService::GetNotificationSource() { 134 content::NotificationSource WebDataService::GetNotificationSource() {
140 return content::Source<WebDataService>(this); 135 return content::Source<WebDataService>(this);
141 } 136 }
142 137
143 bool WebDataService::IsDatabaseLoaded() { 138 bool WebDataService::IsDatabaseLoaded() {
144 return db_ != NULL; 139 return db_ != NULL;
145 } 140 }
146 141
147 WebDatabase* WebDataService::GetDatabase() { 142 WebDatabase* WebDataService::GetDatabase() {
148 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 143 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
149 return db_; 144 return db_;
150 } 145 }
151 146
152 ////////////////////////////////////////////////////////////////////////////// 147 //////////////////////////////////////////////////////////////////////////////
153 // 148 //
154 // Keywords. 149 // Keywords.
155 // 150 //
156 ////////////////////////////////////////////////////////////////////////////// 151 //////////////////////////////////////////////////////////////////////////////
157 152
158 void WebDataService::AddKeyword(const TemplateURLData& data) { 153 void WebDataService::AddKeyword(const TemplateURLData& data) {
159 GenericRequest<TemplateURLData>* request = 154 GenericRequest<TemplateURLData>* request =
160 new GenericRequest<TemplateURLData>(this, GetNextRequestHandle(), NULL, 155 new GenericRequest<TemplateURLData>(
161 data); 156 this, NULL, request_manager_.get(), data);
162 RegisterRequest(request);
163 ScheduleTask(FROM_HERE, Bind(&WebDataService::AddKeywordImpl, this, request)); 157 ScheduleTask(FROM_HERE, Bind(&WebDataService::AddKeywordImpl, this, request));
164 } 158 }
165 159
166 void WebDataService::RemoveKeyword(TemplateURLID id) { 160 void WebDataService::RemoveKeyword(TemplateURLID id) {
167 GenericRequest<TemplateURLID>* request = 161 GenericRequest<TemplateURLID>* request =
168 new GenericRequest<TemplateURLID>(this, GetNextRequestHandle(), NULL, id); 162 new GenericRequest<TemplateURLID>(this, NULL, request_manager_.get(), id);
169 RegisterRequest(request);
170 ScheduleTask(FROM_HERE, 163 ScheduleTask(FROM_HERE,
171 Bind(&WebDataService::RemoveKeywordImpl, this, request)); 164 Bind(&WebDataService::RemoveKeywordImpl, this, request));
172 } 165 }
173 166
174 void WebDataService::UpdateKeyword(const TemplateURLData& data) { 167 void WebDataService::UpdateKeyword(const TemplateURLData& data) {
175 GenericRequest<TemplateURLData>* request = 168 GenericRequest<TemplateURLData>* request =
176 new GenericRequest<TemplateURLData>(this, GetNextRequestHandle(), NULL, 169 new GenericRequest<TemplateURLData>(
177 data); 170 this, NULL, request_manager_.get(), data);
178 RegisterRequest(request);
179 ScheduleTask(FROM_HERE, 171 ScheduleTask(FROM_HERE,
180 Bind(&WebDataService::UpdateKeywordImpl, this, request)); 172 Bind(&WebDataService::UpdateKeywordImpl, this, request));
181 } 173 }
182 174
183 WebDataService::Handle WebDataService::GetKeywords( 175 WebDataService::Handle WebDataService::GetKeywords(
184 WebDataServiceConsumer* consumer) { 176 WebDataServiceConsumer* consumer) {
185 WebDataRequest* request = 177 WebDataRequest* request =
186 new WebDataRequest(this, GetNextRequestHandle(), consumer); 178 new WebDataRequest(this, consumer, request_manager_.get());
187 RegisterRequest(request);
188 ScheduleTask(FROM_HERE, 179 ScheduleTask(FROM_HERE,
189 Bind(&WebDataService::GetKeywordsImpl, this, request)); 180 Bind(&WebDataService::GetKeywordsImpl, this, request));
190 return request->GetHandle(); 181 return request->GetHandle();
191 } 182 }
192 183
193 void WebDataService::SetDefaultSearchProvider(const TemplateURL* url) { 184 void WebDataService::SetDefaultSearchProvider(const TemplateURL* url) {
194 GenericRequest<TemplateURLID>* request = new GenericRequest<TemplateURLID>( 185 GenericRequest<TemplateURLID>* request = new GenericRequest<TemplateURLID>(
195 this, GetNextRequestHandle(), NULL, url ? url->id() : 0); 186 this, NULL, request_manager_.get(), url ? url->id() : 0);
196 RegisterRequest(request);
197 ScheduleTask(FROM_HERE, Bind(&WebDataService::SetDefaultSearchProviderImpl, 187 ScheduleTask(FROM_HERE, Bind(&WebDataService::SetDefaultSearchProviderImpl,
198 this, request)); 188 this, request));
199 } 189 }
200 190
201 void WebDataService::SetBuiltinKeywordVersion(int version) { 191 void WebDataService::SetBuiltinKeywordVersion(int version) {
202 GenericRequest<int>* request = 192 GenericRequest<int>* request = new GenericRequest<int>(
203 new GenericRequest<int>(this, GetNextRequestHandle(), NULL, version); 193 this, NULL, request_manager_.get(), version);
204 RegisterRequest(request);
205 ScheduleTask(FROM_HERE, Bind(&WebDataService::SetBuiltinKeywordVersionImpl, 194 ScheduleTask(FROM_HERE, Bind(&WebDataService::SetBuiltinKeywordVersionImpl,
206 this, request)); 195 this, request));
207 } 196 }
208 197
209 ////////////////////////////////////////////////////////////////////////////// 198 //////////////////////////////////////////////////////////////////////////////
210 // 199 //
211 // Web Apps 200 // Web Apps
212 // 201 //
213 ////////////////////////////////////////////////////////////////////////////// 202 //////////////////////////////////////////////////////////////////////////////
214 203
215 void WebDataService::SetWebAppImage(const GURL& app_url, 204 void WebDataService::SetWebAppImage(const GURL& app_url,
216 const SkBitmap& image) { 205 const SkBitmap& image) {
217 GenericRequest2<GURL, SkBitmap>* request = 206 GenericRequest2<GURL, SkBitmap>* request =
218 new GenericRequest2<GURL, SkBitmap>(this, GetNextRequestHandle(), 207 new GenericRequest2<GURL, SkBitmap>(
219 NULL, app_url, image); 208 this, NULL, request_manager_.get(), app_url, image);
220 RegisterRequest(request);
221 ScheduleTask(FROM_HERE, 209 ScheduleTask(FROM_HERE,
222 Bind(&WebDataService::SetWebAppImageImpl, this, request)); 210 Bind(&WebDataService::SetWebAppImageImpl, this, request));
223 } 211 }
224 212
225 void WebDataService::SetWebAppHasAllImages(const GURL& app_url, 213 void WebDataService::SetWebAppHasAllImages(const GURL& app_url,
226 bool has_all_images) { 214 bool has_all_images) {
227 GenericRequest2<GURL, bool>* request = 215 GenericRequest2<GURL, bool>* request =
228 new GenericRequest2<GURL, bool>(this, GetNextRequestHandle(), 216 new GenericRequest2<GURL, bool>(
229 NULL, app_url, has_all_images); 217 this, NULL, request_manager_.get(), app_url, has_all_images);
230 RegisterRequest(request);
231 ScheduleTask(FROM_HERE, 218 ScheduleTask(FROM_HERE,
232 Bind(&WebDataService::SetWebAppHasAllImagesImpl, this, request)); 219 Bind(&WebDataService::SetWebAppHasAllImagesImpl, this, request));
233 } 220 }
234 221
235 void WebDataService::RemoveWebApp(const GURL& app_url) { 222 void WebDataService::RemoveWebApp(const GURL& app_url) {
236 GenericRequest<GURL>* request = 223 GenericRequest<GURL>* request =
237 new GenericRequest<GURL>(this, GetNextRequestHandle(), NULL, app_url); 224 new GenericRequest<GURL>(this, NULL, request_manager_.get(), app_url);
238 RegisterRequest(request);
239 ScheduleTask(FROM_HERE, 225 ScheduleTask(FROM_HERE,
240 Bind(&WebDataService::RemoveWebAppImpl, this, request)); 226 Bind(&WebDataService::RemoveWebAppImpl, this, request));
241 } 227 }
242 228
243 WebDataService::Handle WebDataService::GetWebAppImages( 229 WebDataService::Handle WebDataService::GetWebAppImages(
244 const GURL& app_url, 230 const GURL& app_url,
245 WebDataServiceConsumer* consumer) { 231 WebDataServiceConsumer* consumer) {
246 GenericRequest<GURL>* request = 232 GenericRequest<GURL>* request =
247 new GenericRequest<GURL>(this, GetNextRequestHandle(), consumer, app_url); 233 new GenericRequest<GURL>(this, consumer, request_manager_.get(), app_url);
248 RegisterRequest(request);
249 ScheduleTask(FROM_HERE, 234 ScheduleTask(FROM_HERE,
250 Bind(&WebDataService::GetWebAppImagesImpl, this, request)); 235 Bind(&WebDataService::GetWebAppImagesImpl, this, request));
251 return request->GetHandle(); 236 return request->GetHandle();
252 } 237 }
253 238
254 ////////////////////////////////////////////////////////////////////////////// 239 //////////////////////////////////////////////////////////////////////////////
255 // 240 //
256 // Web Intents. 241 // Web Intents.
257 // 242 //
258 ////////////////////////////////////////////////////////////////////////////// 243 //////////////////////////////////////////////////////////////////////////////
259 244
260 void WebDataService::AddWebIntentService(const WebIntentServiceData& service) { 245 void WebDataService::AddWebIntentService(const WebIntentServiceData& service) {
261 GenericRequest<WebIntentServiceData>* request = 246 GenericRequest<WebIntentServiceData>* request =
262 new GenericRequest<WebIntentServiceData>( 247 new GenericRequest<WebIntentServiceData>(
263 this, GetNextRequestHandle(), NULL, service); 248 this, NULL, request_manager_.get(), service);
264 RegisterRequest(request);
265 ScheduleTask(FROM_HERE, 249 ScheduleTask(FROM_HERE,
266 Bind(&WebDataService::AddWebIntentServiceImpl, this, request)); 250 Bind(&WebDataService::AddWebIntentServiceImpl, this, request));
267 } 251 }
268 252
269 void WebDataService::RemoveWebIntentService( 253 void WebDataService::RemoveWebIntentService(
270 const WebIntentServiceData& service) { 254 const WebIntentServiceData& service) {
271 GenericRequest<WebIntentServiceData>* request = 255 GenericRequest<WebIntentServiceData>* request =
272 new GenericRequest<WebIntentServiceData>( 256 new GenericRequest<WebIntentServiceData>(
273 this, GetNextRequestHandle(), NULL, service); 257 this, NULL, request_manager_.get(), service);
274 RegisterRequest(request);
275 ScheduleTask(FROM_HERE, Bind(&WebDataService::RemoveWebIntentServiceImpl, 258 ScheduleTask(FROM_HERE, Bind(&WebDataService::RemoveWebIntentServiceImpl,
276 this, request)); 259 this, request));
277 } 260 }
278 261
279 WebDataService::Handle WebDataService::GetWebIntentServicesForAction( 262 WebDataService::Handle WebDataService::GetWebIntentServicesForAction(
280 const string16& action, 263 const string16& action,
281 WebDataServiceConsumer* consumer) { 264 WebDataServiceConsumer* consumer) {
282 DCHECK(consumer); 265 DCHECK(consumer);
283 GenericRequest<string16>* request = new GenericRequest<string16>( 266 GenericRequest<string16>* request =
284 this, GetNextRequestHandle(), consumer, action); 267 new GenericRequest<string16>(
285 RegisterRequest(request); 268 this, consumer, request_manager_.get(), action);
286 ScheduleTask(FROM_HERE, 269 ScheduleTask(FROM_HERE,
287 Bind(&WebDataService::GetWebIntentServicesImpl, this, request)); 270 Bind(&WebDataService::GetWebIntentServicesImpl, this, request));
288 return request->GetHandle(); 271 return request->GetHandle();
289 } 272 }
290 273
291 WebDataService::Handle WebDataService::GetWebIntentServicesForURL( 274 WebDataService::Handle WebDataService::GetWebIntentServicesForURL(
292 const string16& service_url, 275 const string16& service_url,
293 WebDataServiceConsumer* consumer) { 276 WebDataServiceConsumer* consumer) {
294 DCHECK(consumer); 277 DCHECK(consumer);
295 GenericRequest<string16>* request = new GenericRequest<string16>( 278 GenericRequest<string16>* request =
296 this, GetNextRequestHandle(), consumer, service_url); 279 new GenericRequest<string16>(
297 RegisterRequest(request); 280 this, consumer, request_manager_.get(), service_url);
298 ScheduleTask(FROM_HERE, Bind(&WebDataService::GetWebIntentServicesForURLImpl, 281 ScheduleTask(FROM_HERE, Bind(&WebDataService::GetWebIntentServicesForURLImpl,
299 this, request)); 282 this, request));
300 return request->GetHandle(); 283 return request->GetHandle();
301 } 284 }
302 285
303 286
304 WebDataService::Handle WebDataService::GetAllWebIntentServices( 287 WebDataService::Handle WebDataService::GetAllWebIntentServices(
305 WebDataServiceConsumer* consumer) { 288 WebDataServiceConsumer* consumer) {
306 DCHECK(consumer); 289 DCHECK(consumer);
307 GenericRequest<std::string>* request = new GenericRequest<std::string>( 290 GenericRequest<std::string>* request =
308 this, GetNextRequestHandle(), consumer, std::string()); 291 new GenericRequest<std::string>(
309 RegisterRequest(request); 292 this, consumer, request_manager_.get(), std::string());
310 ScheduleTask(FROM_HERE, Bind(&WebDataService::GetAllWebIntentServicesImpl, 293 ScheduleTask(FROM_HERE, Bind(&WebDataService::GetAllWebIntentServicesImpl,
311 this, request)); 294 this, request));
312 return request->GetHandle(); 295 return request->GetHandle();
313 } 296 }
314 297
315 void WebDataService::AddDefaultWebIntentService( 298 void WebDataService::AddDefaultWebIntentService(
316 const DefaultWebIntentService& service) { 299 const DefaultWebIntentService& service) {
317 GenericRequest<DefaultWebIntentService>* request = 300 GenericRequest<DefaultWebIntentService>* request =
318 new GenericRequest<DefaultWebIntentService>( 301 new GenericRequest<DefaultWebIntentService>(
319 this, GetNextRequestHandle(), NULL, service); 302 this, NULL, request_manager_.get(), service);
320 RegisterRequest(request);
321 ScheduleTask(FROM_HERE, 303 ScheduleTask(FROM_HERE,
322 Bind(&WebDataService::AddDefaultWebIntentServiceImpl, this, 304 Bind(&WebDataService::AddDefaultWebIntentServiceImpl, this,
323 request)); 305 request));
324 } 306 }
325 307
326 void WebDataService::RemoveDefaultWebIntentService( 308 void WebDataService::RemoveDefaultWebIntentService(
327 const DefaultWebIntentService& service) { 309 const DefaultWebIntentService& service) {
328 GenericRequest<DefaultWebIntentService>* request = 310 GenericRequest<DefaultWebIntentService>* request =
329 new GenericRequest<DefaultWebIntentService>( 311 new GenericRequest<DefaultWebIntentService>(
330 this, GetNextRequestHandle(), NULL, service); 312 this, NULL, request_manager_.get(), service);
331 RegisterRequest(request);
332 ScheduleTask(FROM_HERE, 313 ScheduleTask(FROM_HERE,
333 Bind(&WebDataService::RemoveDefaultWebIntentServiceImpl, this, 314 Bind(&WebDataService::RemoveDefaultWebIntentServiceImpl, this,
334 request)); 315 request));
335 } 316 }
336 317
337 void WebDataService::RemoveWebIntentServiceDefaults( 318 void WebDataService::RemoveWebIntentServiceDefaults(
338 const GURL& service_url) { 319 const GURL& service_url) {
339 GenericRequest<GURL>* request = 320 GenericRequest<GURL>* request =
340 new GenericRequest<GURL>( 321 new GenericRequest<GURL>(this, NULL, request_manager_.get(), service_url);
341 this, GetNextRequestHandle(), NULL, service_url);
342 RegisterRequest(request);
343 ScheduleTask( 322 ScheduleTask(
344 FROM_HERE, 323 FROM_HERE,
345 Bind(&WebDataService::RemoveWebIntentServiceDefaultsImpl, this, request)); 324 Bind(&WebDataService::RemoveWebIntentServiceDefaultsImpl, this, request));
346 } 325 }
347 326
348 WebDataService::Handle WebDataService::GetDefaultWebIntentServicesForAction( 327 WebDataService::Handle WebDataService::GetDefaultWebIntentServicesForAction(
349 const string16& action, 328 const string16& action,
350 WebDataServiceConsumer* consumer) { 329 WebDataServiceConsumer* consumer) {
351 DCHECK(consumer); 330 DCHECK(consumer);
352 GenericRequest<string16>* request = new GenericRequest<string16>( 331 GenericRequest<string16>* request = new GenericRequest<string16>(
353 this, GetNextRequestHandle(), consumer, action); 332 this, consumer, request_manager_.get(), action);
354 RegisterRequest(request);
355 ScheduleTask(FROM_HERE, 333 ScheduleTask(FROM_HERE,
356 Bind(&WebDataService::GetDefaultWebIntentServicesForActionImpl, 334 Bind(&WebDataService::GetDefaultWebIntentServicesForActionImpl,
357 this, request)); 335 this, request));
358 return request->GetHandle(); 336 return request->GetHandle();
359 } 337 }
360 338
361 WebDataService::Handle WebDataService::GetAllDefaultWebIntentServices( 339 WebDataService::Handle WebDataService::GetAllDefaultWebIntentServices(
362 WebDataServiceConsumer* consumer) { 340 WebDataServiceConsumer* consumer) {
363 DCHECK(consumer); 341 DCHECK(consumer);
364 GenericRequest<std::string>* request = new GenericRequest<std::string>( 342 GenericRequest<std::string>* request = new GenericRequest<std::string>(
365 this, GetNextRequestHandle(), consumer, std::string()); 343 this, consumer, request_manager_.get(), std::string());
366 RegisterRequest(request);
367 ScheduleTask(FROM_HERE, 344 ScheduleTask(FROM_HERE,
368 Bind(&WebDataService::GetAllDefaultWebIntentServicesImpl, 345 Bind(&WebDataService::GetAllDefaultWebIntentServicesImpl,
369 this, request)); 346 this, request));
370 return request->GetHandle(); 347 return request->GetHandle();
371 } 348 }
372 349
373 //////////////////////////////////////////////////////////////////////////////// 350 ////////////////////////////////////////////////////////////////////////////////
374 // 351 //
375 // Token Service 352 // Token Service
376 // 353 //
377 //////////////////////////////////////////////////////////////////////////////// 354 ////////////////////////////////////////////////////////////////////////////////
378 355
379 void WebDataService::SetTokenForService(const std::string& service, 356 void WebDataService::SetTokenForService(const std::string& service,
380 const std::string& token) { 357 const std::string& token) {
381 GenericRequest2<std::string, std::string>* request = 358 GenericRequest2<std::string, std::string>* request =
382 new GenericRequest2<std::string, std::string>( 359 new GenericRequest2<std::string, std::string>(
383 this, GetNextRequestHandle(), NULL, service, token); 360 this, NULL, request_manager_.get(), service, token);
384 RegisterRequest(request);
385 ScheduleTask(FROM_HERE, 361 ScheduleTask(FROM_HERE,
386 Bind(&WebDataService::SetTokenForServiceImpl, this, request)); 362 Bind(&WebDataService::SetTokenForServiceImpl, this, request));
387 } 363 }
388 364
389 void WebDataService::RemoveAllTokens() { 365 void WebDataService::RemoveAllTokens() {
390 GenericRequest<std::string>* request = 366 GenericRequest<std::string>* request =
391 new GenericRequest<std::string>( 367 new GenericRequest<std::string>(
392 this, GetNextRequestHandle(), NULL, std::string()); 368 this, NULL, request_manager_.get(), std::string());
393 RegisterRequest(request);
394 ScheduleTask(FROM_HERE, 369 ScheduleTask(FROM_HERE,
395 Bind(&WebDataService::RemoveAllTokensImpl, this, request)); 370 Bind(&WebDataService::RemoveAllTokensImpl, this, request));
396 } 371 }
397 372
398 // Null on failure. Success is WDResult<std::string> 373 // Null on failure. Success is WDResult<std::string>
399 WebDataService::Handle WebDataService::GetAllTokens( 374 WebDataService::Handle WebDataService::GetAllTokens(
400 WebDataServiceConsumer* consumer) { 375 WebDataServiceConsumer* consumer) {
401 376
402 GenericRequest<std::string>* request = 377 GenericRequest<std::string>* request =
403 new GenericRequest<std::string>( 378 new GenericRequest<std::string>(
404 this, GetNextRequestHandle(), consumer, std::string()); 379 this, consumer, request_manager_.get(), std::string());
405 RegisterRequest(request);
406 ScheduleTask(FROM_HERE, 380 ScheduleTask(FROM_HERE,
407 Bind(&WebDataService::GetAllTokensImpl, this, request)); 381 Bind(&WebDataService::GetAllTokensImpl, this, request));
408 return request->GetHandle(); 382 return request->GetHandle();
409 } 383 }
410 384
411 //////////////////////////////////////////////////////////////////////////////// 385 ////////////////////////////////////////////////////////////////////////////////
412 // 386 //
413 // Autofill. 387 // Autofill.
414 // 388 //
415 //////////////////////////////////////////////////////////////////////////////// 389 ////////////////////////////////////////////////////////////////////////////////
416 390
417 void WebDataService::AddFormFields( 391 void WebDataService::AddFormFields(
418 const std::vector<FormFieldData>& fields) { 392 const std::vector<FormFieldData>& fields) {
419 GenericRequest<std::vector<FormFieldData> >* request = 393 GenericRequest<std::vector<FormFieldData> >* request =
420 new GenericRequest<std::vector<FormFieldData> >( 394 new GenericRequest<std::vector<FormFieldData> >(
421 this, GetNextRequestHandle(), NULL, fields); 395 this, NULL, request_manager_.get(), fields);
422 RegisterRequest(request);
423 ScheduleTask(FROM_HERE, 396 ScheduleTask(FROM_HERE,
424 Bind(&WebDataService::AddFormElementsImpl, this, request)); 397 Bind(&WebDataService::AddFormElementsImpl, this, request));
425 } 398 }
426 399
427 WebDataService::Handle WebDataService::GetFormValuesForElementName( 400 WebDataService::Handle WebDataService::GetFormValuesForElementName(
428 const string16& name, const string16& prefix, int limit, 401 const string16& name, const string16& prefix, int limit,
429 WebDataServiceConsumer* consumer) { 402 WebDataServiceConsumer* consumer) {
430 WebDataRequest* request = 403 WebDataRequest* request =
431 new WebDataRequest(this, GetNextRequestHandle(), consumer); 404 new WebDataRequest(this, consumer, request_manager_.get());
432 RegisterRequest(request);
433 ScheduleTask(FROM_HERE, 405 ScheduleTask(FROM_HERE,
434 Bind(&WebDataService::GetFormValuesForElementNameImpl, 406 Bind(&WebDataService::GetFormValuesForElementNameImpl,
435 this, request, name, prefix, limit)); 407 this, request, name, prefix, limit));
436 return request->GetHandle(); 408 return request->GetHandle();
437 } 409 }
438 410
439 void WebDataService::RemoveFormElementsAddedBetween(const Time& delete_begin, 411 void WebDataService::RemoveFormElementsAddedBetween(const Time& delete_begin,
440 const Time& delete_end) { 412 const Time& delete_end) {
441 GenericRequest2<Time, Time>* request = 413 GenericRequest2<Time, Time>* request =
442 new GenericRequest2<Time, Time>(this, 414 new GenericRequest2<Time, Time>(
443 GetNextRequestHandle(), 415 this, NULL, request_manager_.get(), delete_begin, delete_end);
444 NULL,
445 delete_begin,
446 delete_end);
447 RegisterRequest(request);
448 ScheduleTask(FROM_HERE, 416 ScheduleTask(FROM_HERE,
449 Bind(&WebDataService::RemoveFormElementsAddedBetweenImpl, 417 Bind(&WebDataService::RemoveFormElementsAddedBetweenImpl,
450 this, request)); 418 this, request));
451 } 419 }
452 420
453 void WebDataService::RemoveExpiredFormElements() { 421 void WebDataService::RemoveExpiredFormElements() {
454 WebDataRequest* request = 422 WebDataRequest* request =
455 new WebDataRequest(this, GetNextRequestHandle(), NULL); 423 new WebDataRequest(this, NULL, request_manager_.get());
456 RegisterRequest(request);
457 ScheduleTask(FROM_HERE, 424 ScheduleTask(FROM_HERE,
458 Bind(&WebDataService::RemoveExpiredFormElementsImpl, 425 Bind(&WebDataService::RemoveExpiredFormElementsImpl,
459 this, request)); 426 this, request));
460 } 427 }
461 428
462 void WebDataService::RemoveFormValueForElementName( 429 void WebDataService::RemoveFormValueForElementName(
463 const string16& name, const string16& value) { 430 const string16& name, const string16& value) {
464 GenericRequest2<string16, string16>* request = 431 GenericRequest2<string16, string16>* request =
465 new GenericRequest2<string16, string16>(this, 432 new GenericRequest2<string16, string16>(
466 GetNextRequestHandle(), 433 this, NULL, request_manager_.get(), name, value);
467 NULL,
468 name, value);
469 RegisterRequest(request);
470 ScheduleTask(FROM_HERE, 434 ScheduleTask(FROM_HERE,
471 Bind(&WebDataService::RemoveFormValueForElementNameImpl, 435 Bind(&WebDataService::RemoveFormValueForElementNameImpl,
472 this, request)); 436 this, request));
473 } 437 }
474 438
475 void WebDataService::AddAutofillProfile(const AutofillProfile& profile) { 439 void WebDataService::AddAutofillProfile(const AutofillProfile& profile) {
476 GenericRequest<AutofillProfile>* request = 440 GenericRequest<AutofillProfile>* request =
477 new GenericRequest<AutofillProfile>( 441 new GenericRequest<AutofillProfile>(
478 this, GetNextRequestHandle(), NULL, profile); 442 this, NULL, request_manager_.get(), profile);
479 RegisterRequest(request);
480 ScheduleTask(FROM_HERE, 443 ScheduleTask(FROM_HERE,
481 Bind(&WebDataService::AddAutofillProfileImpl, this, request)); 444 Bind(&WebDataService::AddAutofillProfileImpl, this, request));
482 } 445 }
483 446
484 void WebDataService::UpdateAutofillProfile(const AutofillProfile& profile) { 447 void WebDataService::UpdateAutofillProfile(const AutofillProfile& profile) {
485 GenericRequest<AutofillProfile>* request = 448 GenericRequest<AutofillProfile>* request =
486 new GenericRequest<AutofillProfile>( 449 new GenericRequest<AutofillProfile>(
487 this, GetNextRequestHandle(), NULL, profile); 450 this, NULL, request_manager_.get(), profile);
488 RegisterRequest(request);
489 ScheduleTask(FROM_HERE, 451 ScheduleTask(FROM_HERE,
490 Bind(&WebDataService::UpdateAutofillProfileImpl, this, request)); 452 Bind(&WebDataService::UpdateAutofillProfileImpl, this, request));
491 } 453 }
492 454
493 void WebDataService::RemoveAutofillProfile(const std::string& guid) { 455 void WebDataService::RemoveAutofillProfile(const std::string& guid) {
494 GenericRequest<std::string>* request = 456 GenericRequest<std::string>* request =
495 new GenericRequest<std::string>( 457 new GenericRequest<std::string>(this, NULL, request_manager_.get(), guid);
496 this, GetNextRequestHandle(), NULL, guid);
497 RegisterRequest(request);
498 ScheduleTask(FROM_HERE, 458 ScheduleTask(FROM_HERE,
499 Bind(&WebDataService::RemoveAutofillProfileImpl, this, request)); 459 Bind(&WebDataService::RemoveAutofillProfileImpl, this, request));
500 } 460 }
501 461
502 WebDataService::Handle WebDataService::GetAutofillProfiles( 462 WebDataService::Handle WebDataService::GetAutofillProfiles(
503 WebDataServiceConsumer* consumer) { 463 WebDataServiceConsumer* consumer) {
504 WebDataRequest* request = 464 WebDataRequest* request =
505 new WebDataRequest(this, GetNextRequestHandle(), consumer); 465 new WebDataRequest(this, consumer, request_manager_.get());
506 RegisterRequest(request);
507 ScheduleTask(FROM_HERE, 466 ScheduleTask(FROM_HERE,
508 Bind(&WebDataService::GetAutofillProfilesImpl, this, request)); 467 Bind(&WebDataService::GetAutofillProfilesImpl, this, request));
509 return request->GetHandle(); 468 return request->GetHandle();
510 } 469 }
511 470
512 void WebDataService::EmptyMigrationTrash(bool notify_sync) { 471 void WebDataService::EmptyMigrationTrash(bool notify_sync) {
513 GenericRequest<bool>* request = 472 GenericRequest<bool>* request =
514 new GenericRequest<bool>( 473 new GenericRequest<bool>(this, NULL, request_manager_.get(), notify_sync);
515 this, GetNextRequestHandle(), NULL, notify_sync);
516 RegisterRequest(request);
517 ScheduleTask(FROM_HERE, 474 ScheduleTask(FROM_HERE,
518 Bind(&WebDataService::EmptyMigrationTrashImpl, this, request)); 475 Bind(&WebDataService::EmptyMigrationTrashImpl, this, request));
519 } 476 }
520 477
521 void WebDataService::AddCreditCard(const CreditCard& credit_card) { 478 void WebDataService::AddCreditCard(const CreditCard& credit_card) {
522 GenericRequest<CreditCard>* request = 479 GenericRequest<CreditCard>* request =
523 new GenericRequest<CreditCard>( 480 new GenericRequest<CreditCard>(
524 this, GetNextRequestHandle(), NULL, credit_card); 481 this, NULL, request_manager_.get(), credit_card);
525 RegisterRequest(request);
526 ScheduleTask(FROM_HERE, 482 ScheduleTask(FROM_HERE,
527 Bind(&WebDataService::AddCreditCardImpl, this, request)); 483 Bind(&WebDataService::AddCreditCardImpl, this, request));
528 } 484 }
529 485
530 void WebDataService::UpdateCreditCard(const CreditCard& credit_card) { 486 void WebDataService::UpdateCreditCard(const CreditCard& credit_card) {
531 GenericRequest<CreditCard>* request = 487 GenericRequest<CreditCard>* request =
532 new GenericRequest<CreditCard>( 488 new GenericRequest<CreditCard>(
533 this, GetNextRequestHandle(), NULL, credit_card); 489 this, NULL, request_manager_.get(), credit_card);
534 RegisterRequest(request);
535 ScheduleTask(FROM_HERE, 490 ScheduleTask(FROM_HERE,
536 Bind(&WebDataService::UpdateCreditCardImpl, this, request)); 491 Bind(&WebDataService::UpdateCreditCardImpl, this, request));
537 } 492 }
538 493
539 void WebDataService::RemoveCreditCard(const std::string& guid) { 494 void WebDataService::RemoveCreditCard(const std::string& guid) {
540 GenericRequest<std::string>* request = 495 GenericRequest<std::string>* request =
541 new GenericRequest<std::string>( 496 new GenericRequest<std::string>(this, NULL, request_manager_.get(), guid);
542 this, GetNextRequestHandle(), NULL, guid);
543 RegisterRequest(request);
544 ScheduleTask(FROM_HERE, 497 ScheduleTask(FROM_HERE,
545 Bind(&WebDataService::RemoveCreditCardImpl, this, request)); 498 Bind(&WebDataService::RemoveCreditCardImpl, this, request));
546 } 499 }
547 500
548 WebDataService::Handle WebDataService::GetCreditCards( 501 WebDataService::Handle WebDataService::GetCreditCards(
549 WebDataServiceConsumer* consumer) { 502 WebDataServiceConsumer* consumer) {
550 WebDataRequest* request = 503 WebDataRequest* request =
551 new WebDataRequest(this, GetNextRequestHandle(), consumer); 504 new WebDataRequest(this, consumer, request_manager_.get());
552 RegisterRequest(request);
553 ScheduleTask(FROM_HERE, 505 ScheduleTask(FROM_HERE,
554 Bind(&WebDataService::GetCreditCardsImpl, this, request)); 506 Bind(&WebDataService::GetCreditCardsImpl, this, request));
555 return request->GetHandle(); 507 return request->GetHandle();
556 } 508 }
557 509
558 void WebDataService::RemoveAutofillProfilesAndCreditCardsModifiedBetween( 510 void WebDataService::RemoveAutofillProfilesAndCreditCardsModifiedBetween(
559 const Time& delete_begin, 511 const Time& delete_begin,
560 const Time& delete_end) { 512 const Time& delete_end) {
561 GenericRequest2<Time, Time>* request = 513 GenericRequest2<Time, Time>* request =
562 new GenericRequest2<Time, Time>(this, 514 new GenericRequest2<Time, Time>(
563 GetNextRequestHandle(), 515 this, NULL, request_manager_.get(), delete_begin, delete_end);
564 NULL,
565 delete_begin,
566 delete_end);
567 RegisterRequest(request);
568 ScheduleTask(FROM_HERE, Bind( 516 ScheduleTask(FROM_HERE, Bind(
569 &WebDataService::RemoveAutofillProfilesAndCreditCardsModifiedBetweenImpl, 517 &WebDataService::RemoveAutofillProfilesAndCreditCardsModifiedBetweenImpl,
570 this, request)); 518 this, request));
571 } 519 }
572 520
573 WebDataService::~WebDataService() { 521 WebDataService::~WebDataService() {
574 if (is_running_ && db_) { 522 if (is_running_ && db_) {
575 DLOG_ASSERT("WebDataService dtor called without Shutdown"); 523 DLOG_ASSERT("WebDataService dtor called without Shutdown");
576 NOTREACHED(); 524 NOTREACHED();
577 } 525 }
(...skipping 12 matching lines...) Expand all
590 AutofillCountry::ApplicationLocale(); 538 AutofillCountry::ApplicationLocale();
591 539
592 ScheduleTask(FROM_HERE, 540 ScheduleTask(FROM_HERE,
593 Bind(&WebDataService::InitializeDatabaseIfNecessary, this)); 541 Bind(&WebDataService::InitializeDatabaseIfNecessary, this));
594 ScheduleTask(FROM_HERE, 542 ScheduleTask(FROM_HERE,
595 Bind(&WebDataService::InitializeSyncableServices, this)); 543 Bind(&WebDataService::InitializeSyncableServices, this));
596 return true; 544 return true;
597 } 545 }
598 546
599 void WebDataService::RequestCompleted(Handle h) { 547 void WebDataService::RequestCompleted(Handle h) {
600 pending_lock_.Acquire(); 548 request_manager_->RequestCompleted(h);
601 RequestMap::iterator i = pending_requests_.find(h);
602 if (i == pending_requests_.end()) {
603 NOTREACHED() << "Request completed called for an unknown request";
604 pending_lock_.Release();
605 return;
606 }
607
608 // Take ownership of the request object and remove it from the map.
609 scoped_ptr<WebDataRequest> request(i->second);
610 pending_requests_.erase(i);
611 pending_lock_.Release();
612
613 // Notify the consumer if needed.
614 WebDataServiceConsumer* consumer = NULL;
615 if (!request->IsCancelled(&consumer) && consumer) {
616 consumer->OnWebDataServiceRequestDone(request->GetHandle(),
617 request->GetResult());
618 } else {
619 // Nobody is taken ownership of the result, either because it is cancelled
620 // or there is no consumer. Destroy results that require special handling.
621 WDTypedResult const *result = request->GetResult();
622 if (result) {
623 if (result->GetType() == AUTOFILL_PROFILES_RESULT) {
624 const WDResult<std::vector<AutofillProfile*> >* r =
625 static_cast<const WDResult<std::vector<AutofillProfile*> >*>(
626 result);
627 std::vector<AutofillProfile*> profiles = r->GetValue();
628 STLDeleteElements(&profiles);
629 } else if (result->GetType() == AUTOFILL_CREDITCARDS_RESULT) {
630 const WDResult<std::vector<CreditCard*> >* r =
631 static_cast<const WDResult<std::vector<CreditCard*> >*>(result);
632
633 std::vector<CreditCard*> credit_cards = r->GetValue();
634 STLDeleteElements(&credit_cards);
635 }
636 }
637 }
638 }
639
640 void WebDataService::RegisterRequest(WebDataRequest* request) {
641 base::AutoLock l(pending_lock_);
642 pending_requests_[request->GetHandle()] = request;
643 } 549 }
644 550
645 //////////////////////////////////////////////////////////////////////////////// 551 ////////////////////////////////////////////////////////////////////////////////
646 // 552 //
647 // The following methods are executed in Chrome_WebDataThread. 553 // The following methods are executed in Chrome_WebDataThread.
648 // 554 //
649 //////////////////////////////////////////////////////////////////////////////// 555 ////////////////////////////////////////////////////////////////////////////////
650 556
651 void WebDataService::DBInitFailed(sql::InitStatus init_status) { 557 void WebDataService::DBInitFailed(sql::InitStatus init_status) {
652 ShowProfileErrorDialog( 558 ShowProfileErrorDialog(
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 NOTREACHED() << "Task scheduled after Shutdown()"; 645 NOTREACHED() << "Task scheduled after Shutdown()";
740 } 646 }
741 647
742 void WebDataService::ScheduleCommit() { 648 void WebDataService::ScheduleCommit() {
743 if (should_commit_ == false) { 649 if (should_commit_ == false) {
744 should_commit_ = true; 650 should_commit_ = true;
745 ScheduleTask(FROM_HERE, Bind(&WebDataService::Commit, this)); 651 ScheduleTask(FROM_HERE, Bind(&WebDataService::Commit, this));
746 } 652 }
747 } 653 }
748 654
749 int WebDataService::GetNextRequestHandle() {
750 base::AutoLock l(pending_lock_);
751 return ++next_request_handle_;
752 }
753
754 //////////////////////////////////////////////////////////////////////////////// 655 ////////////////////////////////////////////////////////////////////////////////
755 // 656 //
756 // Keywords implementation. 657 // Keywords implementation.
757 // 658 //
758 //////////////////////////////////////////////////////////////////////////////// 659 ////////////////////////////////////////////////////////////////////////////////
759 660
760 void WebDataService::AddKeywordImpl(GenericRequest<TemplateURLData>* request) { 661 void WebDataService::AddKeywordImpl(GenericRequest<TemplateURLData>* request) {
761 InitializeDatabaseIfNecessary(); 662 InitializeDatabaseIfNecessary();
762 if (db_ && !request->IsCancelled(NULL)) { 663 if (db_ && !request->IsCancelled()) {
763 db_->GetKeywordTable()->AddKeyword(request->arg()); 664 db_->GetKeywordTable()->AddKeyword(request->arg());
764 ScheduleCommit(); 665 ScheduleCommit();
765 } 666 }
766 request->RequestComplete(); 667 request->RequestComplete();
767 } 668 }
768 669
769 void WebDataService::RemoveKeywordImpl(GenericRequest<TemplateURLID>* request) { 670 void WebDataService::RemoveKeywordImpl(GenericRequest<TemplateURLID>* request) {
770 InitializeDatabaseIfNecessary(); 671 InitializeDatabaseIfNecessary();
771 if (db_ && !request->IsCancelled(NULL)) { 672 if (db_ && !request->IsCancelled()) {
772 DCHECK(request->arg()); 673 DCHECK(request->arg());
773 db_->GetKeywordTable()->RemoveKeyword(request->arg()); 674 db_->GetKeywordTable()->RemoveKeyword(request->arg());
774 ScheduleCommit(); 675 ScheduleCommit();
775 } 676 }
776 request->RequestComplete(); 677 request->RequestComplete();
777 } 678 }
778 679
779 void WebDataService::UpdateKeywordImpl( 680 void WebDataService::UpdateKeywordImpl(
780 GenericRequest<TemplateURLData>* request) { 681 GenericRequest<TemplateURLData>* request) {
781 InitializeDatabaseIfNecessary(); 682 InitializeDatabaseIfNecessary();
782 if (db_ && !request->IsCancelled(NULL)) { 683 if (db_ && !request->IsCancelled()) {
783 if (!db_->GetKeywordTable()->UpdateKeyword(request->arg())) { 684 if (!db_->GetKeywordTable()->UpdateKeyword(request->arg())) {
784 NOTREACHED(); 685 NOTREACHED();
785 return; 686 return;
786 } 687 }
787 ScheduleCommit(); 688 ScheduleCommit();
788 } 689 }
789 request->RequestComplete(); 690 request->RequestComplete();
790 } 691 }
791 692
792 void WebDataService::GetKeywordsImpl(WebDataRequest* request) { 693 void WebDataService::GetKeywordsImpl(WebDataRequest* request) {
793 InitializeDatabaseIfNecessary(); 694 InitializeDatabaseIfNecessary();
794 if (db_ && !request->IsCancelled(NULL)) { 695 if (db_ && !request->IsCancelled()) {
795 WDKeywordsResult result; 696 WDKeywordsResult result;
796 db_->GetKeywordTable()->GetKeywords(&result.keywords); 697 db_->GetKeywordTable()->GetKeywords(&result.keywords);
797 result.default_search_provider_id = 698 result.default_search_provider_id =
798 db_->GetKeywordTable()->GetDefaultSearchProviderID(); 699 db_->GetKeywordTable()->GetDefaultSearchProviderID();
799 result.builtin_keyword_version = 700 result.builtin_keyword_version =
800 db_->GetKeywordTable()->GetBuiltinKeywordVersion(); 701 db_->GetKeywordTable()->GetBuiltinKeywordVersion();
801 request->SetResult( 702 request->SetResult(
802 new WDResult<WDKeywordsResult>(KEYWORDS_RESULT, result)); 703 new WDResult<WDKeywordsResult>(KEYWORDS_RESULT, result));
803 } 704 }
804 request->RequestComplete(); 705 request->RequestComplete();
805 } 706 }
806 707
807 void WebDataService::SetDefaultSearchProviderImpl( 708 void WebDataService::SetDefaultSearchProviderImpl(
808 GenericRequest<TemplateURLID>* request) { 709 GenericRequest<TemplateURLID>* request) {
809 InitializeDatabaseIfNecessary(); 710 InitializeDatabaseIfNecessary();
810 if (db_ && !request->IsCancelled(NULL)) { 711 if (db_ && !request->IsCancelled()) {
811 if (!db_->GetKeywordTable()->SetDefaultSearchProviderID(request->arg())) { 712 if (!db_->GetKeywordTable()->SetDefaultSearchProviderID(request->arg())) {
812 NOTREACHED(); 713 NOTREACHED();
813 return; 714 return;
814 } 715 }
815 ScheduleCommit(); 716 ScheduleCommit();
816 } 717 }
817 request->RequestComplete(); 718 request->RequestComplete();
818 } 719 }
819 720
820 void WebDataService::SetBuiltinKeywordVersionImpl( 721 void WebDataService::SetBuiltinKeywordVersionImpl(
821 GenericRequest<int>* request) { 722 GenericRequest<int>* request) {
822 InitializeDatabaseIfNecessary(); 723 InitializeDatabaseIfNecessary();
823 if (db_ && !request->IsCancelled(NULL)) { 724 if (db_ && !request->IsCancelled()) {
824 if (!db_->GetKeywordTable()->SetBuiltinKeywordVersion(request->arg())) { 725 if (!db_->GetKeywordTable()->SetBuiltinKeywordVersion(request->arg())) {
825 NOTREACHED(); 726 NOTREACHED();
826 return; 727 return;
827 } 728 }
828 ScheduleCommit(); 729 ScheduleCommit();
829 } 730 }
830 request->RequestComplete(); 731 request->RequestComplete();
831 } 732 }
832 733
833 //////////////////////////////////////////////////////////////////////////////// 734 ////////////////////////////////////////////////////////////////////////////////
834 // 735 //
835 // Web Apps implementation. 736 // Web Apps implementation.
836 // 737 //
837 //////////////////////////////////////////////////////////////////////////////// 738 ////////////////////////////////////////////////////////////////////////////////
838 739
839 void WebDataService::SetWebAppImageImpl( 740 void WebDataService::SetWebAppImageImpl(
840 GenericRequest2<GURL, SkBitmap>* request) { 741 GenericRequest2<GURL, SkBitmap>* request) {
841 InitializeDatabaseIfNecessary(); 742 InitializeDatabaseIfNecessary();
842 if (db_ && !request->IsCancelled(NULL)) { 743 if (db_ && !request->IsCancelled()) {
843 db_->GetWebAppsTable()->SetWebAppImage( 744 db_->GetWebAppsTable()->SetWebAppImage(
844 request->arg1(), request->arg2()); 745 request->arg1(), request->arg2());
845 ScheduleCommit(); 746 ScheduleCommit();
846 } 747 }
847 request->RequestComplete(); 748 request->RequestComplete();
848 } 749 }
849 750
850 void WebDataService::SetWebAppHasAllImagesImpl( 751 void WebDataService::SetWebAppHasAllImagesImpl(
851 GenericRequest2<GURL, bool>* request) { 752 GenericRequest2<GURL, bool>* request) {
852 InitializeDatabaseIfNecessary(); 753 InitializeDatabaseIfNecessary();
853 if (db_ && !request->IsCancelled(NULL)) { 754 if (db_ && !request->IsCancelled()) {
854 db_->GetWebAppsTable()->SetWebAppHasAllImages(request->arg1(), 755 db_->GetWebAppsTable()->SetWebAppHasAllImages(request->arg1(),
855 request->arg2()); 756 request->arg2());
856 ScheduleCommit(); 757 ScheduleCommit();
857 } 758 }
858 request->RequestComplete(); 759 request->RequestComplete();
859 } 760 }
860 761
861 void WebDataService::RemoveWebAppImpl(GenericRequest<GURL>* request) { 762 void WebDataService::RemoveWebAppImpl(GenericRequest<GURL>* request) {
862 InitializeDatabaseIfNecessary(); 763 InitializeDatabaseIfNecessary();
863 if (db_ && !request->IsCancelled(NULL)) { 764 if (db_ && !request->IsCancelled()) {
864 db_->GetWebAppsTable()->RemoveWebApp(request->arg()); 765 db_->GetWebAppsTable()->RemoveWebApp(request->arg());
865 ScheduleCommit(); 766 ScheduleCommit();
866 } 767 }
867 request->RequestComplete(); 768 request->RequestComplete();
868 } 769 }
869 770
870 void WebDataService::GetWebAppImagesImpl(GenericRequest<GURL>* request) { 771 void WebDataService::GetWebAppImagesImpl(GenericRequest<GURL>* request) {
871 InitializeDatabaseIfNecessary(); 772 InitializeDatabaseIfNecessary();
872 if (db_ && !request->IsCancelled(NULL)) { 773 if (db_ && !request->IsCancelled()) {
873 WDAppImagesResult result; 774 WDAppImagesResult result;
874 result.has_all_images = 775 result.has_all_images =
875 db_->GetWebAppsTable()->GetWebAppHasAllImages(request->arg()); 776 db_->GetWebAppsTable()->GetWebAppHasAllImages(request->arg());
876 db_->GetWebAppsTable()->GetWebAppImages(request->arg(), &result.images); 777 db_->GetWebAppsTable()->GetWebAppImages(request->arg(), &result.images);
877 request->SetResult( 778 request->SetResult(
878 new WDResult<WDAppImagesResult>(WEB_APP_IMAGES, result)); 779 new WDResult<WDAppImagesResult>(WEB_APP_IMAGES, result));
879 } 780 }
880 request->RequestComplete(); 781 request->RequestComplete();
881 } 782 }
882 783
883 //////////////////////////////////////////////////////////////////////////////// 784 ////////////////////////////////////////////////////////////////////////////////
884 // 785 //
885 // Web Intents implementation. 786 // Web Intents implementation.
886 // 787 //
887 //////////////////////////////////////////////////////////////////////////////// 788 ////////////////////////////////////////////////////////////////////////////////
888 789
889 void WebDataService::RemoveWebIntentServiceImpl( 790 void WebDataService::RemoveWebIntentServiceImpl(
890 GenericRequest<WebIntentServiceData>* request) { 791 GenericRequest<WebIntentServiceData>* request) {
891 InitializeDatabaseIfNecessary(); 792 InitializeDatabaseIfNecessary();
892 if (db_ && !request->IsCancelled(NULL)) { 793 if (db_ && !request->IsCancelled()) {
893 const WebIntentServiceData& service = request->arg(); 794 const WebIntentServiceData& service = request->arg();
894 db_->GetWebIntentsTable()->RemoveWebIntentService(service); 795 db_->GetWebIntentsTable()->RemoveWebIntentService(service);
895 ScheduleCommit(); 796 ScheduleCommit();
896 } 797 }
897 request->RequestComplete(); 798 request->RequestComplete();
898 } 799 }
899 800
900 void WebDataService::AddWebIntentServiceImpl( 801 void WebDataService::AddWebIntentServiceImpl(
901 GenericRequest<WebIntentServiceData>* request) { 802 GenericRequest<WebIntentServiceData>* request) {
902 InitializeDatabaseIfNecessary(); 803 InitializeDatabaseIfNecessary();
903 if (db_ && !request->IsCancelled(NULL)) { 804 if (db_ && !request->IsCancelled()) {
904 const WebIntentServiceData& service = request->arg(); 805 const WebIntentServiceData& service = request->arg();
905 db_->GetWebIntentsTable()->SetWebIntentService(service); 806 db_->GetWebIntentsTable()->SetWebIntentService(service);
906 ScheduleCommit(); 807 ScheduleCommit();
907 } 808 }
908 request->RequestComplete(); 809 request->RequestComplete();
909 } 810 }
910 811
911 812
912 void WebDataService::GetWebIntentServicesImpl( 813 void WebDataService::GetWebIntentServicesImpl(
913 GenericRequest<string16>* request) { 814 GenericRequest<string16>* request) {
914 InitializeDatabaseIfNecessary(); 815 InitializeDatabaseIfNecessary();
915 if (db_ && !request->IsCancelled(NULL)) { 816 if (db_ && !request->IsCancelled()) {
916 std::vector<WebIntentServiceData> result; 817 std::vector<WebIntentServiceData> result;
917 db_->GetWebIntentsTable()->GetWebIntentServicesForAction(request->arg(), 818 db_->GetWebIntentsTable()->GetWebIntentServicesForAction(request->arg(),
918 &result); 819 &result);
919 request->SetResult(new WDResult<std::vector<WebIntentServiceData> >( 820 request->SetResult(new WDResult<std::vector<WebIntentServiceData> >(
920 WEB_INTENTS_RESULT, result)); 821 WEB_INTENTS_RESULT, result));
921 } 822 }
922 request->RequestComplete(); 823 request->RequestComplete();
923 } 824 }
924 825
925 void WebDataService::GetWebIntentServicesForURLImpl( 826 void WebDataService::GetWebIntentServicesForURLImpl(
926 GenericRequest<string16>* request) { 827 GenericRequest<string16>* request) {
927 InitializeDatabaseIfNecessary(); 828 InitializeDatabaseIfNecessary();
928 if (db_ && !request->IsCancelled(NULL)) { 829 if (db_ && !request->IsCancelled()) {
929 std::vector<WebIntentServiceData> result; 830 std::vector<WebIntentServiceData> result;
930 db_->GetWebIntentsTable()->GetWebIntentServicesForURL( 831 db_->GetWebIntentsTable()->GetWebIntentServicesForURL(
931 request->arg(), &result); 832 request->arg(), &result);
932 request->SetResult( 833 request->SetResult(
933 new WDResult<std::vector<WebIntentServiceData> >( 834 new WDResult<std::vector<WebIntentServiceData> >(
934 WEB_INTENTS_RESULT, result)); 835 WEB_INTENTS_RESULT, result));
935 } 836 }
936 request->RequestComplete(); 837 request->RequestComplete();
937 } 838 }
938 839
939 void WebDataService::GetAllWebIntentServicesImpl( 840 void WebDataService::GetAllWebIntentServicesImpl(
940 GenericRequest<std::string>* request) { 841 GenericRequest<std::string>* request) {
941 InitializeDatabaseIfNecessary(); 842 InitializeDatabaseIfNecessary();
942 if (db_ && !request->IsCancelled(NULL)) { 843 if (db_ && !request->IsCancelled()) {
943 std::vector<WebIntentServiceData> result; 844 std::vector<WebIntentServiceData> result;
944 db_->GetWebIntentsTable()->GetAllWebIntentServices(&result); 845 db_->GetWebIntentsTable()->GetAllWebIntentServices(&result);
945 request->SetResult( 846 request->SetResult(
946 new WDResult<std::vector<WebIntentServiceData> >( 847 new WDResult<std::vector<WebIntentServiceData> >(
947 WEB_INTENTS_RESULT, result)); 848 WEB_INTENTS_RESULT, result));
948 } 849 }
949 request->RequestComplete(); 850 request->RequestComplete();
950 } 851 }
951 852
952 void WebDataService::AddDefaultWebIntentServiceImpl( 853 void WebDataService::AddDefaultWebIntentServiceImpl(
953 GenericRequest<DefaultWebIntentService>* request) { 854 GenericRequest<DefaultWebIntentService>* request) {
954 InitializeDatabaseIfNecessary(); 855 InitializeDatabaseIfNecessary();
955 if (db_ && !request->IsCancelled(NULL)) { 856 if (db_ && !request->IsCancelled()) {
956 const DefaultWebIntentService& service = request->arg(); 857 const DefaultWebIntentService& service = request->arg();
957 db_->GetWebIntentsTable()->SetDefaultService(service); 858 db_->GetWebIntentsTable()->SetDefaultService(service);
958 ScheduleCommit(); 859 ScheduleCommit();
959 } 860 }
960 request->RequestComplete(); 861 request->RequestComplete();
961 } 862 }
962 863
963 void WebDataService::RemoveDefaultWebIntentServiceImpl( 864 void WebDataService::RemoveDefaultWebIntentServiceImpl(
964 GenericRequest<DefaultWebIntentService>* request) { 865 GenericRequest<DefaultWebIntentService>* request) {
965 InitializeDatabaseIfNecessary(); 866 InitializeDatabaseIfNecessary();
966 if (db_ && !request->IsCancelled(NULL)) { 867 if (db_ && !request->IsCancelled()) {
967 const DefaultWebIntentService& service = request->arg(); 868 const DefaultWebIntentService& service = request->arg();
968 db_->GetWebIntentsTable()->RemoveDefaultService(service); 869 db_->GetWebIntentsTable()->RemoveDefaultService(service);
969 ScheduleCommit(); 870 ScheduleCommit();
970 } 871 }
971 request->RequestComplete(); 872 request->RequestComplete();
972 } 873 }
973 874
974 void WebDataService::RemoveWebIntentServiceDefaultsImpl( 875 void WebDataService::RemoveWebIntentServiceDefaultsImpl(
975 GenericRequest<GURL>* request) { 876 GenericRequest<GURL>* request) {
976 InitializeDatabaseIfNecessary(); 877 InitializeDatabaseIfNecessary();
977 if (db_ && !request->IsCancelled(NULL)) { 878 if (db_ && !request->IsCancelled()) {
978 const GURL& service_url = request->arg(); 879 const GURL& service_url = request->arg();
979 db_->GetWebIntentsTable()->RemoveServiceDefaults(service_url); 880 db_->GetWebIntentsTable()->RemoveServiceDefaults(service_url);
980 ScheduleCommit(); 881 ScheduleCommit();
981 } 882 }
982 request->RequestComplete(); 883 request->RequestComplete();
983 } 884 }
984 885
985 void WebDataService::GetDefaultWebIntentServicesForActionImpl( 886 void WebDataService::GetDefaultWebIntentServicesForActionImpl(
986 GenericRequest<string16>* request) { 887 GenericRequest<string16>* request) {
987 InitializeDatabaseIfNecessary(); 888 InitializeDatabaseIfNecessary();
988 if (db_ && !request->IsCancelled(NULL)) { 889 if (db_ && !request->IsCancelled()) {
989 std::vector<DefaultWebIntentService> result; 890 std::vector<DefaultWebIntentService> result;
990 db_->GetWebIntentsTable()->GetDefaultServices( 891 db_->GetWebIntentsTable()->GetDefaultServices(
991 request->arg(), &result); 892 request->arg(), &result);
992 request->SetResult( 893 request->SetResult(
993 new WDResult<std::vector<DefaultWebIntentService> >( 894 new WDResult<std::vector<DefaultWebIntentService> >(
994 WEB_INTENTS_DEFAULTS_RESULT, result)); 895 WEB_INTENTS_DEFAULTS_RESULT, result));
995 } 896 }
996 request->RequestComplete(); 897 request->RequestComplete();
997 } 898 }
998 899
999 void WebDataService::GetAllDefaultWebIntentServicesImpl( 900 void WebDataService::GetAllDefaultWebIntentServicesImpl(
1000 GenericRequest<std::string>* request) { 901 GenericRequest<std::string>* request) {
1001 InitializeDatabaseIfNecessary(); 902 InitializeDatabaseIfNecessary();
1002 if (db_ && !request->IsCancelled(NULL)) { 903 if (db_ && !request->IsCancelled()) {
1003 std::vector<DefaultWebIntentService> result; 904 std::vector<DefaultWebIntentService> result;
1004 db_->GetWebIntentsTable()->GetAllDefaultServices(&result); 905 db_->GetWebIntentsTable()->GetAllDefaultServices(&result);
1005 request->SetResult( 906 request->SetResult(
1006 new WDResult<std::vector<DefaultWebIntentService> >( 907 new WDResult<std::vector<DefaultWebIntentService> >(
1007 WEB_INTENTS_DEFAULTS_RESULT, result)); 908 WEB_INTENTS_DEFAULTS_RESULT, result));
1008 } 909 }
1009 request->RequestComplete(); 910 request->RequestComplete();
1010 } 911 }
1011 912
1012 //////////////////////////////////////////////////////////////////////////////// 913 ////////////////////////////////////////////////////////////////////////////////
1013 // 914 //
1014 // Token Service implementation. 915 // Token Service implementation.
1015 // 916 //
1016 //////////////////////////////////////////////////////////////////////////////// 917 ////////////////////////////////////////////////////////////////////////////////
1017 918
1018 // argument std::string is unused 919 // argument std::string is unused
1019 void WebDataService::RemoveAllTokensImpl( 920 void WebDataService::RemoveAllTokensImpl(
1020 GenericRequest<std::string>* request) { 921 GenericRequest<std::string>* request) {
1021 InitializeDatabaseIfNecessary(); 922 InitializeDatabaseIfNecessary();
1022 if (db_ && !request->IsCancelled(NULL)) { 923 if (db_ && !request->IsCancelled()) {
1023 if (db_->GetTokenServiceTable()->RemoveAllTokens()) { 924 if (db_->GetTokenServiceTable()->RemoveAllTokens()) {
1024 ScheduleCommit(); 925 ScheduleCommit();
1025 } 926 }
1026 } 927 }
1027 request->RequestComplete(); 928 request->RequestComplete();
1028 } 929 }
1029 930
1030 void WebDataService::SetTokenForServiceImpl( 931 void WebDataService::SetTokenForServiceImpl(
1031 GenericRequest2<std::string, std::string>* request) { 932 GenericRequest2<std::string, std::string>* request) {
1032 InitializeDatabaseIfNecessary(); 933 InitializeDatabaseIfNecessary();
1033 if (db_ && !request->IsCancelled(NULL)) { 934 if (db_ && !request->IsCancelled()) {
1034 if (db_->GetTokenServiceTable()->SetTokenForService( 935 if (db_->GetTokenServiceTable()->SetTokenForService(
1035 request->arg1(), request->arg2())) { 936 request->arg1(), request->arg2())) {
1036 ScheduleCommit(); 937 ScheduleCommit();
1037 } 938 }
1038 } 939 }
1039 request->RequestComplete(); 940 request->RequestComplete();
1040 } 941 }
1041 942
1042 // argument is unused 943 // argument is unused
1043 void WebDataService::GetAllTokensImpl( 944 void WebDataService::GetAllTokensImpl(
1044 GenericRequest<std::string>* request) { 945 GenericRequest<std::string>* request) {
1045 InitializeDatabaseIfNecessary(); 946 InitializeDatabaseIfNecessary();
1046 if (db_ && !request->IsCancelled(NULL)) { 947 if (db_ && !request->IsCancelled()) {
1047 std::map<std::string, std::string> map; 948 std::map<std::string, std::string> map;
1048 db_->GetTokenServiceTable()->GetAllTokens(&map); 949 db_->GetTokenServiceTable()->GetAllTokens(&map);
1049 request->SetResult( 950 request->SetResult(
1050 new WDResult<std::map<std::string, std::string> >(TOKEN_RESULT, map)); 951 new WDResult<std::map<std::string, std::string> >(TOKEN_RESULT, map));
1051 } 952 }
1052 request->RequestComplete(); 953 request->RequestComplete();
1053 } 954 }
1054 955
1055 //////////////////////////////////////////////////////////////////////////////// 956 ////////////////////////////////////////////////////////////////////////////////
1056 // 957 //
1057 // Autofill implementation. 958 // Autofill implementation.
1058 // 959 //
1059 //////////////////////////////////////////////////////////////////////////////// 960 ////////////////////////////////////////////////////////////////////////////////
1060 961
1061 void WebDataService::AddFormElementsImpl( 962 void WebDataService::AddFormElementsImpl(
1062 GenericRequest<std::vector<FormFieldData> >* request) { 963 GenericRequest<std::vector<FormFieldData> >* request) {
1063 InitializeDatabaseIfNecessary(); 964 InitializeDatabaseIfNecessary();
1064 if (db_ && !request->IsCancelled(NULL)) { 965 if (db_ && !request->IsCancelled()) {
1065 AutofillChangeList changes; 966 AutofillChangeList changes;
1066 if (!db_->GetAutofillTable()->AddFormFieldValues( 967 if (!db_->GetAutofillTable()->AddFormFieldValues(
1067 request->arg(), &changes)) { 968 request->arg(), &changes)) {
1068 NOTREACHED(); 969 NOTREACHED();
1069 return; 970 return;
1070 } 971 }
1071 request->SetResult( 972 request->SetResult(
1072 new WDResult<AutofillChangeList>(AUTOFILL_CHANGES, changes)); 973 new WDResult<AutofillChangeList>(AUTOFILL_CHANGES, changes));
1073 ScheduleCommit(); 974 ScheduleCommit();
1074 975
1075 // Post the notifications including the list of affected keys. 976 // Post the notifications including the list of affected keys.
1076 // This is sent here so that work resulting from this notification will be 977 // This is sent here so that work resulting from this notification will be
1077 // done on the DB thread, and not the UI thread. 978 // done on the DB thread, and not the UI thread.
1078 content::NotificationService::current()->Notify( 979 content::NotificationService::current()->Notify(
1079 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, 980 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED,
1080 content::Source<WebDataService>(this), 981 content::Source<WebDataService>(this),
1081 content::Details<AutofillChangeList>(&changes)); 982 content::Details<AutofillChangeList>(&changes));
1082 } 983 }
1083 984
1084 request->RequestComplete(); 985 request->RequestComplete();
1085 } 986 }
1086 987
1087 void WebDataService::GetFormValuesForElementNameImpl(WebDataRequest* request, 988 void WebDataService::GetFormValuesForElementNameImpl(WebDataRequest* request,
1088 const string16& name, const string16& prefix, int limit) { 989 const string16& name, const string16& prefix, int limit) {
1089 InitializeDatabaseIfNecessary(); 990 InitializeDatabaseIfNecessary();
1090 if (db_ && !request->IsCancelled(NULL)) { 991 if (db_ && !request->IsCancelled()) {
1091 std::vector<string16> values; 992 std::vector<string16> values;
1092 db_->GetAutofillTable()->GetFormValuesForElementName( 993 db_->GetAutofillTable()->GetFormValuesForElementName(
1093 name, prefix, &values, limit); 994 name, prefix, &values, limit);
1094 request->SetResult( 995 request->SetResult(
1095 new WDResult<std::vector<string16> >(AUTOFILL_VALUE_RESULT, values)); 996 new WDResult<std::vector<string16> >(AUTOFILL_VALUE_RESULT, values));
1096 } 997 }
1097 request->RequestComplete(); 998 request->RequestComplete();
1098 } 999 }
1099 1000
1100 void WebDataService::RemoveFormElementsAddedBetweenImpl( 1001 void WebDataService::RemoveFormElementsAddedBetweenImpl(
1101 GenericRequest2<Time, Time>* request) { 1002 GenericRequest2<Time, Time>* request) {
1102 InitializeDatabaseIfNecessary(); 1003 InitializeDatabaseIfNecessary();
1103 if (db_ && !request->IsCancelled(NULL)) { 1004 if (db_ && !request->IsCancelled()) {
1104 AutofillChangeList changes; 1005 AutofillChangeList changes;
1105 if (db_->GetAutofillTable()->RemoveFormElementsAddedBetween( 1006 if (db_->GetAutofillTable()->RemoveFormElementsAddedBetween(
1106 request->arg1(), request->arg2(), &changes)) { 1007 request->arg1(), request->arg2(), &changes)) {
1107 if (!changes.empty()) { 1008 if (!changes.empty()) {
1108 request->SetResult( 1009 request->SetResult(
1109 new WDResult<AutofillChangeList>(AUTOFILL_CHANGES, changes)); 1010 new WDResult<AutofillChangeList>(AUTOFILL_CHANGES, changes));
1110 1011
1111 // Post the notifications including the list of affected keys. 1012 // Post the notifications including the list of affected keys.
1112 // This is sent here so that work resulting from this notification 1013 // This is sent here so that work resulting from this notification
1113 // will be done on the DB thread, and not the UI thread. 1014 // will be done on the DB thread, and not the UI thread.
1114 content::NotificationService::current()->Notify( 1015 content::NotificationService::current()->Notify(
1115 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, 1016 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED,
1116 content::Source<WebDataService>(this), 1017 content::Source<WebDataService>(this),
1117 content::Details<AutofillChangeList>(&changes)); 1018 content::Details<AutofillChangeList>(&changes));
1118 } 1019 }
1119 ScheduleCommit(); 1020 ScheduleCommit();
1120 } 1021 }
1121 } 1022 }
1122 request->RequestComplete(); 1023 request->RequestComplete();
1123 } 1024 }
1124 1025
1125 void WebDataService::RemoveExpiredFormElementsImpl(WebDataRequest* request) { 1026 void WebDataService::RemoveExpiredFormElementsImpl(WebDataRequest* request) {
1126 InitializeDatabaseIfNecessary(); 1027 InitializeDatabaseIfNecessary();
1127 if (db_ && !request->IsCancelled(NULL)) { 1028 if (db_ && !request->IsCancelled()) {
1128 AutofillChangeList changes; 1029 AutofillChangeList changes;
1129 if (db_->GetAutofillTable()->RemoveExpiredFormElements(&changes)) { 1030 if (db_->GetAutofillTable()->RemoveExpiredFormElements(&changes)) {
1130 if (!changes.empty()) { 1031 if (!changes.empty()) {
1131 request->SetResult( 1032 request->SetResult(
1132 new WDResult<AutofillChangeList>(AUTOFILL_CHANGES, changes)); 1033 new WDResult<AutofillChangeList>(AUTOFILL_CHANGES, changes));
1133 1034
1134 // Post the notifications including the list of affected keys. 1035 // Post the notifications including the list of affected keys.
1135 // This is sent here so that work resulting from this notification 1036 // This is sent here so that work resulting from this notification
1136 // will be done on the DB thread, and not the UI thread. 1037 // will be done on the DB thread, and not the UI thread.
1137 content::NotificationService::current()->Notify( 1038 content::NotificationService::current()->Notify(
1138 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, 1039 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED,
1139 content::Source<WebDataService>(this), 1040 content::Source<WebDataService>(this),
1140 content::Details<AutofillChangeList>(&changes)); 1041 content::Details<AutofillChangeList>(&changes));
1141 } 1042 }
1142 ScheduleCommit(); 1043 ScheduleCommit();
1143 } 1044 }
1144 } 1045 }
1145 request->RequestComplete(); 1046 request->RequestComplete();
1146 } 1047 }
1147 1048
1148 void WebDataService::RemoveFormValueForElementNameImpl( 1049 void WebDataService::RemoveFormValueForElementNameImpl(
1149 GenericRequest2<string16, string16>* request) { 1050 GenericRequest2<string16, string16>* request) {
1150 InitializeDatabaseIfNecessary(); 1051 InitializeDatabaseIfNecessary();
1151 if (db_ && !request->IsCancelled(NULL)) { 1052 if (db_ && !request->IsCancelled()) {
1152 const string16& name = request->arg1(); 1053 const string16& name = request->arg1();
1153 const string16& value = request->arg2(); 1054 const string16& value = request->arg2();
1154 1055
1155 if (db_->GetAutofillTable()->RemoveFormElement(name, value)) { 1056 if (db_->GetAutofillTable()->RemoveFormElement(name, value)) {
1156 AutofillChangeList changes; 1057 AutofillChangeList changes;
1157 changes.push_back(AutofillChange(AutofillChange::REMOVE, 1058 changes.push_back(AutofillChange(AutofillChange::REMOVE,
1158 AutofillKey(name, value))); 1059 AutofillKey(name, value)));
1159 request->SetResult( 1060 request->SetResult(
1160 new WDResult<AutofillChangeList>(AUTOFILL_CHANGES, changes)); 1061 new WDResult<AutofillChangeList>(AUTOFILL_CHANGES, changes));
1161 ScheduleCommit(); 1062 ScheduleCommit();
1162 1063
1163 // Post the notifications including the list of affected keys. 1064 // Post the notifications including the list of affected keys.
1164 content::NotificationService::current()->Notify( 1065 content::NotificationService::current()->Notify(
1165 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, 1066 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED,
1166 content::Source<WebDataService>(this), 1067 content::Source<WebDataService>(this),
1167 content::Details<AutofillChangeList>(&changes)); 1068 content::Details<AutofillChangeList>(&changes));
1168 } 1069 }
1169 } 1070 }
1170 request->RequestComplete(); 1071 request->RequestComplete();
1171 } 1072 }
1172 1073
1173 void WebDataService::AddAutofillProfileImpl( 1074 void WebDataService::AddAutofillProfileImpl(
1174 GenericRequest<AutofillProfile>* request) { 1075 GenericRequest<AutofillProfile>* request) {
1175 InitializeDatabaseIfNecessary(); 1076 InitializeDatabaseIfNecessary();
1176 if (db_ && !request->IsCancelled(NULL)) { 1077 if (db_ && !request->IsCancelled()) {
1177 const AutofillProfile& profile = request->arg(); 1078 const AutofillProfile& profile = request->arg();
1178 if (!db_->GetAutofillTable()->AddAutofillProfile(profile)) { 1079 if (!db_->GetAutofillTable()->AddAutofillProfile(profile)) {
1179 NOTREACHED(); 1080 NOTREACHED();
1180 return; 1081 return;
1181 } 1082 }
1182 ScheduleCommit(); 1083 ScheduleCommit();
1183 1084
1184 // Send GUID-based notification. 1085 // Send GUID-based notification.
1185 AutofillProfileChange change(AutofillProfileChange::ADD, 1086 AutofillProfileChange change(AutofillProfileChange::ADD,
1186 profile.guid(), &profile); 1087 profile.guid(), &profile);
1187 content::NotificationService::current()->Notify( 1088 content::NotificationService::current()->Notify(
1188 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, 1089 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED,
1189 content::Source<WebDataService>(this), 1090 content::Source<WebDataService>(this),
1190 content::Details<AutofillProfileChange>(&change)); 1091 content::Details<AutofillProfileChange>(&change));
1191 } 1092 }
1192 request->RequestComplete(); 1093 request->RequestComplete();
1193 } 1094 }
1194 1095
1195 void WebDataService::UpdateAutofillProfileImpl( 1096 void WebDataService::UpdateAutofillProfileImpl(
1196 GenericRequest<AutofillProfile>* request) { 1097 GenericRequest<AutofillProfile>* request) {
1197 InitializeDatabaseIfNecessary(); 1098 InitializeDatabaseIfNecessary();
1198 if (db_ && !request->IsCancelled(NULL)) { 1099 if (db_ && !request->IsCancelled()) {
1199 const AutofillProfile& profile = request->arg(); 1100 const AutofillProfile& profile = request->arg();
1200 1101
1201 // Only perform the update if the profile exists. It is currently 1102 // Only perform the update if the profile exists. It is currently
1202 // valid to try to update a missing profile. We simply drop the write and 1103 // valid to try to update a missing profile. We simply drop the write and
1203 // the caller will detect this on the next refresh. 1104 // the caller will detect this on the next refresh.
1204 AutofillProfile* original_profile = NULL; 1105 AutofillProfile* original_profile = NULL;
1205 if (!db_->GetAutofillTable()->GetAutofillProfile(profile.guid(), 1106 if (!db_->GetAutofillTable()->GetAutofillProfile(profile.guid(),
1206 &original_profile)) { 1107 &original_profile)) {
1207 request->RequestComplete(); 1108 request->RequestComplete();
1208 return; 1109 return;
(...skipping 13 matching lines...) Expand all
1222 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, 1123 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED,
1223 content::Source<WebDataService>(this), 1124 content::Source<WebDataService>(this),
1224 content::Details<AutofillProfileChange>(&change)); 1125 content::Details<AutofillProfileChange>(&change));
1225 } 1126 }
1226 request->RequestComplete(); 1127 request->RequestComplete();
1227 } 1128 }
1228 1129
1229 void WebDataService::RemoveAutofillProfileImpl( 1130 void WebDataService::RemoveAutofillProfileImpl(
1230 GenericRequest<std::string>* request) { 1131 GenericRequest<std::string>* request) {
1231 InitializeDatabaseIfNecessary(); 1132 InitializeDatabaseIfNecessary();
1232 if (db_ && !request->IsCancelled(NULL)) { 1133 if (db_ && !request->IsCancelled()) {
1233 const std::string& guid = request->arg(); 1134 const std::string& guid = request->arg();
1234 1135
1235 AutofillProfile* profile = NULL; 1136 AutofillProfile* profile = NULL;
1236 if (!db_->GetAutofillTable()->GetAutofillProfile(guid, &profile)) { 1137 if (!db_->GetAutofillTable()->GetAutofillProfile(guid, &profile)) {
1237 NOTREACHED(); 1138 NOTREACHED();
1238 return; 1139 return;
1239 } 1140 }
1240 scoped_ptr<AutofillProfile> scoped_profile(profile); 1141 scoped_ptr<AutofillProfile> scoped_profile(profile);
1241 1142
1242 if (!db_->GetAutofillTable()->RemoveAutofillProfile(guid)) { 1143 if (!db_->GetAutofillTable()->RemoveAutofillProfile(guid)) {
1243 NOTREACHED(); 1144 NOTREACHED();
1244 return; 1145 return;
1245 } 1146 }
1246 ScheduleCommit(); 1147 ScheduleCommit();
1247 1148
1248 // Send GUID-based notification. 1149 // Send GUID-based notification.
1249 AutofillProfileChange change(AutofillProfileChange::REMOVE, guid, NULL); 1150 AutofillProfileChange change(AutofillProfileChange::REMOVE, guid, NULL);
1250 content::NotificationService::current()->Notify( 1151 content::NotificationService::current()->Notify(
1251 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, 1152 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED,
1252 content::Source<WebDataService>(this), 1153 content::Source<WebDataService>(this),
1253 content::Details<AutofillProfileChange>(&change)); 1154 content::Details<AutofillProfileChange>(&change));
1254 } 1155 }
1255 request->RequestComplete(); 1156 request->RequestComplete();
1256 } 1157 }
1257 1158
1258 void WebDataService::GetAutofillProfilesImpl(WebDataRequest* request) { 1159 void WebDataService::GetAutofillProfilesImpl(WebDataRequest* request) {
1259 InitializeDatabaseIfNecessary(); 1160 InitializeDatabaseIfNecessary();
1260 if (db_ && !request->IsCancelled(NULL)) { 1161 if (db_ && !request->IsCancelled()) {
1261 std::vector<AutofillProfile*> profiles; 1162 std::vector<AutofillProfile*> profiles;
1262 db_->GetAutofillTable()->GetAutofillProfiles(&profiles); 1163 db_->GetAutofillTable()->GetAutofillProfiles(&profiles);
1263 request->SetResult( 1164 request->SetResult(
1264 new WDResult<std::vector<AutofillProfile*> >(AUTOFILL_PROFILES_RESULT, 1165 new WDResult<std::vector<AutofillProfile*> >(AUTOFILL_PROFILES_RESULT,
1265 profiles)); 1166 base::Bind(&WebDataService::DestroyAutofillProfileResult,
1167 base::Unretained(this)), profiles));
1266 } 1168 }
1267 request->RequestComplete(); 1169 request->RequestComplete();
1268 } 1170 }
1269 1171
1270 void WebDataService::EmptyMigrationTrashImpl( 1172 void WebDataService::EmptyMigrationTrashImpl(
1271 GenericRequest<bool>* request) { 1173 GenericRequest<bool>* request) {
1272 InitializeDatabaseIfNecessary(); 1174 InitializeDatabaseIfNecessary();
1273 if (db_ && !request->IsCancelled(NULL)) { 1175 if (db_ && !request->IsCancelled()) {
1274 bool notify_sync = request->arg(); 1176 bool notify_sync = request->arg();
1275 if (notify_sync) { 1177 if (notify_sync) {
1276 std::vector<std::string> guids; 1178 std::vector<std::string> guids;
1277 if (!db_->GetAutofillTable()->GetAutofillProfilesInTrash(&guids)) { 1179 if (!db_->GetAutofillTable()->GetAutofillProfilesInTrash(&guids)) {
1278 NOTREACHED(); 1180 NOTREACHED();
1279 return; 1181 return;
1280 } 1182 }
1281 1183
1282 for (std::vector<std::string>::const_iterator iter = guids.begin(); 1184 for (std::vector<std::string>::const_iterator iter = guids.begin();
1283 iter != guids.end(); ++iter) { 1185 iter != guids.end(); ++iter) {
(...skipping 30 matching lines...) Expand all
1314 return; 1216 return;
1315 } 1217 }
1316 ScheduleCommit(); 1218 ScheduleCommit();
1317 } 1219 }
1318 request->RequestComplete(); 1220 request->RequestComplete();
1319 } 1221 }
1320 1222
1321 void WebDataService::AddCreditCardImpl( 1223 void WebDataService::AddCreditCardImpl(
1322 GenericRequest<CreditCard>* request) { 1224 GenericRequest<CreditCard>* request) {
1323 InitializeDatabaseIfNecessary(); 1225 InitializeDatabaseIfNecessary();
1324 if (db_ && !request->IsCancelled(NULL)) { 1226 if (db_ && !request->IsCancelled()) {
1325 const CreditCard& credit_card = request->arg(); 1227 const CreditCard& credit_card = request->arg();
1326 if (!db_->GetAutofillTable()->AddCreditCard(credit_card)) { 1228 if (!db_->GetAutofillTable()->AddCreditCard(credit_card)) {
1327 NOTREACHED(); 1229 NOTREACHED();
1328 return; 1230 return;
1329 } 1231 }
1330 ScheduleCommit(); 1232 ScheduleCommit();
1331 1233
1332 // Send GUID-based notification. 1234 // Send GUID-based notification.
1333 AutofillCreditCardChange change(AutofillCreditCardChange::ADD, 1235 AutofillCreditCardChange change(AutofillCreditCardChange::ADD,
1334 credit_card.guid(), &credit_card); 1236 credit_card.guid(), &credit_card);
1335 content::NotificationService::current()->Notify( 1237 content::NotificationService::current()->Notify(
1336 chrome::NOTIFICATION_AUTOFILL_CREDIT_CARD_CHANGED, 1238 chrome::NOTIFICATION_AUTOFILL_CREDIT_CARD_CHANGED,
1337 content::Source<WebDataService>(this), 1239 content::Source<WebDataService>(this),
1338 content::Details<AutofillCreditCardChange>(&change)); 1240 content::Details<AutofillCreditCardChange>(&change));
1339 } 1241 }
1340 request->RequestComplete(); 1242 request->RequestComplete();
1341 } 1243 }
1342 1244
1343 void WebDataService::UpdateCreditCardImpl( 1245 void WebDataService::UpdateCreditCardImpl(
1344 GenericRequest<CreditCard>* request) { 1246 GenericRequest<CreditCard>* request) {
1345 InitializeDatabaseIfNecessary(); 1247 InitializeDatabaseIfNecessary();
1346 if (db_ && !request->IsCancelled(NULL)) { 1248 if (db_ && !request->IsCancelled()) {
1347 const CreditCard& credit_card = request->arg(); 1249 const CreditCard& credit_card = request->arg();
1348 1250
1349 // It is currently valid to try to update a missing profile. We simply drop 1251 // It is currently valid to try to update a missing profile. We simply drop
1350 // the write and the caller will detect this on the next refresh. 1252 // the write and the caller will detect this on the next refresh.
1351 CreditCard* original_credit_card = NULL; 1253 CreditCard* original_credit_card = NULL;
1352 if (!db_->GetAutofillTable()->GetCreditCard(credit_card.guid(), 1254 if (!db_->GetAutofillTable()->GetCreditCard(credit_card.guid(),
1353 &original_credit_card)) { 1255 &original_credit_card)) {
1354 request->RequestComplete(); 1256 request->RequestComplete();
1355 return; 1257 return;
1356 } 1258 }
(...skipping 12 matching lines...) Expand all
1369 chrome::NOTIFICATION_AUTOFILL_CREDIT_CARD_CHANGED, 1271 chrome::NOTIFICATION_AUTOFILL_CREDIT_CARD_CHANGED,
1370 content::Source<WebDataService>(this), 1272 content::Source<WebDataService>(this),
1371 content::Details<AutofillCreditCardChange>(&change)); 1273 content::Details<AutofillCreditCardChange>(&change));
1372 } 1274 }
1373 request->RequestComplete(); 1275 request->RequestComplete();
1374 } 1276 }
1375 1277
1376 void WebDataService::RemoveCreditCardImpl( 1278 void WebDataService::RemoveCreditCardImpl(
1377 GenericRequest<std::string>* request) { 1279 GenericRequest<std::string>* request) {
1378 InitializeDatabaseIfNecessary(); 1280 InitializeDatabaseIfNecessary();
1379 if (db_ && !request->IsCancelled(NULL)) { 1281 if (db_ && !request->IsCancelled()) {
1380 const std::string& guid = request->arg(); 1282 const std::string& guid = request->arg();
1381 if (!db_->GetAutofillTable()->RemoveCreditCard(guid)) { 1283 if (!db_->GetAutofillTable()->RemoveCreditCard(guid)) {
1382 NOTREACHED(); 1284 NOTREACHED();
1383 return; 1285 return;
1384 } 1286 }
1385 ScheduleCommit(); 1287 ScheduleCommit();
1386 1288
1387 // Send GUID-based notification. 1289 // Send GUID-based notification.
1388 AutofillCreditCardChange change(AutofillCreditCardChange::REMOVE, guid, 1290 AutofillCreditCardChange change(AutofillCreditCardChange::REMOVE, guid,
1389 NULL); 1291 NULL);
1390 content::NotificationService::current()->Notify( 1292 content::NotificationService::current()->Notify(
1391 chrome::NOTIFICATION_AUTOFILL_CREDIT_CARD_CHANGED, 1293 chrome::NOTIFICATION_AUTOFILL_CREDIT_CARD_CHANGED,
1392 content::Source<WebDataService>(this), 1294 content::Source<WebDataService>(this),
1393 content::Details<AutofillCreditCardChange>(&change)); 1295 content::Details<AutofillCreditCardChange>(&change));
1394 } 1296 }
1395 request->RequestComplete(); 1297 request->RequestComplete();
1396 } 1298 }
1397 1299
1398 void WebDataService::GetCreditCardsImpl(WebDataRequest* request) { 1300 void WebDataService::GetCreditCardsImpl(WebDataRequest* request) {
1399 InitializeDatabaseIfNecessary(); 1301 InitializeDatabaseIfNecessary();
1400 if (db_ && !request->IsCancelled(NULL)) { 1302 if (db_ && !request->IsCancelled()) {
1401 std::vector<CreditCard*> credit_cards; 1303 std::vector<CreditCard*> credit_cards;
1402 db_->GetAutofillTable()->GetCreditCards(&credit_cards); 1304 db_->GetAutofillTable()->GetCreditCards(&credit_cards);
1403 request->SetResult( 1305 request->SetResult(
1404 new WDResult<std::vector<CreditCard*> >(AUTOFILL_CREDITCARDS_RESULT, 1306 new WDResult<std::vector<CreditCard*> >(AUTOFILL_CREDITCARDS_RESULT,
1405 credit_cards)); 1307 base::Bind(&WebDataService::DestroyAutofillCreditCardResult,
1308 base::Unretained(this)), credit_cards));
1406 } 1309 }
1407 request->RequestComplete(); 1310 request->RequestComplete();
1408 } 1311 }
1409 1312
1410 void WebDataService::RemoveAutofillProfilesAndCreditCardsModifiedBetweenImpl( 1313 void WebDataService::RemoveAutofillProfilesAndCreditCardsModifiedBetweenImpl(
1411 GenericRequest2<Time, Time>* request) { 1314 GenericRequest2<Time, Time>* request) {
1412 InitializeDatabaseIfNecessary(); 1315 InitializeDatabaseIfNecessary();
1413 if (db_ && !request->IsCancelled(NULL)) { 1316 if (db_ && !request->IsCancelled()) {
1414 std::vector<std::string> profile_guids; 1317 std::vector<std::string> profile_guids;
1415 std::vector<std::string> credit_card_guids; 1318 std::vector<std::string> credit_card_guids;
1416 if (db_->GetAutofillTable()-> 1319 if (db_->GetAutofillTable()->
1417 RemoveAutofillProfilesAndCreditCardsModifiedBetween( 1320 RemoveAutofillProfilesAndCreditCardsModifiedBetween(
1418 request->arg1(), 1321 request->arg1(),
1419 request->arg2(), 1322 request->arg2(),
1420 &profile_guids, 1323 &profile_guids,
1421 &credit_card_guids)) { 1324 &credit_card_guids)) {
1422 for (std::vector<std::string>::iterator iter = profile_guids.begin(); 1325 for (std::vector<std::string>::iterator iter = profile_guids.begin();
1423 iter != profile_guids.end(); ++iter) { 1326 iter != profile_guids.end(); ++iter) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1455 } 1358 }
1456 1359
1457 AutocompleteSyncableService* WebDataService::GetAutocompleteSyncableService() 1360 AutocompleteSyncableService* WebDataService::GetAutocompleteSyncableService()
1458 const { 1361 const {
1459 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 1362 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
1460 DCHECK(autocomplete_syncable_service_); // Make sure we're initialized. 1363 DCHECK(autocomplete_syncable_service_); // Make sure we're initialized.
1461 1364
1462 return autocomplete_syncable_service_; 1365 return autocomplete_syncable_service_;
1463 } 1366 }
1464 1367
1465 1368 void WebDataService::DestroyAutofillProfileResult(const WDTypedResult* result) {
1466 //////////////////////////////////////////////////////////////////////////////// 1369 DCHECK(result->GetType() == AUTOFILL_PROFILES_RESULT);
1467 // 1370 const WDResult<std::vector<AutofillProfile*> >* r =
1468 // WebDataRequest implementation. 1371 static_cast<const WDResult<std::vector<AutofillProfile*> >*>(result);
1469 // 1372 std::vector<AutofillProfile*> profiles = r->GetValue();
1470 //////////////////////////////////////////////////////////////////////////////// 1373 STLDeleteElements(&profiles);
1471
1472 WebDataService::WebDataRequest::WebDataRequest(WebDataService* service,
1473 Handle handle,
1474 WebDataServiceConsumer* consumer)
1475 : service_(service),
1476 handle_(handle),
1477 cancelled_(false),
1478 consumer_(consumer),
1479 result_(NULL) {
1480 message_loop_ = MessageLoop::current();
1481 } 1374 }
1482 1375
1483 WebDataService::WebDataRequest::~WebDataRequest() { 1376 void WebDataService::DestroyAutofillCreditCardResult(
1484 delete result_; 1377 const WDTypedResult* result) {
1378 DCHECK(result->GetType() == AUTOFILL_CREDITCARDS_RESULT);
1379 const WDResult<std::vector<CreditCard*> >* r =
1380 static_cast<const WDResult<std::vector<CreditCard*> >*>(result);
1381
1382 std::vector<CreditCard*> credit_cards = r->GetValue();
1383 STLDeleteElements(&credit_cards);
1485 } 1384 }
1486
1487 WebDataService::Handle WebDataService::WebDataRequest::GetHandle() const {
1488 return handle_;
1489 }
1490
1491 bool WebDataService::WebDataRequest::IsCancelled(
1492 WebDataServiceConsumer** consumer) const {
1493 base::AutoLock l(cancel_lock_);
1494 if (consumer)
1495 *consumer = consumer_;
1496 return cancelled_;
1497 }
1498
1499 void WebDataService::WebDataRequest::Cancel() {
1500 base::AutoLock l(cancel_lock_);
1501 cancelled_ = true;
1502 consumer_ = NULL;
1503 }
1504
1505 void WebDataService::WebDataRequest::SetResult(WDTypedResult* r) {
1506 result_ = r;
1507 }
1508
1509 const WDTypedResult* WebDataService::WebDataRequest::GetResult() const {
1510 return result_;
1511 }
1512
1513 void WebDataService::WebDataRequest::RequestComplete() {
1514 message_loop_->PostTask(FROM_HERE, Bind(&WebDataService::RequestCompleted,
1515 service_.get(), handle_));
1516 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698