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