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