OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
101 make_scoped_refptr(web_data_service))); | 101 make_scoped_refptr(web_data_service))); |
102 } | 102 } |
103 | 103 |
104 bool WebDataService::Init(const FilePath& profile_path) { | 104 bool WebDataService::Init(const FilePath& profile_path) { |
105 FilePath path = profile_path; | 105 FilePath path = profile_path; |
106 path = path.Append(chrome::kWebDataFilename); | 106 path = path.Append(chrome::kWebDataFilename); |
107 return InitWithPath(path); | 107 return InitWithPath(path); |
108 } | 108 } |
109 | 109 |
110 void WebDataService::Shutdown() { | 110 void WebDataService::Shutdown() { |
111 ScheduleTask(Bind(&WebDataService::ShutdownSyncableServices, this)); | 111 ScheduleTask(FROM_HERE, |
112 Bind(&WebDataService::ShutdownSyncableServices, this)); | |
112 UnloadDatabase(); | 113 UnloadDatabase(); |
113 } | 114 } |
114 | 115 |
115 bool WebDataService::IsRunning() const { | 116 bool WebDataService::IsRunning() const { |
116 return is_running_; | 117 return is_running_; |
117 } | 118 } |
118 | 119 |
119 void WebDataService::UnloadDatabase() { | 120 void WebDataService::UnloadDatabase() { |
120 ScheduleTask(Bind(&WebDataService::ShutdownDatabase, this)); | 121 ScheduleTask(FROM_HERE, Bind(&WebDataService::ShutdownDatabase, this)); |
121 } | 122 } |
122 | 123 |
123 void WebDataService::CancelRequest(Handle h) { | 124 void WebDataService::CancelRequest(Handle h) { |
124 base::AutoLock l(pending_lock_); | 125 base::AutoLock l(pending_lock_); |
125 RequestMap::iterator i = pending_requests_.find(h); | 126 RequestMap::iterator i = pending_requests_.find(h); |
126 if (i == pending_requests_.end()) { | 127 if (i == pending_requests_.end()) { |
127 NOTREACHED() << "Canceling a nonexistent web data service request"; | 128 NOTREACHED() << "Canceling a nonexistent web data service request"; |
128 return; | 129 return; |
129 } | 130 } |
130 i->second->Cancel(); | 131 i->second->Cancel(); |
(...skipping 14 matching lines...) Expand all Loading... | |
145 // | 146 // |
146 ////////////////////////////////////////////////////////////////////////////// | 147 ////////////////////////////////////////////////////////////////////////////// |
147 | 148 |
148 void WebDataService::AddKeyword(const TemplateURL& url) { | 149 void WebDataService::AddKeyword(const TemplateURL& url) { |
149 // Ensure that the keyword is already generated (and cached) before caching | 150 // Ensure that the keyword is already generated (and cached) before caching |
150 // the TemplateURL for use on another keyword. | 151 // the TemplateURL for use on another keyword. |
151 url.EnsureKeyword(); | 152 url.EnsureKeyword(); |
152 GenericRequest<TemplateURL>* request = | 153 GenericRequest<TemplateURL>* request = |
153 new GenericRequest<TemplateURL>(this, GetNextRequestHandle(), NULL, url); | 154 new GenericRequest<TemplateURL>(this, GetNextRequestHandle(), NULL, url); |
154 RegisterRequest(request); | 155 RegisterRequest(request); |
155 ScheduleTask(Bind(&WebDataService::AddKeywordImpl, this, request)); | 156 ScheduleTask(FROM_HERE, Bind(&WebDataService::AddKeywordImpl, this, request)); |
156 } | 157 } |
157 | 158 |
158 void WebDataService::RemoveKeyword(const TemplateURL& url) { | 159 void WebDataService::RemoveKeyword(const TemplateURL& url) { |
159 GenericRequest<TemplateURLID>* request = | 160 GenericRequest<TemplateURLID>* request = |
160 new GenericRequest<TemplateURLID>(this, GetNextRequestHandle(), | 161 new GenericRequest<TemplateURLID>(this, GetNextRequestHandle(), |
161 NULL, url.id()); | 162 NULL, url.id()); |
162 RegisterRequest(request); | 163 RegisterRequest(request); |
163 ScheduleTask(Bind(&WebDataService::RemoveKeywordImpl, this, request)); | 164 ScheduleTask(FROM_HERE, |
165 Bind(&WebDataService::RemoveKeywordImpl, this, request)); | |
164 } | 166 } |
165 | 167 |
166 void WebDataService::UpdateKeyword(const TemplateURL& url) { | 168 void WebDataService::UpdateKeyword(const TemplateURL& url) { |
167 // Ensure that the keyword is already generated (and cached) before caching | 169 // Ensure that the keyword is already generated (and cached) before caching |
168 // the TemplateURL for use on another keyword. | 170 // the TemplateURL for use on another keyword. |
169 url.EnsureKeyword(); | 171 url.EnsureKeyword(); |
170 GenericRequest<TemplateURL>* request = | 172 GenericRequest<TemplateURL>* request = |
171 new GenericRequest<TemplateURL>(this, GetNextRequestHandle(), NULL, url); | 173 new GenericRequest<TemplateURL>(this, GetNextRequestHandle(), NULL, url); |
172 RegisterRequest(request); | 174 RegisterRequest(request); |
173 ScheduleTask(Bind(&WebDataService::UpdateKeywordImpl, this, request)); | 175 ScheduleTask(FROM_HERE, |
176 Bind(&WebDataService::UpdateKeywordImpl, this, request)); | |
174 } | 177 } |
175 | 178 |
176 WebDataService::Handle WebDataService::GetKeywords( | 179 WebDataService::Handle WebDataService::GetKeywords( |
177 WebDataServiceConsumer* consumer) { | 180 WebDataServiceConsumer* consumer) { |
178 WebDataRequest* request = | 181 WebDataRequest* request = |
179 new WebDataRequest(this, GetNextRequestHandle(), consumer); | 182 new WebDataRequest(this, GetNextRequestHandle(), consumer); |
180 RegisterRequest(request); | 183 RegisterRequest(request); |
181 ScheduleTask(Bind(&WebDataService::GetKeywordsImpl, this, request)); | 184 ScheduleTask(FROM_HERE, |
185 Bind(&WebDataService::GetKeywordsImpl, this, request)); | |
182 return request->GetHandle(); | 186 return request->GetHandle(); |
183 } | 187 } |
184 | 188 |
185 void WebDataService::SetDefaultSearchProvider(const TemplateURL* url) { | 189 void WebDataService::SetDefaultSearchProvider(const TemplateURL* url) { |
186 GenericRequest<TemplateURLID>* request = | 190 GenericRequest<TemplateURLID>* request = |
187 new GenericRequest<TemplateURLID>(this, | 191 new GenericRequest<TemplateURLID>(this, |
188 GetNextRequestHandle(), | 192 GetNextRequestHandle(), |
189 NULL, | 193 NULL, |
190 url ? url->id() : 0); | 194 url ? url->id() : 0); |
191 RegisterRequest(request); | 195 RegisterRequest(request); |
192 ScheduleTask(Bind(&WebDataService::SetDefaultSearchProviderImpl, | 196 ScheduleTask(FROM_HERE, Bind(&WebDataService::SetDefaultSearchProviderImpl, |
193 this, request)); | 197 this, request)); |
194 } | 198 } |
195 | 199 |
196 void WebDataService::SetBuiltinKeywordVersion(int version) { | 200 void WebDataService::SetBuiltinKeywordVersion(int version) { |
197 GenericRequest<int>* request = | 201 GenericRequest<int>* request = |
198 new GenericRequest<int>(this, GetNextRequestHandle(), NULL, version); | 202 new GenericRequest<int>(this, GetNextRequestHandle(), NULL, version); |
199 RegisterRequest(request); | 203 RegisterRequest(request); |
200 ScheduleTask(Bind(&WebDataService::SetBuiltinKeywordVersionImpl, | 204 ScheduleTask(FROM_HERE, Bind(&WebDataService::SetBuiltinKeywordVersionImpl, |
201 this, request)); | 205 this, request)); |
202 } | 206 } |
203 | 207 |
204 ////////////////////////////////////////////////////////////////////////////// | 208 ////////////////////////////////////////////////////////////////////////////// |
205 // | 209 // |
206 // Web Apps | 210 // Web Apps |
207 // | 211 // |
208 ////////////////////////////////////////////////////////////////////////////// | 212 ////////////////////////////////////////////////////////////////////////////// |
209 | 213 |
210 void WebDataService::SetWebAppImage(const GURL& app_url, | 214 void WebDataService::SetWebAppImage(const GURL& app_url, |
211 const SkBitmap& image) { | 215 const SkBitmap& image) { |
212 GenericRequest2<GURL, SkBitmap>* request = | 216 GenericRequest2<GURL, SkBitmap>* request = |
213 new GenericRequest2<GURL, SkBitmap>(this, GetNextRequestHandle(), | 217 new GenericRequest2<GURL, SkBitmap>(this, GetNextRequestHandle(), |
214 NULL, app_url, image); | 218 NULL, app_url, image); |
215 RegisterRequest(request); | 219 RegisterRequest(request); |
216 ScheduleTask(Bind(&WebDataService::SetWebAppImageImpl, this, request)); | 220 ScheduleTask(FROM_HERE, |
221 Bind(&WebDataService::SetWebAppImageImpl, this, request)); | |
217 } | 222 } |
218 | 223 |
219 void WebDataService::SetWebAppHasAllImages(const GURL& app_url, | 224 void WebDataService::SetWebAppHasAllImages(const GURL& app_url, |
220 bool has_all_images) { | 225 bool has_all_images) { |
221 GenericRequest2<GURL, bool>* request = | 226 GenericRequest2<GURL, bool>* request = |
222 new GenericRequest2<GURL, bool>(this, GetNextRequestHandle(), | 227 new GenericRequest2<GURL, bool>(this, GetNextRequestHandle(), |
223 NULL, app_url, has_all_images); | 228 NULL, app_url, has_all_images); |
224 RegisterRequest(request); | 229 RegisterRequest(request); |
225 ScheduleTask(Bind(&WebDataService::SetWebAppHasAllImagesImpl, this, request)); | 230 ScheduleTask(FROM_HERE, |
231 Bind(&WebDataService::SetWebAppHasAllImagesImpl, this, request)); | |
226 } | 232 } |
227 | 233 |
228 void WebDataService::RemoveWebApp(const GURL& app_url) { | 234 void WebDataService::RemoveWebApp(const GURL& app_url) { |
229 GenericRequest<GURL>* request = | 235 GenericRequest<GURL>* request = |
230 new GenericRequest<GURL>(this, GetNextRequestHandle(), NULL, app_url); | 236 new GenericRequest<GURL>(this, GetNextRequestHandle(), NULL, app_url); |
231 RegisterRequest(request); | 237 RegisterRequest(request); |
232 ScheduleTask(Bind(&WebDataService::RemoveWebAppImpl, this, request)); | 238 ScheduleTask(FROM_HERE, |
239 Bind(&WebDataService::RemoveWebAppImpl, this, request)); | |
233 } | 240 } |
234 | 241 |
235 WebDataService::Handle WebDataService::GetWebAppImages( | 242 WebDataService::Handle WebDataService::GetWebAppImages( |
236 const GURL& app_url, | 243 const GURL& app_url, |
237 WebDataServiceConsumer* consumer) { | 244 WebDataServiceConsumer* consumer) { |
238 GenericRequest<GURL>* request = | 245 GenericRequest<GURL>* request = |
239 new GenericRequest<GURL>(this, GetNextRequestHandle(), consumer, app_url); | 246 new GenericRequest<GURL>(this, GetNextRequestHandle(), consumer, app_url); |
240 RegisterRequest(request); | 247 RegisterRequest(request); |
241 ScheduleTask(Bind(&WebDataService::GetWebAppImagesImpl, this, request)); | 248 ScheduleTask(FROM_HERE, |
249 Bind(&WebDataService::GetWebAppImagesImpl, this, request)); | |
242 return request->GetHandle(); | 250 return request->GetHandle(); |
243 } | 251 } |
244 | 252 |
245 ////////////////////////////////////////////////////////////////////////////// | 253 ////////////////////////////////////////////////////////////////////////////// |
246 // | 254 // |
247 // Web Intents. | 255 // Web Intents. |
248 // | 256 // |
249 ////////////////////////////////////////////////////////////////////////////// | 257 ////////////////////////////////////////////////////////////////////////////// |
250 | 258 |
251 void WebDataService::AddWebIntentService(const WebIntentServiceData& service) { | 259 void WebDataService::AddWebIntentService(const WebIntentServiceData& service) { |
252 GenericRequest<WebIntentServiceData>* request = | 260 GenericRequest<WebIntentServiceData>* request = |
253 new GenericRequest<WebIntentServiceData>( | 261 new GenericRequest<WebIntentServiceData>( |
254 this, GetNextRequestHandle(), NULL, service); | 262 this, GetNextRequestHandle(), NULL, service); |
255 RegisterRequest(request); | 263 RegisterRequest(request); |
256 ScheduleTask(Bind(&WebDataService::AddWebIntentServiceImpl, this, request)); | 264 ScheduleTask(FROM_HERE, |
265 Bind(&WebDataService::AddWebIntentServiceImpl, this, request)); | |
257 } | 266 } |
258 | 267 |
259 void WebDataService::RemoveWebIntentService( | 268 void WebDataService::RemoveWebIntentService( |
260 const WebIntentServiceData& service) { | 269 const WebIntentServiceData& service) { |
261 GenericRequest<WebIntentServiceData>* request = | 270 GenericRequest<WebIntentServiceData>* request = |
262 new GenericRequest<WebIntentServiceData>( | 271 new GenericRequest<WebIntentServiceData>( |
263 this, GetNextRequestHandle(), NULL, service); | 272 this, GetNextRequestHandle(), NULL, service); |
264 RegisterRequest(request); | 273 RegisterRequest(request); |
265 ScheduleTask(Bind(&WebDataService::RemoveWebIntentServiceImpl, | 274 ScheduleTask(FROM_HERE, Bind(&WebDataService::RemoveWebIntentServiceImpl, |
266 this, | 275 this, request)); |
267 request)); | |
268 } | 276 } |
269 | 277 |
270 WebDataService::Handle WebDataService::GetWebIntentServices( | 278 WebDataService::Handle WebDataService::GetWebIntentServices( |
271 const string16& action, | 279 const string16& action, |
272 WebDataServiceConsumer* consumer) { | 280 WebDataServiceConsumer* consumer) { |
273 DCHECK(consumer); | 281 DCHECK(consumer); |
274 GenericRequest<string16>* request = new GenericRequest<string16>( | 282 GenericRequest<string16>* request = new GenericRequest<string16>( |
275 this, GetNextRequestHandle(), consumer, action); | 283 this, GetNextRequestHandle(), consumer, action); |
276 RegisterRequest(request); | 284 RegisterRequest(request); |
277 ScheduleTask(Bind(&WebDataService::GetWebIntentServicesImpl, this, request)); | 285 ScheduleTask(FROM_HERE, |
286 Bind(&WebDataService::GetWebIntentServicesImpl, this, request)); | |
278 return request->GetHandle(); | 287 return request->GetHandle(); |
279 } | 288 } |
280 | 289 |
281 WebDataService::Handle WebDataService::GetWebIntentServicesForURL( | 290 WebDataService::Handle WebDataService::GetWebIntentServicesForURL( |
282 const string16& service_url, | 291 const string16& service_url, |
283 WebDataServiceConsumer* consumer) { | 292 WebDataServiceConsumer* consumer) { |
284 DCHECK(consumer); | 293 DCHECK(consumer); |
285 GenericRequest<string16>* request = new GenericRequest<string16>( | 294 GenericRequest<string16>* request = new GenericRequest<string16>( |
286 this, GetNextRequestHandle(), consumer, service_url); | 295 this, GetNextRequestHandle(), consumer, service_url); |
287 RegisterRequest(request); | 296 RegisterRequest(request); |
288 ScheduleTask(Bind(&WebDataService::GetWebIntentServicesForURLImpl, | 297 ScheduleTask(FROM_HERE, Bind(&WebDataService::GetWebIntentServicesForURLImpl, |
289 this, | 298 this, request)); |
290 request)); | |
291 return request->GetHandle(); | 299 return request->GetHandle(); |
292 } | 300 } |
293 | 301 |
294 | 302 |
295 WebDataService::Handle WebDataService::GetAllWebIntentServices( | 303 WebDataService::Handle WebDataService::GetAllWebIntentServices( |
296 WebDataServiceConsumer* consumer) { | 304 WebDataServiceConsumer* consumer) { |
297 DCHECK(consumer); | 305 DCHECK(consumer); |
298 GenericRequest<std::string>* request = new GenericRequest<std::string>( | 306 GenericRequest<std::string>* request = new GenericRequest<std::string>( |
299 this, GetNextRequestHandle(), consumer, std::string()); | 307 this, GetNextRequestHandle(), consumer, std::string()); |
300 RegisterRequest(request); | 308 RegisterRequest(request); |
301 ScheduleTask(Bind(&WebDataService::GetAllWebIntentServicesImpl, | 309 ScheduleTask(FROM_HERE, Bind(&WebDataService::GetAllWebIntentServicesImpl, |
302 this, | 310 this, request)); |
303 request)); | |
304 return request->GetHandle(); | 311 return request->GetHandle(); |
305 } | 312 } |
306 | 313 |
307 //////////////////////////////////////////////////////////////////////////////// | 314 //////////////////////////////////////////////////////////////////////////////// |
308 // | 315 // |
309 // Token Service | 316 // Token Service |
310 // | 317 // |
311 //////////////////////////////////////////////////////////////////////////////// | 318 //////////////////////////////////////////////////////////////////////////////// |
312 | 319 |
313 void WebDataService::SetTokenForService(const std::string& service, | 320 void WebDataService::SetTokenForService(const std::string& service, |
314 const std::string& token) { | 321 const std::string& token) { |
315 GenericRequest2<std::string, std::string>* request = | 322 GenericRequest2<std::string, std::string>* request = |
316 new GenericRequest2<std::string, std::string>( | 323 new GenericRequest2<std::string, std::string>( |
317 this, GetNextRequestHandle(), NULL, service, token); | 324 this, GetNextRequestHandle(), NULL, service, token); |
318 RegisterRequest(request); | 325 RegisterRequest(request); |
319 ScheduleTask(Bind(&WebDataService::SetTokenForServiceImpl, this, request)); | 326 ScheduleTask(FROM_HERE, |
327 Bind(&WebDataService::SetTokenForServiceImpl, this, request)); | |
320 } | 328 } |
321 | 329 |
322 void WebDataService::RemoveAllTokens() { | 330 void WebDataService::RemoveAllTokens() { |
323 GenericRequest<std::string>* request = | 331 GenericRequest<std::string>* request = |
324 new GenericRequest<std::string>( | 332 new GenericRequest<std::string>( |
325 this, GetNextRequestHandle(), NULL, std::string()); | 333 this, GetNextRequestHandle(), NULL, std::string()); |
326 RegisterRequest(request); | 334 RegisterRequest(request); |
327 ScheduleTask(Bind(&WebDataService::RemoveAllTokensImpl, this, request)); | 335 ScheduleTask(FROM_HERE, |
336 Bind(&WebDataService::RemoveAllTokensImpl, this, request)); | |
328 } | 337 } |
329 | 338 |
330 // Null on failure. Success is WDResult<std::string> | 339 // Null on failure. Success is WDResult<std::string> |
331 WebDataService::Handle WebDataService::GetAllTokens( | 340 WebDataService::Handle WebDataService::GetAllTokens( |
332 WebDataServiceConsumer* consumer) { | 341 WebDataServiceConsumer* consumer) { |
333 | 342 |
334 GenericRequest<std::string>* request = | 343 GenericRequest<std::string>* request = |
335 new GenericRequest<std::string>( | 344 new GenericRequest<std::string>( |
336 this, GetNextRequestHandle(), consumer, std::string()); | 345 this, GetNextRequestHandle(), consumer, std::string()); |
337 RegisterRequest(request); | 346 RegisterRequest(request); |
338 ScheduleTask(Bind(&WebDataService::GetAllTokensImpl, this, request)); | 347 ScheduleTask(FROM_HERE, |
348 Bind(&WebDataService::GetAllTokensImpl, this, request)); | |
339 return request->GetHandle(); | 349 return request->GetHandle(); |
340 } | 350 } |
341 | 351 |
342 //////////////////////////////////////////////////////////////////////////////// | 352 //////////////////////////////////////////////////////////////////////////////// |
343 // | 353 // |
344 // Password manager. | 354 // Password manager. |
345 // | 355 // |
346 //////////////////////////////////////////////////////////////////////////////// | 356 //////////////////////////////////////////////////////////////////////////////// |
347 | 357 |
348 void WebDataService::AddLogin(const PasswordForm& form) { | 358 void WebDataService::AddLogin(const PasswordForm& form) { |
349 GenericRequest<PasswordForm>* request = | 359 GenericRequest<PasswordForm>* request = |
350 new GenericRequest<PasswordForm>(this, GetNextRequestHandle(), NULL, | 360 new GenericRequest<PasswordForm>(this, GetNextRequestHandle(), NULL, |
351 form); | 361 form); |
352 RegisterRequest(request); | 362 RegisterRequest(request); |
353 ScheduleTask(Bind(&WebDataService::AddLoginImpl, this, request)); | 363 ScheduleTask(FROM_HERE, Bind(&WebDataService::AddLoginImpl, this, request)); |
354 } | 364 } |
355 | 365 |
356 void WebDataService::UpdateLogin(const PasswordForm& form) { | 366 void WebDataService::UpdateLogin(const PasswordForm& form) { |
357 GenericRequest<PasswordForm>* request = | 367 GenericRequest<PasswordForm>* request = |
358 new GenericRequest<PasswordForm>(this, GetNextRequestHandle(), | 368 new GenericRequest<PasswordForm>(this, GetNextRequestHandle(), |
359 NULL, form); | 369 NULL, form); |
360 RegisterRequest(request); | 370 RegisterRequest(request); |
361 ScheduleTask(Bind(&WebDataService::UpdateLoginImpl, this, request)); | 371 ScheduleTask(FROM_HERE, |
372 Bind(&WebDataService::UpdateLoginImpl, this, request)); | |
362 } | 373 } |
363 | 374 |
364 void WebDataService::RemoveLogin(const PasswordForm& form) { | 375 void WebDataService::RemoveLogin(const PasswordForm& form) { |
365 GenericRequest<PasswordForm>* request = | 376 GenericRequest<PasswordForm>* request = |
366 new GenericRequest<PasswordForm>(this, GetNextRequestHandle(), NULL, | 377 new GenericRequest<PasswordForm>(this, GetNextRequestHandle(), NULL, |
367 form); | 378 form); |
368 RegisterRequest(request); | 379 RegisterRequest(request); |
369 ScheduleTask(Bind(&WebDataService::RemoveLoginImpl, this, request)); | 380 ScheduleTask(FROM_HERE, |
381 Bind(&WebDataService::RemoveLoginImpl, this, request)); | |
370 } | 382 } |
371 | 383 |
372 void WebDataService::RemoveLoginsCreatedBetween(const Time& delete_begin, | 384 void WebDataService::RemoveLoginsCreatedBetween(const Time& delete_begin, |
373 const Time& delete_end) { | 385 const Time& delete_end) { |
374 GenericRequest2<Time, Time>* request = | 386 GenericRequest2<Time, Time>* request = |
375 new GenericRequest2<Time, Time>(this, | 387 new GenericRequest2<Time, Time>(this, |
376 GetNextRequestHandle(), | 388 GetNextRequestHandle(), |
377 NULL, | 389 NULL, |
378 delete_begin, | 390 delete_begin, |
379 delete_end); | 391 delete_end); |
380 RegisterRequest(request); | 392 RegisterRequest(request); |
381 ScheduleTask(Bind(&WebDataService::RemoveLoginsCreatedBetweenImpl, | 393 ScheduleTask(FROM_HERE, Bind(&WebDataService::RemoveLoginsCreatedBetweenImpl, |
382 this, request)); | 394 this, request)); |
383 } | 395 } |
384 | 396 |
385 void WebDataService::RemoveLoginsCreatedAfter(const Time& delete_begin) { | 397 void WebDataService::RemoveLoginsCreatedAfter(const Time& delete_begin) { |
386 RemoveLoginsCreatedBetween(delete_begin, Time()); | 398 RemoveLoginsCreatedBetween(delete_begin, Time()); |
387 } | 399 } |
388 | 400 |
389 WebDataService::Handle WebDataService::GetLogins( | 401 WebDataService::Handle WebDataService::GetLogins( |
390 const PasswordForm& form, | 402 const PasswordForm& form, |
391 WebDataServiceConsumer* consumer) { | 403 WebDataServiceConsumer* consumer) { |
392 GenericRequest<PasswordForm>* request = | 404 GenericRequest<PasswordForm>* request = |
393 new GenericRequest<PasswordForm>(this, GetNextRequestHandle(), | 405 new GenericRequest<PasswordForm>(this, GetNextRequestHandle(), |
394 consumer, form); | 406 consumer, form); |
395 RegisterRequest(request); | 407 RegisterRequest(request); |
396 ScheduleTask(Bind(&WebDataService::GetLoginsImpl, this, request)); | 408 ScheduleTask(FROM_HERE, Bind(&WebDataService::GetLoginsImpl, this, request)); |
397 return request->GetHandle(); | 409 return request->GetHandle(); |
398 } | 410 } |
399 | 411 |
400 WebDataService::Handle WebDataService::GetAutofillableLogins( | 412 WebDataService::Handle WebDataService::GetAutofillableLogins( |
401 WebDataServiceConsumer* consumer) { | 413 WebDataServiceConsumer* consumer) { |
402 WebDataRequest* request = | 414 WebDataRequest* request = |
403 new WebDataRequest(this, GetNextRequestHandle(), consumer); | 415 new WebDataRequest(this, GetNextRequestHandle(), consumer); |
404 RegisterRequest(request); | 416 RegisterRequest(request); |
405 ScheduleTask(Bind(&WebDataService::GetAutofillableLoginsImpl, this, request)); | 417 ScheduleTask(FROM_HERE, |
418 Bind(&WebDataService::GetAutofillableLoginsImpl, this, request)); | |
406 return request->GetHandle(); | 419 return request->GetHandle(); |
407 } | 420 } |
408 | 421 |
409 WebDataService::Handle WebDataService::GetBlacklistLogins( | 422 WebDataService::Handle WebDataService::GetBlacklistLogins( |
410 WebDataServiceConsumer* consumer) { | 423 WebDataServiceConsumer* consumer) { |
411 WebDataRequest* request = | 424 WebDataRequest* request = |
412 new WebDataRequest(this, GetNextRequestHandle(), consumer); | 425 new WebDataRequest(this, GetNextRequestHandle(), consumer); |
413 RegisterRequest(request); | 426 RegisterRequest(request); |
414 ScheduleTask(Bind(&WebDataService::GetBlacklistLoginsImpl, this, request)); | 427 ScheduleTask(FROM_HERE, |
428 Bind(&WebDataService::GetBlacklistLoginsImpl, this, request)); | |
415 return request->GetHandle(); | 429 return request->GetHandle(); |
416 } | 430 } |
417 | 431 |
418 //////////////////////////////////////////////////////////////////////////////// | 432 //////////////////////////////////////////////////////////////////////////////// |
419 // | 433 // |
420 // Autofill. | 434 // Autofill. |
421 // | 435 // |
422 //////////////////////////////////////////////////////////////////////////////// | 436 //////////////////////////////////////////////////////////////////////////////// |
423 | 437 |
424 void WebDataService::AddFormFields( | 438 void WebDataService::AddFormFields( |
425 const std::vector<FormField>& fields) { | 439 const std::vector<FormField>& fields) { |
426 GenericRequest<std::vector<FormField> >* request = | 440 GenericRequest<std::vector<FormField> >* request = |
427 new GenericRequest<std::vector<FormField> >( | 441 new GenericRequest<std::vector<FormField> >( |
428 this, GetNextRequestHandle(), NULL, fields); | 442 this, GetNextRequestHandle(), NULL, fields); |
429 RegisterRequest(request); | 443 RegisterRequest(request); |
430 ScheduleTask(Bind(&WebDataService::AddFormElementsImpl, this, request)); | 444 ScheduleTask(FROM_HERE, |
445 Bind(&WebDataService::AddFormElementsImpl, this, request)); | |
431 } | 446 } |
432 | 447 |
433 WebDataService::Handle WebDataService::GetFormValuesForElementName( | 448 WebDataService::Handle WebDataService::GetFormValuesForElementName( |
434 const string16& name, const string16& prefix, int limit, | 449 const string16& name, const string16& prefix, int limit, |
435 WebDataServiceConsumer* consumer) { | 450 WebDataServiceConsumer* consumer) { |
436 WebDataRequest* request = | 451 WebDataRequest* request = |
437 new WebDataRequest(this, GetNextRequestHandle(), consumer); | 452 new WebDataRequest(this, GetNextRequestHandle(), consumer); |
438 RegisterRequest(request); | 453 RegisterRequest(request); |
439 ScheduleTask(Bind(&WebDataService::GetFormValuesForElementNameImpl, | 454 ScheduleTask(FROM_HERE, |
455 Bind(&WebDataService::GetFormValuesForElementNameImpl, | |
440 this, request, name, prefix, limit)); | 456 this, request, name, prefix, limit)); |
441 return request->GetHandle(); | 457 return request->GetHandle(); |
442 } | 458 } |
443 | 459 |
444 void WebDataService::RemoveFormElementsAddedBetween(const Time& delete_begin, | 460 void WebDataService::RemoveFormElementsAddedBetween(const Time& delete_begin, |
445 const Time& delete_end) { | 461 const Time& delete_end) { |
446 GenericRequest2<Time, Time>* request = | 462 GenericRequest2<Time, Time>* request = |
447 new GenericRequest2<Time, Time>(this, | 463 new GenericRequest2<Time, Time>(this, |
448 GetNextRequestHandle(), | 464 GetNextRequestHandle(), |
449 NULL, | 465 NULL, |
450 delete_begin, | 466 delete_begin, |
451 delete_end); | 467 delete_end); |
452 RegisterRequest(request); | 468 RegisterRequest(request); |
453 ScheduleTask(Bind(&WebDataService::RemoveFormElementsAddedBetweenImpl, | 469 ScheduleTask(FROM_HERE, |
470 Bind(&WebDataService::RemoveFormElementsAddedBetweenImpl, | |
454 this, request)); | 471 this, request)); |
455 } | 472 } |
456 | 473 |
457 void WebDataService::RemoveFormValueForElementName( | 474 void WebDataService::RemoveFormValueForElementName( |
458 const string16& name, const string16& value) { | 475 const string16& name, const string16& value) { |
459 GenericRequest2<string16, string16>* request = | 476 GenericRequest2<string16, string16>* request = |
460 new GenericRequest2<string16, string16>(this, | 477 new GenericRequest2<string16, string16>(this, |
461 GetNextRequestHandle(), | 478 GetNextRequestHandle(), |
462 NULL, | 479 NULL, |
463 name, value); | 480 name, value); |
464 RegisterRequest(request); | 481 RegisterRequest(request); |
465 ScheduleTask(Bind(&WebDataService::RemoveFormValueForElementNameImpl, | 482 ScheduleTask(FROM_HERE, |
483 Bind(&WebDataService::RemoveFormValueForElementNameImpl, | |
466 this, request)); | 484 this, request)); |
467 } | 485 } |
468 | 486 |
469 void WebDataService::AddAutofillProfile(const AutofillProfile& profile) { | 487 void WebDataService::AddAutofillProfile(const AutofillProfile& profile) { |
470 GenericRequest<AutofillProfile>* request = | 488 GenericRequest<AutofillProfile>* request = |
471 new GenericRequest<AutofillProfile>( | 489 new GenericRequest<AutofillProfile>( |
472 this, GetNextRequestHandle(), NULL, profile); | 490 this, GetNextRequestHandle(), NULL, profile); |
473 RegisterRequest(request); | 491 RegisterRequest(request); |
474 ScheduleTask(Bind(&WebDataService::AddAutofillProfileImpl, this, request)); | 492 ScheduleTask(FROM_HERE, |
493 Bind(&WebDataService::AddAutofillProfileImpl, this, request)); | |
475 } | 494 } |
476 | 495 |
477 void WebDataService::UpdateAutofillProfile(const AutofillProfile& profile) { | 496 void WebDataService::UpdateAutofillProfile(const AutofillProfile& profile) { |
478 GenericRequest<AutofillProfile>* request = | 497 GenericRequest<AutofillProfile>* request = |
479 new GenericRequest<AutofillProfile>( | 498 new GenericRequest<AutofillProfile>( |
480 this, GetNextRequestHandle(), NULL, profile); | 499 this, GetNextRequestHandle(), NULL, profile); |
481 RegisterRequest(request); | 500 RegisterRequest(request); |
482 ScheduleTask(Bind(&WebDataService::UpdateAutofillProfileImpl, this, request)); | 501 ScheduleTask(FROM_HERE, |
502 Bind(&WebDataService::UpdateAutofillProfileImpl, this, request)); | |
483 } | 503 } |
484 | 504 |
485 void WebDataService::RemoveAutofillProfile(const std::string& guid) { | 505 void WebDataService::RemoveAutofillProfile(const std::string& guid) { |
486 GenericRequest<std::string>* request = | 506 GenericRequest<std::string>* request = |
487 new GenericRequest<std::string>( | 507 new GenericRequest<std::string>( |
488 this, GetNextRequestHandle(), NULL, guid); | 508 this, GetNextRequestHandle(), NULL, guid); |
489 RegisterRequest(request); | 509 RegisterRequest(request); |
490 ScheduleTask(Bind(&WebDataService::RemoveAutofillProfileImpl, this, request)); | 510 ScheduleTask(FROM_HERE, |
511 Bind(&WebDataService::RemoveAutofillProfileImpl, this, request)); | |
491 } | 512 } |
492 | 513 |
493 WebDataService::Handle WebDataService::GetAutofillProfiles( | 514 WebDataService::Handle WebDataService::GetAutofillProfiles( |
494 WebDataServiceConsumer* consumer) { | 515 WebDataServiceConsumer* consumer) { |
495 WebDataRequest* request = | 516 WebDataRequest* request = |
496 new WebDataRequest(this, GetNextRequestHandle(), consumer); | 517 new WebDataRequest(this, GetNextRequestHandle(), consumer); |
497 RegisterRequest(request); | 518 RegisterRequest(request); |
498 ScheduleTask(Bind(&WebDataService::GetAutofillProfilesImpl, this, request)); | 519 ScheduleTask(FROM_HERE, |
520 Bind(&WebDataService::GetAutofillProfilesImpl, this, request)); | |
499 return request->GetHandle(); | 521 return request->GetHandle(); |
500 } | 522 } |
501 | 523 |
502 void WebDataService::EmptyMigrationTrash(bool notify_sync) { | 524 void WebDataService::EmptyMigrationTrash(bool notify_sync) { |
503 GenericRequest<bool>* request = | 525 GenericRequest<bool>* request = |
504 new GenericRequest<bool>( | 526 new GenericRequest<bool>( |
505 this, GetNextRequestHandle(), NULL, notify_sync); | 527 this, GetNextRequestHandle(), NULL, notify_sync); |
506 RegisterRequest(request); | 528 RegisterRequest(request); |
507 ScheduleTask(Bind(&WebDataService::EmptyMigrationTrashImpl, this, request)); | 529 ScheduleTask(FROM_HERE, |
530 Bind(&WebDataService::EmptyMigrationTrashImpl, this, request)); | |
508 } | 531 } |
509 | 532 |
510 void WebDataService::AddCreditCard(const CreditCard& credit_card) { | 533 void WebDataService::AddCreditCard(const CreditCard& credit_card) { |
511 GenericRequest<CreditCard>* request = | 534 GenericRequest<CreditCard>* request = |
512 new GenericRequest<CreditCard>( | 535 new GenericRequest<CreditCard>( |
513 this, GetNextRequestHandle(), NULL, credit_card); | 536 this, GetNextRequestHandle(), NULL, credit_card); |
514 RegisterRequest(request); | 537 RegisterRequest(request); |
515 ScheduleTask(Bind(&WebDataService::AddCreditCardImpl, this, request)); | 538 ScheduleTask(FROM_HERE, |
539 Bind(&WebDataService::AddCreditCardImpl, this, request)); | |
516 } | 540 } |
517 | 541 |
518 void WebDataService::UpdateCreditCard(const CreditCard& credit_card) { | 542 void WebDataService::UpdateCreditCard(const CreditCard& credit_card) { |
519 GenericRequest<CreditCard>* request = | 543 GenericRequest<CreditCard>* request = |
520 new GenericRequest<CreditCard>( | 544 new GenericRequest<CreditCard>( |
521 this, GetNextRequestHandle(), NULL, credit_card); | 545 this, GetNextRequestHandle(), NULL, credit_card); |
522 RegisterRequest(request); | 546 RegisterRequest(request); |
523 ScheduleTask(Bind(&WebDataService::UpdateCreditCardImpl, this, request)); | 547 ScheduleTask(FROM_HERE, |
548 Bind(&WebDataService::UpdateCreditCardImpl, this, request)); | |
524 } | 549 } |
525 | 550 |
526 void WebDataService::RemoveCreditCard(const std::string& guid) { | 551 void WebDataService::RemoveCreditCard(const std::string& guid) { |
527 GenericRequest<std::string>* request = | 552 GenericRequest<std::string>* request = |
528 new GenericRequest<std::string>( | 553 new GenericRequest<std::string>( |
529 this, GetNextRequestHandle(), NULL, guid); | 554 this, GetNextRequestHandle(), NULL, guid); |
530 RegisterRequest(request); | 555 RegisterRequest(request); |
531 ScheduleTask(Bind(&WebDataService::RemoveCreditCardImpl, this, request)); | 556 ScheduleTask(FROM_HERE, |
557 Bind(&WebDataService::RemoveCreditCardImpl, this, request)); | |
532 } | 558 } |
533 | 559 |
534 WebDataService::Handle WebDataService::GetCreditCards( | 560 WebDataService::Handle WebDataService::GetCreditCards( |
535 WebDataServiceConsumer* consumer) { | 561 WebDataServiceConsumer* consumer) { |
536 WebDataRequest* request = | 562 WebDataRequest* request = |
537 new WebDataRequest(this, GetNextRequestHandle(), consumer); | 563 new WebDataRequest(this, GetNextRequestHandle(), consumer); |
538 RegisterRequest(request); | 564 RegisterRequest(request); |
539 ScheduleTask(Bind(&WebDataService::GetCreditCardsImpl, this, request)); | 565 ScheduleTask(FROM_HERE, |
566 Bind(&WebDataService::GetCreditCardsImpl, this, request)); | |
540 return request->GetHandle(); | 567 return request->GetHandle(); |
541 } | 568 } |
542 | 569 |
543 void WebDataService::RemoveAutofillProfilesAndCreditCardsModifiedBetween( | 570 void WebDataService::RemoveAutofillProfilesAndCreditCardsModifiedBetween( |
544 const Time& delete_begin, | 571 const Time& delete_begin, |
545 const Time& delete_end) { | 572 const Time& delete_end) { |
546 GenericRequest2<Time, Time>* request = | 573 GenericRequest2<Time, Time>* request = |
547 new GenericRequest2<Time, Time>(this, | 574 new GenericRequest2<Time, Time>(this, |
548 GetNextRequestHandle(), | 575 GetNextRequestHandle(), |
549 NULL, | 576 NULL, |
550 delete_begin, | 577 delete_begin, |
551 delete_end); | 578 delete_end); |
552 RegisterRequest(request); | 579 RegisterRequest(request); |
553 ScheduleTask(Bind( | 580 ScheduleTask(FROM_HERE, Bind( |
554 &WebDataService::RemoveAutofillProfilesAndCreditCardsModifiedBetweenImpl, | 581 &WebDataService::RemoveAutofillProfilesAndCreditCardsModifiedBetweenImpl, |
555 this, | 582 this, request)); |
556 request)); | |
557 } | 583 } |
558 | 584 |
559 WebDataService::~WebDataService() { | 585 WebDataService::~WebDataService() { |
560 if (is_running_ && db_) { | 586 if (is_running_ && db_) { |
561 DLOG_ASSERT("WebDataService dtor called without Shutdown"); | 587 DLOG_ASSERT("WebDataService dtor called without Shutdown"); |
562 } | 588 } |
563 } | 589 } |
564 | 590 |
565 bool WebDataService::InitWithPath(const FilePath& path) { | 591 bool WebDataService::InitWithPath(const FilePath& path) { |
566 path_ = path; | 592 path_ = path; |
567 is_running_ = true; | 593 is_running_ = true; |
568 | 594 |
569 // TODO(isherman): For now, to avoid a data race on shutdown | 595 // TODO(isherman): For now, to avoid a data race on shutdown |
570 // [ http://crbug.com/100745 ], call |AutofillCountry::ApplicationLocale()| to | 596 // [ http://crbug.com/100745 ], call |AutofillCountry::ApplicationLocale()| to |
571 // cache the application locale before we try to access it on the DB thread. | 597 // cache the application locale before we try to access it on the DB thread. |
572 // This should be safe to remove once [ http://crbug.com/100845 ] is fixed. | 598 // This should be safe to remove once [ http://crbug.com/100845 ] is fixed. |
573 AutofillCountry::ApplicationLocale(); | 599 AutofillCountry::ApplicationLocale(); |
574 | 600 |
575 ScheduleTask(Bind(&WebDataService::InitializeDatabaseIfNecessary, this)); | 601 ScheduleTask(FROM_HERE, |
576 ScheduleTask(Bind(&WebDataService::InitializeSyncableServices, this)); | 602 Bind(&WebDataService::InitializeDatabaseIfNecessary, this)); |
603 ScheduleTask(FROM_HERE, | |
604 Bind(&WebDataService::InitializeSyncableServices, this)); | |
577 return true; | 605 return true; |
578 } | 606 } |
579 | 607 |
580 void WebDataService::RequestCompleted(Handle h) { | 608 void WebDataService::RequestCompleted(Handle h) { |
581 pending_lock_.Acquire(); | 609 pending_lock_.Acquire(); |
582 RequestMap::iterator i = pending_requests_.find(h); | 610 RequestMap::iterator i = pending_requests_.find(h); |
583 if (i == pending_requests_.end()) { | 611 if (i == pending_requests_.end()) { |
584 NOTREACHED() << "Request completed called for an unknown request"; | 612 NOTREACHED() << "Request completed called for an unknown request"; |
585 pending_lock_.Release(); | 613 pending_lock_.Release(); |
586 return; | 614 return; |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
704 if (should_commit_) { | 732 if (should_commit_) { |
705 should_commit_ = false; | 733 should_commit_ = false; |
706 | 734 |
707 if (db_) { | 735 if (db_) { |
708 db_->CommitTransaction(); | 736 db_->CommitTransaction(); |
709 db_->BeginTransaction(); | 737 db_->BeginTransaction(); |
710 } | 738 } |
711 } | 739 } |
712 } | 740 } |
713 | 741 |
714 void WebDataService::ScheduleTask(const base::Closure& task) { | 742 void WebDataService::ScheduleTask( |
743 const tracked_objects::Location& from_here, const base::Closure& task) { | |
sky
2011/11/30 17:59:58
nit: each param on own line.
erikwright (departed)
2011/11/30 20:13:54
Done.
| |
715 if (is_running_) | 744 if (is_running_) |
716 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, task); | 745 BrowserThread::PostTask(BrowserThread::DB, from_here, task); |
717 else | 746 else |
718 NOTREACHED() << "Task scheduled after Shutdown()"; | 747 NOTREACHED() << "Task scheduled after Shutdown()"; |
719 } | 748 } |
720 | 749 |
721 void WebDataService::ScheduleCommit() { | 750 void WebDataService::ScheduleCommit() { |
722 if (should_commit_ == false) { | 751 if (should_commit_ == false) { |
723 should_commit_ = true; | 752 should_commit_ = true; |
724 ScheduleTask(Bind(&WebDataService::Commit, this)); | 753 ScheduleTask(FROM_HERE, Bind(&WebDataService::Commit, this)); |
725 } | 754 } |
726 } | 755 } |
727 | 756 |
728 int WebDataService::GetNextRequestHandle() { | 757 int WebDataService::GetNextRequestHandle() { |
729 base::AutoLock l(pending_lock_); | 758 base::AutoLock l(pending_lock_); |
730 return ++next_request_handle_; | 759 return ++next_request_handle_; |
731 } | 760 } |
732 | 761 |
733 //////////////////////////////////////////////////////////////////////////////// | 762 //////////////////////////////////////////////////////////////////////////////// |
734 // | 763 // |
(...skipping 760 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1495 } | 1524 } |
1496 | 1525 |
1497 const WDTypedResult* WebDataService::WebDataRequest::GetResult() const { | 1526 const WDTypedResult* WebDataService::WebDataRequest::GetResult() const { |
1498 return result_; | 1527 return result_; |
1499 } | 1528 } |
1500 | 1529 |
1501 void WebDataService::WebDataRequest::RequestComplete() { | 1530 void WebDataService::WebDataRequest::RequestComplete() { |
1502 message_loop_->PostTask(FROM_HERE, Bind(&WebDataService::RequestCompleted, | 1531 message_loop_->PostTask(FROM_HERE, Bind(&WebDataService::RequestCompleted, |
1503 service_.get(), handle_)); | 1532 service_.get(), handle_)); |
1504 } | 1533 } |
OLD | NEW |