Commit 978ccb43 authored by caitkp@chromium.org's avatar caitkp@chromium.org

Move WebDataRequest management code into a separate class

(which can be reused when WebDataService is broken up).

TBR=ben@chromium.org (for gyp changes)
TEST=No visible change
BUG=166488



Review URL: https://chromiumcodereview.appspot.com/11761016

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@175965 0039d316-1c4b-4281-b951-d872f2087c98
parent 6efc9e52
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/api/webdata/web_data_results.h"
// TODO(caitkp): This should not live in chrome/browser/api.
WDTypedResult::WDTypedResult(WDResultType type)
: type_(type),
callback_(DestroyCallback()) {
}
WDTypedResult::WDTypedResult(WDResultType type, const DestroyCallback& callback)
: type_(type),
callback_(callback) {
}
WDTypedResult::~WDTypedResult() {}
...@@ -6,6 +6,9 @@ ...@@ -6,6 +6,9 @@
#define CHROME_BROWSER_API_WEBDATA_WEB_DATA_RESULTS_H_ #define CHROME_BROWSER_API_WEBDATA_WEB_DATA_RESULTS_H_
#include "base/basictypes.h" #include "base/basictypes.h"
#include "base/callback.h"
class WDTypedResult;
// //
// Result types for WebDataService. // Result types for WebDataService.
...@@ -29,32 +32,47 @@ typedef enum { ...@@ -29,32 +32,47 @@ typedef enum {
WEB_INTENTS_DEFAULTS_RESULT, // WDResult<std::vector<DefaultWebIntentService>> WEB_INTENTS_DEFAULTS_RESULT, // WDResult<std::vector<DefaultWebIntentService>>
} WDResultType; } WDResultType;
typedef base::Callback<void(const WDTypedResult*)> DestroyCallback;
// //
// The top level class for a result. // The top level class for a result.
// //
class WDTypedResult { class WDTypedResult {
public: public:
virtual ~WDTypedResult() {} virtual ~WDTypedResult();
// Return the result type. // Return the result type.
WDResultType GetType() const { WDResultType GetType() const {
return type_; return type_;
} }
protected: void Destroy() const {
explicit WDTypedResult(WDResultType type) : type_(type) { if (!callback_.is_null()) {
callback_.Run(this);
}
} }
protected:
explicit WDTypedResult(WDResultType type);
WDTypedResult(WDResultType type, const DestroyCallback& callback);
private: private:
WDResultType type_; WDResultType type_;
DestroyCallback callback_;
DISALLOW_COPY_AND_ASSIGN(WDTypedResult); DISALLOW_COPY_AND_ASSIGN(WDTypedResult);
}; };
// A result containing one specific pointer or literal value. // A result containing one specific pointer or literal value.
template <class T> class WDResult : public WDTypedResult { template <class T> class WDResult : public WDTypedResult {
public: public:
WDResult(WDResultType type, const T& v)
: WDTypedResult(type), value_(v) {
}
WDResult(WDResultType type, const T& v) : WDTypedResult(type), value_(v) { WDResult(WDResultType type, const DestroyCallback& callback, const T& v)
: WDTypedResult(type, callback), value_(v) {
} }
virtual ~WDResult() { virtual ~WDResult() {
...@@ -73,7 +91,12 @@ template <class T> class WDResult : public WDTypedResult { ...@@ -73,7 +91,12 @@ template <class T> class WDResult : public WDTypedResult {
template <class T> class WDObjectResult : public WDTypedResult { template <class T> class WDObjectResult : public WDTypedResult {
public: public:
explicit WDObjectResult(WDResultType type) : WDTypedResult(type) { explicit WDObjectResult(WDResultType type)
: WDTypedResult(type) {
}
WDObjectResult(WDResultType type, const DestroyCallback& callback)
: WDTypedResult(type, callback) {
} }
T* GetValue() const { T* GetValue() const {
......
// Copyright 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/webdata/web_data_request_manager.h"
#include "base/bind.h"
#include "base/message_loop.h"
#include "base/stl_util.h"
#include "chrome/browser/autofill/autofill_profile.h"
#include "chrome/browser/autofill/credit_card.h"
#include "chrome/browser/webdata/web_data_service.h"
////////////////////////////////////////////////////////////////////////////////
//
// WebDataRequest implementation.
//
////////////////////////////////////////////////////////////////////////////////
WebDataRequest::WebDataRequest(WebDataService* service,
WebDataServiceConsumer* consumer,
WebDataRequestManager* manager)
: service_(service),
cancelled_(false),
consumer_(consumer),
result_(NULL) {
handle_ = manager->GetNextRequestHandle();
message_loop_ = MessageLoop::current();
manager->RegisterRequest(this);
}
WebDataRequest::~WebDataRequest() {
delete result_;
}
WebDataService::Handle WebDataRequest::GetHandle() const {
return handle_;
}
WebDataServiceConsumer* WebDataRequest::GetConsumer() const {
return consumer_;
}
bool WebDataRequest::IsCancelled() const {
base::AutoLock l(cancel_lock_);
return cancelled_;
}
void WebDataRequest::Cancel() {
base::AutoLock l(cancel_lock_);
cancelled_ = true;
consumer_ = NULL;
}
void WebDataRequest::SetResult(WDTypedResult* r) {
result_ = r;
}
const WDTypedResult* WebDataRequest::GetResult() const {
return result_;
}
void WebDataRequest::RequestComplete() {
message_loop_->PostTask(FROM_HERE, Bind(&WebDataService::RequestCompleted,
service_.get(), handle_));
}
////////////////////////////////////////////////////////////////////////////////
//
// WebDataRequestManager implementation.
//
////////////////////////////////////////////////////////////////////////////////
WebDataRequestManager::WebDataRequestManager()
: next_request_handle_(1) {
}
WebDataRequestManager::~WebDataRequestManager() {
}
void WebDataRequestManager::RegisterRequest(WebDataRequest* request) {
base::AutoLock l(pending_lock_);
pending_requests_[request->GetHandle()] = request;
}
int WebDataRequestManager::GetNextRequestHandle() {
base::AutoLock l(pending_lock_);
return ++next_request_handle_;
}
void WebDataRequestManager::CancelRequest(WebDataServiceBase::Handle h) {
base::AutoLock l(pending_lock_);
RequestMap::iterator i = pending_requests_.find(h);
if (i == pending_requests_.end()) {
NOTREACHED() << "Canceling a nonexistent web data service request";
return;
}
i->second->Cancel();
}
void WebDataRequestManager::RequestCompleted(WebDataServiceBase::Handle h) {
pending_lock_.Acquire();
RequestMap::iterator i = pending_requests_.find(h);
if (i == pending_requests_.end()) {
NOTREACHED() << "Request completed called for an unknown request";
pending_lock_.Release();
return;
}
// Take ownership of the request object and remove it from the map.
scoped_ptr<WebDataRequest> request(i->second);
pending_requests_.erase(i);
pending_lock_.Release();
// Notify the consumer if needed.
WebDataServiceConsumer* consumer = request->GetConsumer();
if (!request->IsCancelled() && consumer) {
consumer->OnWebDataServiceRequestDone(request->GetHandle(),
request->GetResult());
} else {
// Nobody is taken ownership of the result, either because it is cancelled
// or there is no consumer. Destroy results that require special handling.
WDTypedResult const *result = request->GetResult();
if (result) {
result->Destroy();
}
}
}
// Copyright 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Chromium settings and storage represent user-selected preferences and
// information and MUST not be extracted, overwritten or modified except
// through Chromium defined APIs.
#ifndef CHROME_BROWSER_WEBDATA_WEB_DATA_REQUEST_MANAGER_H__
#define CHROME_BROWSER_WEBDATA_WEB_DATA_REQUEST_MANAGER_H__
#include <map>
#include "base/memory/ref_counted.h"
#include "base/synchronization/lock.h"
#include "chrome/browser/api/webdata/web_data_results.h"
#include "chrome/browser/api/webdata/web_data_service_base.h"
#include "chrome/browser/api/webdata/web_data_service_consumer.h"
class MessageLoop;
class WebDataService;
class WebDataServiceConsumer;
class WebDataRequestManager;
//////////////////////////////////////////////////////////////////////////////
//
// Webdata requests
//
// Every request is processed using a request object. The object contains
// both the request parameters and the results.
//////////////////////////////////////////////////////////////////////////////
class WebDataRequest {
public:
WebDataRequest(WebDataService* service,
WebDataServiceConsumer* consumer,
WebDataRequestManager* manager);
virtual ~WebDataRequest();
WebDataServiceBase::Handle GetHandle() const;
// Retrieves the |consumer_| set in the constructor.
WebDataServiceConsumer* GetConsumer() const;
// Returns |true| if the request was cancelled via the |Cancel()| method.
bool IsCancelled() const;
// This can be invoked from any thread. From this point we assume that
// our consumer_ reference is invalid.
void Cancel();
// Invoked by the service when this request has been completed.
// This will notify the service in whatever thread was used to create this
// request.
void RequestComplete();
// The result is owned by the request.
void SetResult(WDTypedResult* r);
const WDTypedResult* GetResult() const;
private:
// Used to notify service of request completion.
scoped_refptr<WebDataService> service_;
// Tracks loop that the request originated on.
MessageLoop* message_loop_;
// Identifier for this request.
WebDataServiceBase::Handle handle_;
// A lock to protect against simultaneous cancellations of the request.
// Cancellation affects both the |cancelled_| flag and |consumer_|.
mutable base::Lock cancel_lock_;
bool cancelled_;
// The originator of the service request.
WebDataServiceConsumer* consumer_;
WDTypedResult* result_;
DISALLOW_COPY_AND_ASSIGN(WebDataRequest);
};
//////////////////////////////////////////////////////////////////////////////
//
// Webdata request templates
//
// Internally we use instances of the following template to represent
// requests.
//////////////////////////////////////////////////////////////////////////////
template <class T>
class GenericRequest : public WebDataRequest {
public:
GenericRequest(WebDataService* service,
WebDataServiceConsumer* consumer,
WebDataRequestManager* manager,
const T& arg)
: WebDataRequest(service, consumer, manager),
arg_(arg) {
}
virtual ~GenericRequest() {
}
const T& arg() const { return arg_; }
private:
T arg_;
};
template <class T, class U>
class GenericRequest2 : public WebDataRequest {
public:
GenericRequest2(WebDataService* service,
WebDataServiceConsumer* consumer,
WebDataRequestManager* manager,
const T& arg1,
const U& arg2)
: WebDataRequest(service, consumer, manager),
arg1_(arg1),
arg2_(arg2) {
}
virtual ~GenericRequest2() { }
const T& arg1() const { return arg1_; }
const U& arg2() const { return arg2_; }
private:
T arg1_;
U arg2_;
};
//////////////////////////////////////////////////////////////////////////////
//
// Webdata Request Manager
//
// Tracks all WebDataRequests for a WebDataService.
//
// Note: This is an internal interface, not to be used outside of webdata/
//////////////////////////////////////////////////////////////////////////////
class WebDataRequestManager {
public:
WebDataRequestManager();
~WebDataRequestManager();
// Cancel any pending request.
void CancelRequest(WebDataServiceBase::Handle h);
// Invoked by request implementations when a request has been processed.
void RequestCompleted(WebDataServiceBase::Handle h);
// Register the request as a pending request.
void RegisterRequest(WebDataRequest* request);
// Return the next request handle.
int GetNextRequestHandle();
private:
// A lock to protect pending requests and next request handle.
base::Lock pending_lock_;
// Next handle to be used for requests. Incremented for each use.
WebDataServiceBase::Handle next_request_handle_;
typedef std::map<WebDataServiceBase::Handle, WebDataRequest*> RequestMap;
RequestMap pending_requests_;
DISALLOW_COPY_AND_ASSIGN(WebDataRequestManager);
};
#endif // CHROME_BROWSER_WEBDATA_WEB_DATA_REQUEST_MANAGER_H__
...@@ -84,7 +84,6 @@ WebDataService::WebDataService() ...@@ -84,7 +84,6 @@ WebDataService::WebDataService()
autofill_profile_syncable_service_(NULL), autofill_profile_syncable_service_(NULL),
failed_init_(false), failed_init_(false),
should_commit_(false), should_commit_(false),
next_request_handle_(1),
main_loop_(MessageLoop::current()) { main_loop_(MessageLoop::current()) {
// WebDataService requires DB thread if instantiated. // WebDataService requires DB thread if instantiated.
// Set WebDataServiceFactory::GetInstance()->SetTestingFactory(&profile, NULL) // Set WebDataServiceFactory::GetInstance()->SetTestingFactory(&profile, NULL)
...@@ -127,13 +126,7 @@ void WebDataService::UnloadDatabase() { ...@@ -127,13 +126,7 @@ void WebDataService::UnloadDatabase() {
} }
void WebDataService::CancelRequest(Handle h) { void WebDataService::CancelRequest(Handle h) {
base::AutoLock l(pending_lock_); request_manager_.CancelRequest(h);
RequestMap::iterator i = pending_requests_.find(h);
if (i == pending_requests_.end()) {
NOTREACHED() << "Canceling a nonexistent web data service request";
return;
}
i->second->Cancel();
} }
content::NotificationSource WebDataService::GetNotificationSource() { content::NotificationSource WebDataService::GetNotificationSource() {
...@@ -157,25 +150,22 @@ WebDatabase* WebDataService::GetDatabase() { ...@@ -157,25 +150,22 @@ WebDatabase* WebDataService::GetDatabase() {
void WebDataService::AddKeyword(const TemplateURLData& data) { void WebDataService::AddKeyword(const TemplateURLData& data) {
GenericRequest<TemplateURLData>* request = GenericRequest<TemplateURLData>* request =
new GenericRequest<TemplateURLData>(this, GetNextRequestHandle(), NULL, new GenericRequest<TemplateURLData>(
data); this, NULL, &request_manager_, data);
RegisterRequest(request);
ScheduleTask(FROM_HERE, Bind(&WebDataService::AddKeywordImpl, this, request)); ScheduleTask(FROM_HERE, Bind(&WebDataService::AddKeywordImpl, this, request));
} }
void WebDataService::RemoveKeyword(TemplateURLID id) { void WebDataService::RemoveKeyword(TemplateURLID id) {
GenericRequest<TemplateURLID>* request = GenericRequest<TemplateURLID>* request =
new GenericRequest<TemplateURLID>(this, GetNextRequestHandle(), NULL, id); new GenericRequest<TemplateURLID>(this, NULL, &request_manager_, id);
RegisterRequest(request);
ScheduleTask(FROM_HERE, ScheduleTask(FROM_HERE,
Bind(&WebDataService::RemoveKeywordImpl, this, request)); Bind(&WebDataService::RemoveKeywordImpl, this, request));
} }
void WebDataService::UpdateKeyword(const TemplateURLData& data) { void WebDataService::UpdateKeyword(const TemplateURLData& data) {
GenericRequest<TemplateURLData>* request = GenericRequest<TemplateURLData>* request =
new GenericRequest<TemplateURLData>(this, GetNextRequestHandle(), NULL, new GenericRequest<TemplateURLData>(
data); this, NULL, &request_manager_, data);
RegisterRequest(request);
ScheduleTask(FROM_HERE, ScheduleTask(FROM_HERE,
Bind(&WebDataService::UpdateKeywordImpl, this, request)); Bind(&WebDataService::UpdateKeywordImpl, this, request));
} }
...@@ -183,8 +173,7 @@ void WebDataService::UpdateKeyword(const TemplateURLData& data) { ...@@ -183,8 +173,7 @@ void WebDataService::UpdateKeyword(const TemplateURLData& data) {
WebDataService::Handle WebDataService::GetKeywords( WebDataService::Handle WebDataService::GetKeywords(
WebDataServiceConsumer* consumer) { WebDataServiceConsumer* consumer) {
WebDataRequest* request = WebDataRequest* request =
new WebDataRequest(this, GetNextRequestHandle(), consumer); new WebDataRequest(this, consumer, &request_manager_);
RegisterRequest(request);
ScheduleTask(FROM_HERE, ScheduleTask(FROM_HERE,
Bind(&WebDataService::GetKeywordsImpl, this, request)); Bind(&WebDataService::GetKeywordsImpl, this, request));
return request->GetHandle(); return request->GetHandle();
...@@ -192,16 +181,14 @@ WebDataService::Handle WebDataService::GetKeywords( ...@@ -192,16 +181,14 @@ WebDataService::Handle WebDataService::GetKeywords(
void WebDataService::SetDefaultSearchProvider(const TemplateURL* url) { void WebDataService::SetDefaultSearchProvider(const TemplateURL* url) {
GenericRequest<TemplateURLID>* request = new GenericRequest<TemplateURLID>( GenericRequest<TemplateURLID>* request = new GenericRequest<TemplateURLID>(
this, GetNextRequestHandle(), NULL, url ? url->id() : 0); this, NULL, &request_manager_, url ? url->id() : 0);
RegisterRequest(request);
ScheduleTask(FROM_HERE, Bind(&WebDataService::SetDefaultSearchProviderImpl, ScheduleTask(FROM_HERE, Bind(&WebDataService::SetDefaultSearchProviderImpl,
this, request)); this, request));
} }
void WebDataService::SetBuiltinKeywordVersion(int version) { void WebDataService::SetBuiltinKeywordVersion(int version) {
GenericRequest<int>* request = GenericRequest<int>* request = new GenericRequest<int>(
new GenericRequest<int>(this, GetNextRequestHandle(), NULL, version); this, NULL, &request_manager_, version);
RegisterRequest(request);
ScheduleTask(FROM_HERE, Bind(&WebDataService::SetBuiltinKeywordVersionImpl, ScheduleTask(FROM_HERE, Bind(&WebDataService::SetBuiltinKeywordVersionImpl,
this, request)); this, request));
} }
...@@ -215,9 +202,8 @@ void WebDataService::SetBuiltinKeywordVersion(int version) { ...@@ -215,9 +202,8 @@ void WebDataService::SetBuiltinKeywordVersion(int version) {
void WebDataService::SetWebAppImage(const GURL& app_url, void WebDataService::SetWebAppImage(const GURL& app_url,
const SkBitmap& image) { const SkBitmap& image) {
GenericRequest2<GURL, SkBitmap>* request = GenericRequest2<GURL, SkBitmap>* request =
new GenericRequest2<GURL, SkBitmap>(this, GetNextRequestHandle(), new GenericRequest2<GURL, SkBitmap>(
NULL, app_url, image); this, NULL, &request_manager_, app_url, image);
RegisterRequest(request);
ScheduleTask(FROM_HERE, ScheduleTask(FROM_HERE,
Bind(&WebDataService::SetWebAppImageImpl, this, request)); Bind(&WebDataService::SetWebAppImageImpl, this, request));
} }
...@@ -225,17 +211,15 @@ void WebDataService::SetWebAppImage(const GURL& app_url, ...@@ -225,17 +211,15 @@ void WebDataService::SetWebAppImage(const GURL& app_url,
void WebDataService::SetWebAppHasAllImages(const GURL& app_url, void WebDataService::SetWebAppHasAllImages(const GURL& app_url,
bool has_all_images) { bool has_all_images) {
GenericRequest2<GURL, bool>* request = GenericRequest2<GURL, bool>* request =
new GenericRequest2<GURL, bool>(this, GetNextRequestHandle(), new GenericRequest2<GURL, bool>(
NULL, app_url, has_all_images); this, NULL, &request_manager_, app_url, has_all_images);
RegisterRequest(request);
ScheduleTask(FROM_HERE, ScheduleTask(FROM_HERE,
Bind(&WebDataService::SetWebAppHasAllImagesImpl, this, request)); Bind(&WebDataService::SetWebAppHasAllImagesImpl, this, request));
} }
void WebDataService::RemoveWebApp(const GURL& app_url) { void WebDataService::RemoveWebApp(const GURL& app_url) {
GenericRequest<GURL>* request = GenericRequest<GURL>* request =
new GenericRequest<GURL>(this, GetNextRequestHandle(), NULL, app_url); new GenericRequest<GURL>(this, NULL, &request_manager_, app_url);
RegisterRequest(request);
ScheduleTask(FROM_HERE, ScheduleTask(FROM_HERE,
Bind(&WebDataService::RemoveWebAppImpl, this, request)); Bind(&WebDataService::RemoveWebAppImpl, this, request));
} }
...@@ -244,8 +228,7 @@ WebDataService::Handle WebDataService::GetWebAppImages( ...@@ -244,8 +228,7 @@ WebDataService::Handle WebDataService::GetWebAppImages(
const GURL& app_url, const GURL& app_url,
WebDataServiceConsumer* consumer) { WebDataServiceConsumer* consumer) {
GenericRequest<GURL>* request = GenericRequest<GURL>* request =
new GenericRequest<GURL>(this, GetNextRequestHandle(), consumer, app_url); new GenericRequest<GURL>(this, consumer, &request_manager_, app_url);
RegisterRequest(request);
ScheduleTask(FROM_HERE, ScheduleTask(FROM_HERE,
Bind(&WebDataService::GetWebAppImagesImpl, this, request)); Bind(&WebDataService::GetWebAppImagesImpl, this, request));
return request->GetHandle(); return request->GetHandle();
...@@ -260,8 +243,7 @@ WebDataService::Handle WebDataService::GetWebAppImages( ...@@ -260,8 +243,7 @@ WebDataService::Handle WebDataService::GetWebAppImages(
void WebDataService::AddWebIntentService(const WebIntentServiceData& service) { void WebDataService::AddWebIntentService(const WebIntentServiceData& service) {
GenericRequest<WebIntentServiceData>* request = GenericRequest<WebIntentServiceData>* request =
new GenericRequest<WebIntentServiceData>( new GenericRequest<WebIntentServiceData>(
this, GetNextRequestHandle(), NULL, service); this, NULL, &request_manager_, service);
RegisterRequest(request);
ScheduleTask(FROM_HERE, ScheduleTask(FROM_HERE,
Bind(&WebDataService::AddWebIntentServiceImpl, this, request)); Bind(&WebDataService::AddWebIntentServiceImpl, this, request));
} }
...@@ -270,8 +252,7 @@ void WebDataService::RemoveWebIntentService( ...@@ -270,8 +252,7 @@ void WebDataService::RemoveWebIntentService(
const WebIntentServiceData& service) { const WebIntentServiceData& service) {
GenericRequest<WebIntentServiceData>* request = GenericRequest<WebIntentServiceData>* request =
new GenericRequest<WebIntentServiceData>( new GenericRequest<WebIntentServiceData>(
this, GetNextRequestHandle(), NULL, service); this, NULL, &request_manager_, service);
RegisterRequest(request);
ScheduleTask(FROM_HERE, Bind(&WebDataService::RemoveWebIntentServiceImpl, ScheduleTask(FROM_HERE, Bind(&WebDataService::RemoveWebIntentServiceImpl,
this, request)); this, request));
} }
...@@ -280,9 +261,9 @@ WebDataService::Handle WebDataService::GetWebIntentServicesForAction( ...@@ -280,9 +261,9 @@ WebDataService::Handle WebDataService::GetWebIntentServicesForAction(
const string16& action, const string16& action,
WebDataServiceConsumer* consumer) { WebDataServiceConsumer* consumer) {
DCHECK(consumer); DCHECK(consumer);
GenericRequest<string16>* request = new GenericRequest<string16>( GenericRequest<string16>* request =
this, GetNextRequestHandle(), consumer, action); new GenericRequest<string16>(
RegisterRequest(request); this, consumer, &request_manager_, action);
ScheduleTask(FROM_HERE, ScheduleTask(FROM_HERE,
Bind(&WebDataService::GetWebIntentServicesImpl, this, request)); Bind(&WebDataService::GetWebIntentServicesImpl, this, request));
return request->GetHandle(); return request->GetHandle();
...@@ -292,9 +273,9 @@ WebDataService::Handle WebDataService::GetWebIntentServicesForURL( ...@@ -292,9 +273,9 @@ WebDataService::Handle WebDataService::GetWebIntentServicesForURL(
const string16& service_url, const string16& service_url,
WebDataServiceConsumer* consumer) { WebDataServiceConsumer* consumer) {
DCHECK(consumer); DCHECK(consumer);
GenericRequest<string16>* request = new GenericRequest<string16>( GenericRequest<string16>* request =
this, GetNextRequestHandle(), consumer, service_url); new GenericRequest<string16>(
RegisterRequest(request); this, consumer, &request_manager_, service_url);
ScheduleTask(FROM_HERE, Bind(&WebDataService::GetWebIntentServicesForURLImpl, ScheduleTask(FROM_HERE, Bind(&WebDataService::GetWebIntentServicesForURLImpl,
this, request)); this, request));
return request->GetHandle(); return request->GetHandle();
...@@ -304,9 +285,9 @@ WebDataService::Handle WebDataService::GetWebIntentServicesForURL( ...@@ -304,9 +285,9 @@ WebDataService::Handle WebDataService::GetWebIntentServicesForURL(
WebDataService::Handle WebDataService::GetAllWebIntentServices( WebDataService::Handle WebDataService::GetAllWebIntentServices(
WebDataServiceConsumer* consumer) { WebDataServiceConsumer* consumer) {
DCHECK(consumer); DCHECK(consumer);
GenericRequest<std::string>* request = new GenericRequest<std::string>( GenericRequest<std::string>* request =
this, GetNextRequestHandle(), consumer, std::string()); new GenericRequest<std::string>(
RegisterRequest(request); this, consumer, &request_manager_, std::string());
ScheduleTask(FROM_HERE, Bind(&WebDataService::GetAllWebIntentServicesImpl, ScheduleTask(FROM_HERE, Bind(&WebDataService::GetAllWebIntentServicesImpl,
this, request)); this, request));
return request->GetHandle(); return request->GetHandle();
...@@ -316,8 +297,7 @@ void WebDataService::AddDefaultWebIntentService( ...@@ -316,8 +297,7 @@ void WebDataService::AddDefaultWebIntentService(
const DefaultWebIntentService& service) { const DefaultWebIntentService& service) {
GenericRequest<DefaultWebIntentService>* request = GenericRequest<DefaultWebIntentService>* request =
new GenericRequest<DefaultWebIntentService>( new GenericRequest<DefaultWebIntentService>(
this, GetNextRequestHandle(), NULL, service); this, NULL, &request_manager_, service);
RegisterRequest(request);
ScheduleTask(FROM_HERE, ScheduleTask(FROM_HERE,
Bind(&WebDataService::AddDefaultWebIntentServiceImpl, this, Bind(&WebDataService::AddDefaultWebIntentServiceImpl, this,
request)); request));
...@@ -327,8 +307,7 @@ void WebDataService::RemoveDefaultWebIntentService( ...@@ -327,8 +307,7 @@ void WebDataService::RemoveDefaultWebIntentService(
const DefaultWebIntentService& service) { const DefaultWebIntentService& service) {
GenericRequest<DefaultWebIntentService>* request = GenericRequest<DefaultWebIntentService>* request =
new GenericRequest<DefaultWebIntentService>( new GenericRequest<DefaultWebIntentService>(
this, GetNextRequestHandle(), NULL, service); this, NULL, &request_manager_, service);
RegisterRequest(request);
ScheduleTask(FROM_HERE, ScheduleTask(FROM_HERE,
Bind(&WebDataService::RemoveDefaultWebIntentServiceImpl, this, Bind(&WebDataService::RemoveDefaultWebIntentServiceImpl, this,
request)); request));
...@@ -337,9 +316,7 @@ void WebDataService::RemoveDefaultWebIntentService( ...@@ -337,9 +316,7 @@ void WebDataService::RemoveDefaultWebIntentService(
void WebDataService::RemoveWebIntentServiceDefaults( void WebDataService::RemoveWebIntentServiceDefaults(
const GURL& service_url) { const GURL& service_url) {
GenericRequest<GURL>* request = GenericRequest<GURL>* request =
new GenericRequest<GURL>( new GenericRequest<GURL>(this, NULL, &request_manager_, service_url);
this, GetNextRequestHandle(), NULL, service_url);
RegisterRequest(request);
ScheduleTask( ScheduleTask(
FROM_HERE, FROM_HERE,
Bind(&WebDataService::RemoveWebIntentServiceDefaultsImpl, this, request)); Bind(&WebDataService::RemoveWebIntentServiceDefaultsImpl, this, request));
...@@ -350,8 +327,7 @@ WebDataService::Handle WebDataService::GetDefaultWebIntentServicesForAction( ...@@ -350,8 +327,7 @@ WebDataService::Handle WebDataService::GetDefaultWebIntentServicesForAction(
WebDataServiceConsumer* consumer) { WebDataServiceConsumer* consumer) {
DCHECK(consumer); DCHECK(consumer);
GenericRequest<string16>* request = new GenericRequest<string16>( GenericRequest<string16>* request = new GenericRequest<string16>(
this, GetNextRequestHandle(), consumer, action); this, consumer, &request_manager_, action);
RegisterRequest(request);
ScheduleTask(FROM_HERE, ScheduleTask(FROM_HERE,
Bind(&WebDataService::GetDefaultWebIntentServicesForActionImpl, Bind(&WebDataService::GetDefaultWebIntentServicesForActionImpl,
this, request)); this, request));
...@@ -362,8 +338,7 @@ WebDataService::Handle WebDataService::GetAllDefaultWebIntentServices( ...@@ -362,8 +338,7 @@ WebDataService::Handle WebDataService::GetAllDefaultWebIntentServices(
WebDataServiceConsumer* consumer) { WebDataServiceConsumer* consumer) {
DCHECK(consumer); DCHECK(consumer);
GenericRequest<std::string>* request = new GenericRequest<std::string>( GenericRequest<std::string>* request = new GenericRequest<std::string>(
this, GetNextRequestHandle(), consumer, std::string()); this, consumer, &request_manager_, std::string());
RegisterRequest(request);
ScheduleTask(FROM_HERE, ScheduleTask(FROM_HERE,
Bind(&WebDataService::GetAllDefaultWebIntentServicesImpl, Bind(&WebDataService::GetAllDefaultWebIntentServicesImpl,
this, request)); this, request));
...@@ -380,8 +355,7 @@ void WebDataService::SetTokenForService(const std::string& service, ...@@ -380,8 +355,7 @@ void WebDataService::SetTokenForService(const std::string& service,
const std::string& token) { const std::string& token) {
GenericRequest2<std::string, std::string>* request = GenericRequest2<std::string, std::string>* request =
new GenericRequest2<std::string, std::string>( new GenericRequest2<std::string, std::string>(
this, GetNextRequestHandle(), NULL, service, token); this, NULL, &request_manager_, service, token);
RegisterRequest(request);
ScheduleTask(FROM_HERE, ScheduleTask(FROM_HERE,
Bind(&WebDataService::SetTokenForServiceImpl, this, request)); Bind(&WebDataService::SetTokenForServiceImpl, this, request));
} }
...@@ -389,8 +363,7 @@ void WebDataService::SetTokenForService(const std::string& service, ...@@ -389,8 +363,7 @@ void WebDataService::SetTokenForService(const std::string& service,
void WebDataService::RemoveAllTokens() { void WebDataService::RemoveAllTokens() {
GenericRequest<std::string>* request = GenericRequest<std::string>* request =
new GenericRequest<std::string>( new GenericRequest<std::string>(
this, GetNextRequestHandle(), NULL, std::string()); this, NULL, &request_manager_, std::string());
RegisterRequest(request);
ScheduleTask(FROM_HERE, ScheduleTask(FROM_HERE,
Bind(&WebDataService::RemoveAllTokensImpl, this, request)); Bind(&WebDataService::RemoveAllTokensImpl, this, request));
} }
...@@ -401,8 +374,7 @@ WebDataService::Handle WebDataService::GetAllTokens( ...@@ -401,8 +374,7 @@ WebDataService::Handle WebDataService::GetAllTokens(
GenericRequest<std::string>* request = GenericRequest<std::string>* request =
new GenericRequest<std::string>( new GenericRequest<std::string>(
this, GetNextRequestHandle(), consumer, std::string()); this, consumer, &request_manager_, std::string());
RegisterRequest(request);
ScheduleTask(FROM_HERE, ScheduleTask(FROM_HERE,
Bind(&WebDataService::GetAllTokensImpl, this, request)); Bind(&WebDataService::GetAllTokensImpl, this, request));
return request->GetHandle(); return request->GetHandle();
...@@ -418,8 +390,7 @@ void WebDataService::AddFormFields( ...@@ -418,8 +390,7 @@ void WebDataService::AddFormFields(
const std::vector<FormFieldData>& fields) { const std::vector<FormFieldData>& fields) {
GenericRequest<std::vector<FormFieldData> >* request = GenericRequest<std::vector<FormFieldData> >* request =
new GenericRequest<std::vector<FormFieldData> >( new GenericRequest<std::vector<FormFieldData> >(
this, GetNextRequestHandle(), NULL, fields); this, NULL, &request_manager_, fields);
RegisterRequest(request);
ScheduleTask(FROM_HERE, ScheduleTask(FROM_HERE,
Bind(&WebDataService::AddFormElementsImpl, this, request)); Bind(&WebDataService::AddFormElementsImpl, this, request));
} }
...@@ -428,8 +399,7 @@ WebDataService::Handle WebDataService::GetFormValuesForElementName( ...@@ -428,8 +399,7 @@ WebDataService::Handle WebDataService::GetFormValuesForElementName(
const string16& name, const string16& prefix, int limit, const string16& name, const string16& prefix, int limit,
WebDataServiceConsumer* consumer) { WebDataServiceConsumer* consumer) {
WebDataRequest* request = WebDataRequest* request =
new WebDataRequest(this, GetNextRequestHandle(), consumer); new WebDataRequest(this, consumer, &request_manager_);
RegisterRequest(request);
ScheduleTask(FROM_HERE, ScheduleTask(FROM_HERE,
Bind(&WebDataService::GetFormValuesForElementNameImpl, Bind(&WebDataService::GetFormValuesForElementNameImpl,
this, request, name, prefix, limit)); this, request, name, prefix, limit));
...@@ -439,12 +409,8 @@ WebDataService::Handle WebDataService::GetFormValuesForElementName( ...@@ -439,12 +409,8 @@ WebDataService::Handle WebDataService::GetFormValuesForElementName(
void WebDataService::RemoveFormElementsAddedBetween(const Time& delete_begin, void WebDataService::RemoveFormElementsAddedBetween(const Time& delete_begin,
const Time& delete_end) { const Time& delete_end) {
GenericRequest2<Time, Time>* request = GenericRequest2<Time, Time>* request =
new GenericRequest2<Time, Time>(this, new GenericRequest2<Time, Time>(
GetNextRequestHandle(), this, NULL, &request_manager_, delete_begin, delete_end);
NULL,
delete_begin,
delete_end);
RegisterRequest(request);
ScheduleTask(FROM_HERE, ScheduleTask(FROM_HERE,
Bind(&WebDataService::RemoveFormElementsAddedBetweenImpl, Bind(&WebDataService::RemoveFormElementsAddedBetweenImpl,
this, request)); this, request));
...@@ -452,8 +418,7 @@ void WebDataService::RemoveFormElementsAddedBetween(const Time& delete_begin, ...@@ -452,8 +418,7 @@ void WebDataService::RemoveFormElementsAddedBetween(const Time& delete_begin,
void WebDataService::RemoveExpiredFormElements() { void WebDataService::RemoveExpiredFormElements() {
WebDataRequest* request = WebDataRequest* request =
new WebDataRequest(this, GetNextRequestHandle(), NULL); new WebDataRequest(this, NULL, &request_manager_);
RegisterRequest(request);
ScheduleTask(FROM_HERE, ScheduleTask(FROM_HERE,
Bind(&WebDataService::RemoveExpiredFormElementsImpl, Bind(&WebDataService::RemoveExpiredFormElementsImpl,
this, request)); this, request));
...@@ -462,11 +427,8 @@ void WebDataService::RemoveExpiredFormElements() { ...@@ -462,11 +427,8 @@ void WebDataService::RemoveExpiredFormElements() {
void WebDataService::RemoveFormValueForElementName( void WebDataService::RemoveFormValueForElementName(
const string16& name, const string16& value) { const string16& name, const string16& value) {
GenericRequest2<string16, string16>* request = GenericRequest2<string16, string16>* request =
new GenericRequest2<string16, string16>(this, new GenericRequest2<string16, string16>(
GetNextRequestHandle(), this, NULL, &request_manager_, name, value);
NULL,
name, value);
RegisterRequest(request);
ScheduleTask(FROM_HERE, ScheduleTask(FROM_HERE,
Bind(&WebDataService::RemoveFormValueForElementNameImpl, Bind(&WebDataService::RemoveFormValueForElementNameImpl,
this, request)); this, request));
...@@ -475,8 +437,7 @@ void WebDataService::RemoveFormValueForElementName( ...@@ -475,8 +437,7 @@ void WebDataService::RemoveFormValueForElementName(
void WebDataService::AddAutofillProfile(const AutofillProfile& profile) { void WebDataService::AddAutofillProfile(const AutofillProfile& profile) {
GenericRequest<AutofillProfile>* request = GenericRequest<AutofillProfile>* request =
new GenericRequest<AutofillProfile>( new GenericRequest<AutofillProfile>(
this, GetNextRequestHandle(), NULL, profile); this, NULL, &request_manager_, profile);
RegisterRequest(request);
ScheduleTask(FROM_HERE, ScheduleTask(FROM_HERE,
Bind(&WebDataService::AddAutofillProfileImpl, this, request)); Bind(&WebDataService::AddAutofillProfileImpl, this, request));
} }
...@@ -484,17 +445,14 @@ void WebDataService::AddAutofillProfile(const AutofillProfile& profile) { ...@@ -484,17 +445,14 @@ void WebDataService::AddAutofillProfile(const AutofillProfile& profile) {
void WebDataService::UpdateAutofillProfile(const AutofillProfile& profile) { void WebDataService::UpdateAutofillProfile(const AutofillProfile& profile) {
GenericRequest<AutofillProfile>* request = GenericRequest<AutofillProfile>* request =
new GenericRequest<AutofillProfile>( new GenericRequest<AutofillProfile>(
this, GetNextRequestHandle(), NULL, profile); this, NULL, &request_manager_, profile);
RegisterRequest(request);
ScheduleTask(FROM_HERE, ScheduleTask(FROM_HERE,
Bind(&WebDataService::UpdateAutofillProfileImpl, this, request)); Bind(&WebDataService::UpdateAutofillProfileImpl, this, request));
} }
void WebDataService::RemoveAutofillProfile(const std::string& guid) { void WebDataService::RemoveAutofillProfile(const std::string& guid) {
GenericRequest<std::string>* request = GenericRequest<std::string>* request =
new GenericRequest<std::string>( new GenericRequest<std::string>(this, NULL, &request_manager_, guid);
this, GetNextRequestHandle(), NULL, guid);
RegisterRequest(request);
ScheduleTask(FROM_HERE, ScheduleTask(FROM_HERE,
Bind(&WebDataService::RemoveAutofillProfileImpl, this, request)); Bind(&WebDataService::RemoveAutofillProfileImpl, this, request));
} }
...@@ -502,8 +460,7 @@ void WebDataService::RemoveAutofillProfile(const std::string& guid) { ...@@ -502,8 +460,7 @@ void WebDataService::RemoveAutofillProfile(const std::string& guid) {
WebDataService::Handle WebDataService::GetAutofillProfiles( WebDataService::Handle WebDataService::GetAutofillProfiles(
WebDataServiceConsumer* consumer) { WebDataServiceConsumer* consumer) {
WebDataRequest* request = WebDataRequest* request =
new WebDataRequest(this, GetNextRequestHandle(), consumer); new WebDataRequest(this, consumer, &request_manager_);
RegisterRequest(request);
ScheduleTask(FROM_HERE, ScheduleTask(FROM_HERE,
Bind(&WebDataService::GetAutofillProfilesImpl, this, request)); Bind(&WebDataService::GetAutofillProfilesImpl, this, request));
return request->GetHandle(); return request->GetHandle();
...@@ -511,9 +468,7 @@ WebDataService::Handle WebDataService::GetAutofillProfiles( ...@@ -511,9 +468,7 @@ WebDataService::Handle WebDataService::GetAutofillProfiles(
void WebDataService::EmptyMigrationTrash(bool notify_sync) { void WebDataService::EmptyMigrationTrash(bool notify_sync) {
GenericRequest<bool>* request = GenericRequest<bool>* request =
new GenericRequest<bool>( new GenericRequest<bool>(this, NULL, &request_manager_, notify_sync);
this, GetNextRequestHandle(), NULL, notify_sync);
RegisterRequest(request);
ScheduleTask(FROM_HERE, ScheduleTask(FROM_HERE,
Bind(&WebDataService::EmptyMigrationTrashImpl, this, request)); Bind(&WebDataService::EmptyMigrationTrashImpl, this, request));
} }
...@@ -521,8 +476,7 @@ void WebDataService::EmptyMigrationTrash(bool notify_sync) { ...@@ -521,8 +476,7 @@ void WebDataService::EmptyMigrationTrash(bool notify_sync) {
void WebDataService::AddCreditCard(const CreditCard& credit_card) { void WebDataService::AddCreditCard(const CreditCard& credit_card) {
GenericRequest<CreditCard>* request = GenericRequest<CreditCard>* request =
new GenericRequest<CreditCard>( new GenericRequest<CreditCard>(
this, GetNextRequestHandle(), NULL, credit_card); this, NULL, &request_manager_, credit_card);
RegisterRequest(request);
ScheduleTask(FROM_HERE, ScheduleTask(FROM_HERE,
Bind(&WebDataService::AddCreditCardImpl, this, request)); Bind(&WebDataService::AddCreditCardImpl, this, request));
} }
...@@ -530,17 +484,14 @@ void WebDataService::AddCreditCard(const CreditCard& credit_card) { ...@@ -530,17 +484,14 @@ void WebDataService::AddCreditCard(const CreditCard& credit_card) {
void WebDataService::UpdateCreditCard(const CreditCard& credit_card) { void WebDataService::UpdateCreditCard(const CreditCard& credit_card) {
GenericRequest<CreditCard>* request = GenericRequest<CreditCard>* request =
new GenericRequest<CreditCard>( new GenericRequest<CreditCard>(
this, GetNextRequestHandle(), NULL, credit_card); this, NULL, &request_manager_, credit_card);
RegisterRequest(request);
ScheduleTask(FROM_HERE, ScheduleTask(FROM_HERE,
Bind(&WebDataService::UpdateCreditCardImpl, this, request)); Bind(&WebDataService::UpdateCreditCardImpl, this, request));
} }
void WebDataService::RemoveCreditCard(const std::string& guid) { void WebDataService::RemoveCreditCard(const std::string& guid) {
GenericRequest<std::string>* request = GenericRequest<std::string>* request =
new GenericRequest<std::string>( new GenericRequest<std::string>(this, NULL, &request_manager_, guid);
this, GetNextRequestHandle(), NULL, guid);
RegisterRequest(request);
ScheduleTask(FROM_HERE, ScheduleTask(FROM_HERE,
Bind(&WebDataService::RemoveCreditCardImpl, this, request)); Bind(&WebDataService::RemoveCreditCardImpl, this, request));
} }
...@@ -548,8 +499,7 @@ void WebDataService::RemoveCreditCard(const std::string& guid) { ...@@ -548,8 +499,7 @@ void WebDataService::RemoveCreditCard(const std::string& guid) {
WebDataService::Handle WebDataService::GetCreditCards( WebDataService::Handle WebDataService::GetCreditCards(
WebDataServiceConsumer* consumer) { WebDataServiceConsumer* consumer) {
WebDataRequest* request = WebDataRequest* request =
new WebDataRequest(this, GetNextRequestHandle(), consumer); new WebDataRequest(this, consumer, &request_manager_);
RegisterRequest(request);
ScheduleTask(FROM_HERE, ScheduleTask(FROM_HERE,
Bind(&WebDataService::GetCreditCardsImpl, this, request)); Bind(&WebDataService::GetCreditCardsImpl, this, request));
return request->GetHandle(); return request->GetHandle();
...@@ -559,12 +509,8 @@ void WebDataService::RemoveAutofillProfilesAndCreditCardsModifiedBetween( ...@@ -559,12 +509,8 @@ void WebDataService::RemoveAutofillProfilesAndCreditCardsModifiedBetween(
const Time& delete_begin, const Time& delete_begin,
const Time& delete_end) { const Time& delete_end) {
GenericRequest2<Time, Time>* request = GenericRequest2<Time, Time>* request =
new GenericRequest2<Time, Time>(this, new GenericRequest2<Time, Time>(
GetNextRequestHandle(), this, NULL, &request_manager_, delete_begin, delete_end);
NULL,
delete_begin,
delete_end);
RegisterRequest(request);
ScheduleTask(FROM_HERE, Bind( ScheduleTask(FROM_HERE, Bind(
&WebDataService::RemoveAutofillProfilesAndCreditCardsModifiedBetweenImpl, &WebDataService::RemoveAutofillProfilesAndCreditCardsModifiedBetweenImpl,
this, request)); this, request));
...@@ -597,49 +543,7 @@ bool WebDataService::InitWithPath(const FilePath& path) { ...@@ -597,49 +543,7 @@ bool WebDataService::InitWithPath(const FilePath& path) {
} }
void WebDataService::RequestCompleted(Handle h) { void WebDataService::RequestCompleted(Handle h) {
pending_lock_.Acquire(); request_manager_.RequestCompleted(h);
RequestMap::iterator i = pending_requests_.find(h);
if (i == pending_requests_.end()) {
NOTREACHED() << "Request completed called for an unknown request";
pending_lock_.Release();
return;
}
// Take ownership of the request object and remove it from the map.
scoped_ptr<WebDataRequest> request(i->second);
pending_requests_.erase(i);
pending_lock_.Release();
// Notify the consumer if needed.
WebDataServiceConsumer* consumer = NULL;
if (!request->IsCancelled(&consumer) && consumer) {
consumer->OnWebDataServiceRequestDone(request->GetHandle(),
request->GetResult());
} else {
// Nobody is taken ownership of the result, either because it is cancelled
// or there is no consumer. Destroy results that require special handling.
WDTypedResult const *result = request->GetResult();
if (result) {
if (result->GetType() == AUTOFILL_PROFILES_RESULT) {
const WDResult<std::vector<AutofillProfile*> >* r =
static_cast<const WDResult<std::vector<AutofillProfile*> >*>(
result);
std::vector<AutofillProfile*> profiles = r->GetValue();
STLDeleteElements(&profiles);
} else if (result->GetType() == AUTOFILL_CREDITCARDS_RESULT) {
const WDResult<std::vector<CreditCard*> >* r =
static_cast<const WDResult<std::vector<CreditCard*> >*>(result);
std::vector<CreditCard*> credit_cards = r->GetValue();
STLDeleteElements(&credit_cards);
}
}
}
}
void WebDataService::RegisterRequest(WebDataRequest* request) {
base::AutoLock l(pending_lock_);
pending_requests_[request->GetHandle()] = request;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
...@@ -746,11 +650,6 @@ void WebDataService::ScheduleCommit() { ...@@ -746,11 +650,6 @@ void WebDataService::ScheduleCommit() {
} }
} }
int WebDataService::GetNextRequestHandle() {
base::AutoLock l(pending_lock_);
return ++next_request_handle_;
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// //
// Keywords implementation. // Keywords implementation.
...@@ -759,7 +658,7 @@ int WebDataService::GetNextRequestHandle() { ...@@ -759,7 +658,7 @@ int WebDataService::GetNextRequestHandle() {
void WebDataService::AddKeywordImpl(GenericRequest<TemplateURLData>* request) { void WebDataService::AddKeywordImpl(GenericRequest<TemplateURLData>* request) {
InitializeDatabaseIfNecessary(); InitializeDatabaseIfNecessary();
if (db_ && !request->IsCancelled(NULL)) { if (db_ && !request->IsCancelled()) {
db_->GetKeywordTable()->AddKeyword(request->arg()); db_->GetKeywordTable()->AddKeyword(request->arg());
ScheduleCommit(); ScheduleCommit();
} }
...@@ -768,7 +667,7 @@ void WebDataService::AddKeywordImpl(GenericRequest<TemplateURLData>* request) { ...@@ -768,7 +667,7 @@ void WebDataService::AddKeywordImpl(GenericRequest<TemplateURLData>* request) {
void WebDataService::RemoveKeywordImpl(GenericRequest<TemplateURLID>* request) { void WebDataService::RemoveKeywordImpl(GenericRequest<TemplateURLID>* request) {
InitializeDatabaseIfNecessary(); InitializeDatabaseIfNecessary();
if (db_ && !request->IsCancelled(NULL)) { if (db_ && !request->IsCancelled()) {
DCHECK(request->arg()); DCHECK(request->arg());
db_->GetKeywordTable()->RemoveKeyword(request->arg()); db_->GetKeywordTable()->RemoveKeyword(request->arg());
ScheduleCommit(); ScheduleCommit();
...@@ -779,7 +678,7 @@ void WebDataService::RemoveKeywordImpl(GenericRequest<TemplateURLID>* request) { ...@@ -779,7 +678,7 @@ void WebDataService::RemoveKeywordImpl(GenericRequest<TemplateURLID>* request) {
void WebDataService::UpdateKeywordImpl( void WebDataService::UpdateKeywordImpl(
GenericRequest<TemplateURLData>* request) { GenericRequest<TemplateURLData>* request) {
InitializeDatabaseIfNecessary(); InitializeDatabaseIfNecessary();
if (db_ && !request->IsCancelled(NULL)) { if (db_ && !request->IsCancelled()) {
if (!db_->GetKeywordTable()->UpdateKeyword(request->arg())) { if (!db_->GetKeywordTable()->UpdateKeyword(request->arg())) {
NOTREACHED(); NOTREACHED();
return; return;
...@@ -791,7 +690,7 @@ void WebDataService::UpdateKeywordImpl( ...@@ -791,7 +690,7 @@ void WebDataService::UpdateKeywordImpl(
void WebDataService::GetKeywordsImpl(WebDataRequest* request) { void WebDataService::GetKeywordsImpl(WebDataRequest* request) {
InitializeDatabaseIfNecessary(); InitializeDatabaseIfNecessary();
if (db_ && !request->IsCancelled(NULL)) { if (db_ && !request->IsCancelled()) {
WDKeywordsResult result; WDKeywordsResult result;
db_->GetKeywordTable()->GetKeywords(&result.keywords); db_->GetKeywordTable()->GetKeywords(&result.keywords);
result.default_search_provider_id = result.default_search_provider_id =
...@@ -807,7 +706,7 @@ void WebDataService::GetKeywordsImpl(WebDataRequest* request) { ...@@ -807,7 +706,7 @@ void WebDataService::GetKeywordsImpl(WebDataRequest* request) {
void WebDataService::SetDefaultSearchProviderImpl( void WebDataService::SetDefaultSearchProviderImpl(
GenericRequest<TemplateURLID>* request) { GenericRequest<TemplateURLID>* request) {
InitializeDatabaseIfNecessary(); InitializeDatabaseIfNecessary();
if (db_ && !request->IsCancelled(NULL)) { if (db_ && !request->IsCancelled()) {
if (!db_->GetKeywordTable()->SetDefaultSearchProviderID(request->arg())) { if (!db_->GetKeywordTable()->SetDefaultSearchProviderID(request->arg())) {
NOTREACHED(); NOTREACHED();
return; return;
...@@ -820,7 +719,7 @@ void WebDataService::SetDefaultSearchProviderImpl( ...@@ -820,7 +719,7 @@ void WebDataService::SetDefaultSearchProviderImpl(
void WebDataService::SetBuiltinKeywordVersionImpl( void WebDataService::SetBuiltinKeywordVersionImpl(
GenericRequest<int>* request) { GenericRequest<int>* request) {
InitializeDatabaseIfNecessary(); InitializeDatabaseIfNecessary();
if (db_ && !request->IsCancelled(NULL)) { if (db_ && !request->IsCancelled()) {
if (!db_->GetKeywordTable()->SetBuiltinKeywordVersion(request->arg())) { if (!db_->GetKeywordTable()->SetBuiltinKeywordVersion(request->arg())) {
NOTREACHED(); NOTREACHED();
return; return;
...@@ -839,7 +738,7 @@ void WebDataService::SetBuiltinKeywordVersionImpl( ...@@ -839,7 +738,7 @@ void WebDataService::SetBuiltinKeywordVersionImpl(
void WebDataService::SetWebAppImageImpl( void WebDataService::SetWebAppImageImpl(
GenericRequest2<GURL, SkBitmap>* request) { GenericRequest2<GURL, SkBitmap>* request) {
InitializeDatabaseIfNecessary(); InitializeDatabaseIfNecessary();
if (db_ && !request->IsCancelled(NULL)) { if (db_ && !request->IsCancelled()) {
db_->GetWebAppsTable()->SetWebAppImage( db_->GetWebAppsTable()->SetWebAppImage(
request->arg1(), request->arg2()); request->arg1(), request->arg2());
ScheduleCommit(); ScheduleCommit();
...@@ -850,7 +749,7 @@ void WebDataService::SetWebAppImageImpl( ...@@ -850,7 +749,7 @@ void WebDataService::SetWebAppImageImpl(
void WebDataService::SetWebAppHasAllImagesImpl( void WebDataService::SetWebAppHasAllImagesImpl(
GenericRequest2<GURL, bool>* request) { GenericRequest2<GURL, bool>* request) {
InitializeDatabaseIfNecessary(); InitializeDatabaseIfNecessary();
if (db_ && !request->IsCancelled(NULL)) { if (db_ && !request->IsCancelled()) {
db_->GetWebAppsTable()->SetWebAppHasAllImages(request->arg1(), db_->GetWebAppsTable()->SetWebAppHasAllImages(request->arg1(),
request->arg2()); request->arg2());
ScheduleCommit(); ScheduleCommit();
...@@ -860,7 +759,7 @@ void WebDataService::SetWebAppHasAllImagesImpl( ...@@ -860,7 +759,7 @@ void WebDataService::SetWebAppHasAllImagesImpl(
void WebDataService::RemoveWebAppImpl(GenericRequest<GURL>* request) { void WebDataService::RemoveWebAppImpl(GenericRequest<GURL>* request) {
InitializeDatabaseIfNecessary(); InitializeDatabaseIfNecessary();
if (db_ && !request->IsCancelled(NULL)) { if (db_ && !request->IsCancelled()) {
db_->GetWebAppsTable()->RemoveWebApp(request->arg()); db_->GetWebAppsTable()->RemoveWebApp(request->arg());
ScheduleCommit(); ScheduleCommit();
} }
...@@ -869,7 +768,7 @@ void WebDataService::RemoveWebAppImpl(GenericRequest<GURL>* request) { ...@@ -869,7 +768,7 @@ void WebDataService::RemoveWebAppImpl(GenericRequest<GURL>* request) {
void WebDataService::GetWebAppImagesImpl(GenericRequest<GURL>* request) { void WebDataService::GetWebAppImagesImpl(GenericRequest<GURL>* request) {
InitializeDatabaseIfNecessary(); InitializeDatabaseIfNecessary();
if (db_ && !request->IsCancelled(NULL)) { if (db_ && !request->IsCancelled()) {
WDAppImagesResult result; WDAppImagesResult result;
result.has_all_images = result.has_all_images =
db_->GetWebAppsTable()->GetWebAppHasAllImages(request->arg()); db_->GetWebAppsTable()->GetWebAppHasAllImages(request->arg());
...@@ -889,7 +788,7 @@ void WebDataService::GetWebAppImagesImpl(GenericRequest<GURL>* request) { ...@@ -889,7 +788,7 @@ void WebDataService::GetWebAppImagesImpl(GenericRequest<GURL>* request) {
void WebDataService::RemoveWebIntentServiceImpl( void WebDataService::RemoveWebIntentServiceImpl(
GenericRequest<WebIntentServiceData>* request) { GenericRequest<WebIntentServiceData>* request) {
InitializeDatabaseIfNecessary(); InitializeDatabaseIfNecessary();
if (db_ && !request->IsCancelled(NULL)) { if (db_ && !request->IsCancelled()) {
const WebIntentServiceData& service = request->arg(); const WebIntentServiceData& service = request->arg();
db_->GetWebIntentsTable()->RemoveWebIntentService(service); db_->GetWebIntentsTable()->RemoveWebIntentService(service);
ScheduleCommit(); ScheduleCommit();
...@@ -900,7 +799,7 @@ void WebDataService::RemoveWebIntentServiceImpl( ...@@ -900,7 +799,7 @@ void WebDataService::RemoveWebIntentServiceImpl(
void WebDataService::AddWebIntentServiceImpl( void WebDataService::AddWebIntentServiceImpl(
GenericRequest<WebIntentServiceData>* request) { GenericRequest<WebIntentServiceData>* request) {
InitializeDatabaseIfNecessary(); InitializeDatabaseIfNecessary();
if (db_ && !request->IsCancelled(NULL)) { if (db_ && !request->IsCancelled()) {
const WebIntentServiceData& service = request->arg(); const WebIntentServiceData& service = request->arg();
db_->GetWebIntentsTable()->SetWebIntentService(service); db_->GetWebIntentsTable()->SetWebIntentService(service);
ScheduleCommit(); ScheduleCommit();
...@@ -912,7 +811,7 @@ void WebDataService::AddWebIntentServiceImpl( ...@@ -912,7 +811,7 @@ void WebDataService::AddWebIntentServiceImpl(
void WebDataService::GetWebIntentServicesImpl( void WebDataService::GetWebIntentServicesImpl(
GenericRequest<string16>* request) { GenericRequest<string16>* request) {
InitializeDatabaseIfNecessary(); InitializeDatabaseIfNecessary();
if (db_ && !request->IsCancelled(NULL)) { if (db_ && !request->IsCancelled()) {
std::vector<WebIntentServiceData> result; std::vector<WebIntentServiceData> result;
db_->GetWebIntentsTable()->GetWebIntentServicesForAction(request->arg(), db_->GetWebIntentsTable()->GetWebIntentServicesForAction(request->arg(),
&result); &result);
...@@ -925,7 +824,7 @@ void WebDataService::GetWebIntentServicesImpl( ...@@ -925,7 +824,7 @@ void WebDataService::GetWebIntentServicesImpl(
void WebDataService::GetWebIntentServicesForURLImpl( void WebDataService::GetWebIntentServicesForURLImpl(
GenericRequest<string16>* request) { GenericRequest<string16>* request) {
InitializeDatabaseIfNecessary(); InitializeDatabaseIfNecessary();
if (db_ && !request->IsCancelled(NULL)) { if (db_ && !request->IsCancelled()) {
std::vector<WebIntentServiceData> result; std::vector<WebIntentServiceData> result;
db_->GetWebIntentsTable()->GetWebIntentServicesForURL( db_->GetWebIntentsTable()->GetWebIntentServicesForURL(
request->arg(), &result); request->arg(), &result);
...@@ -939,7 +838,7 @@ void WebDataService::GetWebIntentServicesForURLImpl( ...@@ -939,7 +838,7 @@ void WebDataService::GetWebIntentServicesForURLImpl(
void WebDataService::GetAllWebIntentServicesImpl( void WebDataService::GetAllWebIntentServicesImpl(
GenericRequest<std::string>* request) { GenericRequest<std::string>* request) {
InitializeDatabaseIfNecessary(); InitializeDatabaseIfNecessary();
if (db_ && !request->IsCancelled(NULL)) { if (db_ && !request->IsCancelled()) {
std::vector<WebIntentServiceData> result; std::vector<WebIntentServiceData> result;
db_->GetWebIntentsTable()->GetAllWebIntentServices(&result); db_->GetWebIntentsTable()->GetAllWebIntentServices(&result);
request->SetResult( request->SetResult(
...@@ -952,7 +851,7 @@ void WebDataService::GetAllWebIntentServicesImpl( ...@@ -952,7 +851,7 @@ void WebDataService::GetAllWebIntentServicesImpl(
void WebDataService::AddDefaultWebIntentServiceImpl( void WebDataService::AddDefaultWebIntentServiceImpl(
GenericRequest<DefaultWebIntentService>* request) { GenericRequest<DefaultWebIntentService>* request) {
InitializeDatabaseIfNecessary(); InitializeDatabaseIfNecessary();
if (db_ && !request->IsCancelled(NULL)) { if (db_ && !request->IsCancelled()) {
const DefaultWebIntentService& service = request->arg(); const DefaultWebIntentService& service = request->arg();
db_->GetWebIntentsTable()->SetDefaultService(service); db_->GetWebIntentsTable()->SetDefaultService(service);
ScheduleCommit(); ScheduleCommit();
...@@ -963,7 +862,7 @@ void WebDataService::AddDefaultWebIntentServiceImpl( ...@@ -963,7 +862,7 @@ void WebDataService::AddDefaultWebIntentServiceImpl(
void WebDataService::RemoveDefaultWebIntentServiceImpl( void WebDataService::RemoveDefaultWebIntentServiceImpl(
GenericRequest<DefaultWebIntentService>* request) { GenericRequest<DefaultWebIntentService>* request) {
InitializeDatabaseIfNecessary(); InitializeDatabaseIfNecessary();
if (db_ && !request->IsCancelled(NULL)) { if (db_ && !request->IsCancelled()) {
const DefaultWebIntentService& service = request->arg(); const DefaultWebIntentService& service = request->arg();
db_->GetWebIntentsTable()->RemoveDefaultService(service); db_->GetWebIntentsTable()->RemoveDefaultService(service);
ScheduleCommit(); ScheduleCommit();
...@@ -974,7 +873,7 @@ void WebDataService::RemoveDefaultWebIntentServiceImpl( ...@@ -974,7 +873,7 @@ void WebDataService::RemoveDefaultWebIntentServiceImpl(
void WebDataService::RemoveWebIntentServiceDefaultsImpl( void WebDataService::RemoveWebIntentServiceDefaultsImpl(
GenericRequest<GURL>* request) { GenericRequest<GURL>* request) {
InitializeDatabaseIfNecessary(); InitializeDatabaseIfNecessary();
if (db_ && !request->IsCancelled(NULL)) { if (db_ && !request->IsCancelled()) {
const GURL& service_url = request->arg(); const GURL& service_url = request->arg();
db_->GetWebIntentsTable()->RemoveServiceDefaults(service_url); db_->GetWebIntentsTable()->RemoveServiceDefaults(service_url);
ScheduleCommit(); ScheduleCommit();
...@@ -985,7 +884,7 @@ void WebDataService::RemoveWebIntentServiceDefaultsImpl( ...@@ -985,7 +884,7 @@ void WebDataService::RemoveWebIntentServiceDefaultsImpl(
void WebDataService::GetDefaultWebIntentServicesForActionImpl( void WebDataService::GetDefaultWebIntentServicesForActionImpl(
GenericRequest<string16>* request) { GenericRequest<string16>* request) {
InitializeDatabaseIfNecessary(); InitializeDatabaseIfNecessary();
if (db_ && !request->IsCancelled(NULL)) { if (db_ && !request->IsCancelled()) {
std::vector<DefaultWebIntentService> result; std::vector<DefaultWebIntentService> result;
db_->GetWebIntentsTable()->GetDefaultServices( db_->GetWebIntentsTable()->GetDefaultServices(
request->arg(), &result); request->arg(), &result);
...@@ -999,7 +898,7 @@ void WebDataService::GetDefaultWebIntentServicesForActionImpl( ...@@ -999,7 +898,7 @@ void WebDataService::GetDefaultWebIntentServicesForActionImpl(
void WebDataService::GetAllDefaultWebIntentServicesImpl( void WebDataService::GetAllDefaultWebIntentServicesImpl(
GenericRequest<std::string>* request) { GenericRequest<std::string>* request) {
InitializeDatabaseIfNecessary(); InitializeDatabaseIfNecessary();
if (db_ && !request->IsCancelled(NULL)) { if (db_ && !request->IsCancelled()) {
std::vector<DefaultWebIntentService> result; std::vector<DefaultWebIntentService> result;
db_->GetWebIntentsTable()->GetAllDefaultServices(&result); db_->GetWebIntentsTable()->GetAllDefaultServices(&result);
request->SetResult( request->SetResult(
...@@ -1019,7 +918,7 @@ void WebDataService::GetAllDefaultWebIntentServicesImpl( ...@@ -1019,7 +918,7 @@ void WebDataService::GetAllDefaultWebIntentServicesImpl(
void WebDataService::RemoveAllTokensImpl( void WebDataService::RemoveAllTokensImpl(
GenericRequest<std::string>* request) { GenericRequest<std::string>* request) {
InitializeDatabaseIfNecessary(); InitializeDatabaseIfNecessary();
if (db_ && !request->IsCancelled(NULL)) { if (db_ && !request->IsCancelled()) {
if (db_->GetTokenServiceTable()->RemoveAllTokens()) { if (db_->GetTokenServiceTable()->RemoveAllTokens()) {
ScheduleCommit(); ScheduleCommit();
} }
...@@ -1030,7 +929,7 @@ void WebDataService::RemoveAllTokensImpl( ...@@ -1030,7 +929,7 @@ void WebDataService::RemoveAllTokensImpl(
void WebDataService::SetTokenForServiceImpl( void WebDataService::SetTokenForServiceImpl(
GenericRequest2<std::string, std::string>* request) { GenericRequest2<std::string, std::string>* request) {
InitializeDatabaseIfNecessary(); InitializeDatabaseIfNecessary();
if (db_ && !request->IsCancelled(NULL)) { if (db_ && !request->IsCancelled()) {
if (db_->GetTokenServiceTable()->SetTokenForService( if (db_->GetTokenServiceTable()->SetTokenForService(
request->arg1(), request->arg2())) { request->arg1(), request->arg2())) {
ScheduleCommit(); ScheduleCommit();
...@@ -1043,7 +942,7 @@ void WebDataService::SetTokenForServiceImpl( ...@@ -1043,7 +942,7 @@ void WebDataService::SetTokenForServiceImpl(
void WebDataService::GetAllTokensImpl( void WebDataService::GetAllTokensImpl(
GenericRequest<std::string>* request) { GenericRequest<std::string>* request) {
InitializeDatabaseIfNecessary(); InitializeDatabaseIfNecessary();
if (db_ && !request->IsCancelled(NULL)) { if (db_ && !request->IsCancelled()) {
std::map<std::string, std::string> map; std::map<std::string, std::string> map;
db_->GetTokenServiceTable()->GetAllTokens(&map); db_->GetTokenServiceTable()->GetAllTokens(&map);
request->SetResult( request->SetResult(
...@@ -1061,7 +960,7 @@ void WebDataService::GetAllTokensImpl( ...@@ -1061,7 +960,7 @@ void WebDataService::GetAllTokensImpl(
void WebDataService::AddFormElementsImpl( void WebDataService::AddFormElementsImpl(
GenericRequest<std::vector<FormFieldData> >* request) { GenericRequest<std::vector<FormFieldData> >* request) {
InitializeDatabaseIfNecessary(); InitializeDatabaseIfNecessary();
if (db_ && !request->IsCancelled(NULL)) { if (db_ && !request->IsCancelled()) {
AutofillChangeList changes; AutofillChangeList changes;
if (!db_->GetAutofillTable()->AddFormFieldValues( if (!db_->GetAutofillTable()->AddFormFieldValues(
request->arg(), &changes)) { request->arg(), &changes)) {
...@@ -1087,7 +986,7 @@ void WebDataService::AddFormElementsImpl( ...@@ -1087,7 +986,7 @@ void WebDataService::AddFormElementsImpl(
void WebDataService::GetFormValuesForElementNameImpl(WebDataRequest* request, void WebDataService::GetFormValuesForElementNameImpl(WebDataRequest* request,
const string16& name, const string16& prefix, int limit) { const string16& name, const string16& prefix, int limit) {
InitializeDatabaseIfNecessary(); InitializeDatabaseIfNecessary();
if (db_ && !request->IsCancelled(NULL)) { if (db_ && !request->IsCancelled()) {
std::vector<string16> values; std::vector<string16> values;
db_->GetAutofillTable()->GetFormValuesForElementName( db_->GetAutofillTable()->GetFormValuesForElementName(
name, prefix, &values, limit); name, prefix, &values, limit);
...@@ -1100,7 +999,7 @@ void WebDataService::GetFormValuesForElementNameImpl(WebDataRequest* request, ...@@ -1100,7 +999,7 @@ void WebDataService::GetFormValuesForElementNameImpl(WebDataRequest* request,
void WebDataService::RemoveFormElementsAddedBetweenImpl( void WebDataService::RemoveFormElementsAddedBetweenImpl(
GenericRequest2<Time, Time>* request) { GenericRequest2<Time, Time>* request) {
InitializeDatabaseIfNecessary(); InitializeDatabaseIfNecessary();
if (db_ && !request->IsCancelled(NULL)) { if (db_ && !request->IsCancelled()) {
AutofillChangeList changes; AutofillChangeList changes;
if (db_->GetAutofillTable()->RemoveFormElementsAddedBetween( if (db_->GetAutofillTable()->RemoveFormElementsAddedBetween(
request->arg1(), request->arg2(), &changes)) { request->arg1(), request->arg2(), &changes)) {
...@@ -1124,7 +1023,7 @@ void WebDataService::RemoveFormElementsAddedBetweenImpl( ...@@ -1124,7 +1023,7 @@ void WebDataService::RemoveFormElementsAddedBetweenImpl(
void WebDataService::RemoveExpiredFormElementsImpl(WebDataRequest* request) { void WebDataService::RemoveExpiredFormElementsImpl(WebDataRequest* request) {
InitializeDatabaseIfNecessary(); InitializeDatabaseIfNecessary();
if (db_ && !request->IsCancelled(NULL)) { if (db_ && !request->IsCancelled()) {
AutofillChangeList changes; AutofillChangeList changes;
if (db_->GetAutofillTable()->RemoveExpiredFormElements(&changes)) { if (db_->GetAutofillTable()->RemoveExpiredFormElements(&changes)) {
if (!changes.empty()) { if (!changes.empty()) {
...@@ -1148,7 +1047,7 @@ void WebDataService::RemoveExpiredFormElementsImpl(WebDataRequest* request) { ...@@ -1148,7 +1047,7 @@ void WebDataService::RemoveExpiredFormElementsImpl(WebDataRequest* request) {
void WebDataService::RemoveFormValueForElementNameImpl( void WebDataService::RemoveFormValueForElementNameImpl(
GenericRequest2<string16, string16>* request) { GenericRequest2<string16, string16>* request) {
InitializeDatabaseIfNecessary(); InitializeDatabaseIfNecessary();
if (db_ && !request->IsCancelled(NULL)) { if (db_ && !request->IsCancelled()) {
const string16& name = request->arg1(); const string16& name = request->arg1();
const string16& value = request->arg2(); const string16& value = request->arg2();
...@@ -1173,7 +1072,7 @@ void WebDataService::RemoveFormValueForElementNameImpl( ...@@ -1173,7 +1072,7 @@ void WebDataService::RemoveFormValueForElementNameImpl(
void WebDataService::AddAutofillProfileImpl( void WebDataService::AddAutofillProfileImpl(
GenericRequest<AutofillProfile>* request) { GenericRequest<AutofillProfile>* request) {
InitializeDatabaseIfNecessary(); InitializeDatabaseIfNecessary();
if (db_ && !request->IsCancelled(NULL)) { if (db_ && !request->IsCancelled()) {
const AutofillProfile& profile = request->arg(); const AutofillProfile& profile = request->arg();
if (!db_->GetAutofillTable()->AddAutofillProfile(profile)) { if (!db_->GetAutofillTable()->AddAutofillProfile(profile)) {
NOTREACHED(); NOTREACHED();
...@@ -1195,7 +1094,7 @@ void WebDataService::AddAutofillProfileImpl( ...@@ -1195,7 +1094,7 @@ void WebDataService::AddAutofillProfileImpl(
void WebDataService::UpdateAutofillProfileImpl( void WebDataService::UpdateAutofillProfileImpl(
GenericRequest<AutofillProfile>* request) { GenericRequest<AutofillProfile>* request) {
InitializeDatabaseIfNecessary(); InitializeDatabaseIfNecessary();
if (db_ && !request->IsCancelled(NULL)) { if (db_ && !request->IsCancelled()) {
const AutofillProfile& profile = request->arg(); const AutofillProfile& profile = request->arg();
// Only perform the update if the profile exists. It is currently // Only perform the update if the profile exists. It is currently
...@@ -1229,7 +1128,7 @@ void WebDataService::UpdateAutofillProfileImpl( ...@@ -1229,7 +1128,7 @@ void WebDataService::UpdateAutofillProfileImpl(
void WebDataService::RemoveAutofillProfileImpl( void WebDataService::RemoveAutofillProfileImpl(
GenericRequest<std::string>* request) { GenericRequest<std::string>* request) {
InitializeDatabaseIfNecessary(); InitializeDatabaseIfNecessary();
if (db_ && !request->IsCancelled(NULL)) { if (db_ && !request->IsCancelled()) {
const std::string& guid = request->arg(); const std::string& guid = request->arg();
AutofillProfile* profile = NULL; AutofillProfile* profile = NULL;
...@@ -1257,12 +1156,13 @@ void WebDataService::RemoveAutofillProfileImpl( ...@@ -1257,12 +1156,13 @@ void WebDataService::RemoveAutofillProfileImpl(
void WebDataService::GetAutofillProfilesImpl(WebDataRequest* request) { void WebDataService::GetAutofillProfilesImpl(WebDataRequest* request) {
InitializeDatabaseIfNecessary(); InitializeDatabaseIfNecessary();
if (db_ && !request->IsCancelled(NULL)) { if (db_ && !request->IsCancelled()) {
std::vector<AutofillProfile*> profiles; std::vector<AutofillProfile*> profiles;
db_->GetAutofillTable()->GetAutofillProfiles(&profiles); db_->GetAutofillTable()->GetAutofillProfiles(&profiles);
request->SetResult( request->SetResult(
new WDResult<std::vector<AutofillProfile*> >(AUTOFILL_PROFILES_RESULT, new WDResult<std::vector<AutofillProfile*> >(AUTOFILL_PROFILES_RESULT,
profiles)); base::Bind(&WebDataService::DestroyAutofillProfileResult,
base::Unretained(this)), profiles));
} }
request->RequestComplete(); request->RequestComplete();
} }
...@@ -1270,7 +1170,7 @@ void WebDataService::GetAutofillProfilesImpl(WebDataRequest* request) { ...@@ -1270,7 +1170,7 @@ void WebDataService::GetAutofillProfilesImpl(WebDataRequest* request) {
void WebDataService::EmptyMigrationTrashImpl( void WebDataService::EmptyMigrationTrashImpl(
GenericRequest<bool>* request) { GenericRequest<bool>* request) {
InitializeDatabaseIfNecessary(); InitializeDatabaseIfNecessary();
if (db_ && !request->IsCancelled(NULL)) { if (db_ && !request->IsCancelled()) {
bool notify_sync = request->arg(); bool notify_sync = request->arg();
if (notify_sync) { if (notify_sync) {
std::vector<std::string> guids; std::vector<std::string> guids;
...@@ -1321,7 +1221,7 @@ void WebDataService::EmptyMigrationTrashImpl( ...@@ -1321,7 +1221,7 @@ void WebDataService::EmptyMigrationTrashImpl(
void WebDataService::AddCreditCardImpl( void WebDataService::AddCreditCardImpl(
GenericRequest<CreditCard>* request) { GenericRequest<CreditCard>* request) {
InitializeDatabaseIfNecessary(); InitializeDatabaseIfNecessary();
if (db_ && !request->IsCancelled(NULL)) { if (db_ && !request->IsCancelled()) {
const CreditCard& credit_card = request->arg(); const CreditCard& credit_card = request->arg();
if (!db_->GetAutofillTable()->AddCreditCard(credit_card)) { if (!db_->GetAutofillTable()->AddCreditCard(credit_card)) {
NOTREACHED(); NOTREACHED();
...@@ -1343,7 +1243,7 @@ void WebDataService::AddCreditCardImpl( ...@@ -1343,7 +1243,7 @@ void WebDataService::AddCreditCardImpl(
void WebDataService::UpdateCreditCardImpl( void WebDataService::UpdateCreditCardImpl(
GenericRequest<CreditCard>* request) { GenericRequest<CreditCard>* request) {
InitializeDatabaseIfNecessary(); InitializeDatabaseIfNecessary();
if (db_ && !request->IsCancelled(NULL)) { if (db_ && !request->IsCancelled()) {
const CreditCard& credit_card = request->arg(); const CreditCard& credit_card = request->arg();
// It is currently valid to try to update a missing profile. We simply drop // It is currently valid to try to update a missing profile. We simply drop
...@@ -1376,7 +1276,7 @@ void WebDataService::UpdateCreditCardImpl( ...@@ -1376,7 +1276,7 @@ void WebDataService::UpdateCreditCardImpl(
void WebDataService::RemoveCreditCardImpl( void WebDataService::RemoveCreditCardImpl(
GenericRequest<std::string>* request) { GenericRequest<std::string>* request) {
InitializeDatabaseIfNecessary(); InitializeDatabaseIfNecessary();
if (db_ && !request->IsCancelled(NULL)) { if (db_ && !request->IsCancelled()) {
const std::string& guid = request->arg(); const std::string& guid = request->arg();
if (!db_->GetAutofillTable()->RemoveCreditCard(guid)) { if (!db_->GetAutofillTable()->RemoveCreditCard(guid)) {
NOTREACHED(); NOTREACHED();
...@@ -1397,12 +1297,13 @@ void WebDataService::RemoveCreditCardImpl( ...@@ -1397,12 +1297,13 @@ void WebDataService::RemoveCreditCardImpl(
void WebDataService::GetCreditCardsImpl(WebDataRequest* request) { void WebDataService::GetCreditCardsImpl(WebDataRequest* request) {
InitializeDatabaseIfNecessary(); InitializeDatabaseIfNecessary();
if (db_ && !request->IsCancelled(NULL)) { if (db_ && !request->IsCancelled()) {
std::vector<CreditCard*> credit_cards; std::vector<CreditCard*> credit_cards;
db_->GetAutofillTable()->GetCreditCards(&credit_cards); db_->GetAutofillTable()->GetCreditCards(&credit_cards);
request->SetResult( request->SetResult(
new WDResult<std::vector<CreditCard*> >(AUTOFILL_CREDITCARDS_RESULT, new WDResult<std::vector<CreditCard*> >(AUTOFILL_CREDITCARDS_RESULT,
credit_cards)); base::Bind(&WebDataService::DestroyAutofillCreditCardResult,
base::Unretained(this)), credit_cards));
} }
request->RequestComplete(); request->RequestComplete();
} }
...@@ -1410,7 +1311,7 @@ void WebDataService::GetCreditCardsImpl(WebDataRequest* request) { ...@@ -1410,7 +1311,7 @@ void WebDataService::GetCreditCardsImpl(WebDataRequest* request) {
void WebDataService::RemoveAutofillProfilesAndCreditCardsModifiedBetweenImpl( void WebDataService::RemoveAutofillProfilesAndCreditCardsModifiedBetweenImpl(
GenericRequest2<Time, Time>* request) { GenericRequest2<Time, Time>* request) {
InitializeDatabaseIfNecessary(); InitializeDatabaseIfNecessary();
if (db_ && !request->IsCancelled(NULL)) { if (db_ && !request->IsCancelled()) {
std::vector<std::string> profile_guids; std::vector<std::string> profile_guids;
std::vector<std::string> credit_card_guids; std::vector<std::string> credit_card_guids;
if (db_->GetAutofillTable()-> if (db_->GetAutofillTable()->
...@@ -1462,55 +1363,20 @@ AutocompleteSyncableService* WebDataService::GetAutocompleteSyncableService() ...@@ -1462,55 +1363,20 @@ AutocompleteSyncableService* WebDataService::GetAutocompleteSyncableService()
return autocomplete_syncable_service_; return autocomplete_syncable_service_;
} }
void WebDataService::DestroyAutofillProfileResult(const WDTypedResult* result) {
//////////////////////////////////////////////////////////////////////////////// DCHECK(result->GetType() == AUTOFILL_PROFILES_RESULT);
// const WDResult<std::vector<AutofillProfile*> >* r =
// WebDataRequest implementation. static_cast<const WDResult<std::vector<AutofillProfile*> >*>(result);
// std::vector<AutofillProfile*> profiles = r->GetValue();
//////////////////////////////////////////////////////////////////////////////// STLDeleteElements(&profiles);
WebDataService::WebDataRequest::WebDataRequest(WebDataService* service,
Handle handle,
WebDataServiceConsumer* consumer)
: service_(service),
handle_(handle),
cancelled_(false),
consumer_(consumer),
result_(NULL) {
message_loop_ = MessageLoop::current();
}
WebDataService::WebDataRequest::~WebDataRequest() {
delete result_;
} }
WebDataService::Handle WebDataService::WebDataRequest::GetHandle() const { void WebDataService::DestroyAutofillCreditCardResult(
return handle_; const WDTypedResult* result) {
} DCHECK(result->GetType() == AUTOFILL_CREDITCARDS_RESULT);
const WDResult<std::vector<CreditCard*> >* r =
bool WebDataService::WebDataRequest::IsCancelled( static_cast<const WDResult<std::vector<CreditCard*> >*>(result);
WebDataServiceConsumer** consumer) const {
base::AutoLock l(cancel_lock_);
if (consumer)
*consumer = consumer_;
return cancelled_;
}
void WebDataService::WebDataRequest::Cancel() {
base::AutoLock l(cancel_lock_);
cancelled_ = true;
consumer_ = NULL;
}
void WebDataService::WebDataRequest::SetResult(WDTypedResult* r) {
result_ = r;
}
const WDTypedResult* WebDataService::WebDataRequest::GetResult() const {
return result_;
}
void WebDataService::WebDataRequest::RequestComplete() { std::vector<CreditCard*> credit_cards = r->GetValue();
message_loop_->PostTask(FROM_HERE, Bind(&WebDataService::RequestCompleted, STLDeleteElements(&credit_cards);
service_.get(), handle_));
} }
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include "chrome/browser/search_engines/template_url.h" #include "chrome/browser/search_engines/template_url.h"
#include "chrome/browser/search_engines/template_url_id.h" #include "chrome/browser/search_engines/template_url_id.h"
#include "chrome/browser/webdata/keyword_table.h" #include "chrome/browser/webdata/keyword_table.h"
#include "chrome/browser/webdata/web_data_request_manager.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "sql/init_status.h" #include "sql/init_status.h"
...@@ -100,106 +101,6 @@ class WebDataService ...@@ -100,106 +101,6 @@ class WebDataService
public AutofillWebData, public AutofillWebData,
public RefcountedProfileKeyedService { public RefcountedProfileKeyedService {
public: public:
//////////////////////////////////////////////////////////////////////////////
//
// Internal requests
//
// Every request is processed using a request object. The object contains
// both the request parameters and the results.
//////////////////////////////////////////////////////////////////////////////
class WebDataRequest {
public:
WebDataRequest(WebDataService* service,
Handle handle,
WebDataServiceConsumer* consumer);
virtual ~WebDataRequest();
Handle GetHandle() const;
// Retrieves the |consumer_| set in the constructor. If the request was
// cancelled via the |Cancel()| method then |true| is returned and
// |*consumer| is set to NULL. The |consumer| parameter may be set to NULL
// if only the return value is desired.
bool IsCancelled(WebDataServiceConsumer** consumer) const;
// This can be invoked from any thread. From this point we assume that
// our consumer_ reference is invalid.
void Cancel();
// Invoked by the service when this request has been completed.
// This will notify the service in whatever thread was used to create this
// request.
void RequestComplete();
// The result is owned by the request.
void SetResult(WDTypedResult* r);
const WDTypedResult* GetResult() const;
private:
scoped_refptr<WebDataService> service_;
MessageLoop* message_loop_;
Handle handle_;
// A lock to protect against simultaneous cancellations of the request.
// Cancellation affects both the |cancelled_| flag and |consumer_|.
mutable base::Lock cancel_lock_;
bool cancelled_;
WebDataServiceConsumer* consumer_;
WDTypedResult* result_;
DISALLOW_COPY_AND_ASSIGN(WebDataRequest);
};
//
// Internally we use instances of the following template to represent
// requests.
//
template <class T>
class GenericRequest : public WebDataRequest {
public:
GenericRequest(WebDataService* service,
Handle handle,
WebDataServiceConsumer* consumer,
const T& arg)
: WebDataRequest(service, handle, consumer),
arg_(arg) {
}
virtual ~GenericRequest() {
}
const T& arg() const { return arg_; }
private:
T arg_;
};
template <class T, class U>
class GenericRequest2 : public WebDataRequest {
public:
GenericRequest2(WebDataService* service,
Handle handle,
WebDataServiceConsumer* consumer,
const T& arg1,
const U& arg2)
: WebDataRequest(service, handle, consumer),
arg1_(arg1),
arg2_(arg2) {
}
virtual ~GenericRequest2() { }
const T& arg1() const { return arg1_; }
const U& arg2() const { return arg2_; }
private:
T arg1_;
U arg2_;
};
WebDataService(); WebDataService();
// WebDataServiceBase implementation. // WebDataServiceBase implementation.
...@@ -427,9 +328,6 @@ class WebDataService ...@@ -427,9 +328,6 @@ class WebDataService
// Invoked by request implementations when a request has been processed. // Invoked by request implementations when a request has been processed.
void RequestCompleted(Handle h); void RequestCompleted(Handle h);
// Register the request as a pending request.
void RegisterRequest(WebDataRequest* request);
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
// //
// The following methods are only invoked in the web data service thread. // The following methods are only invoked in the web data service thread.
...@@ -471,9 +369,6 @@ class WebDataService ...@@ -471,9 +369,6 @@ class WebDataService
// Schedule a commit if one is not already pending. // Schedule a commit if one is not already pending.
void ScheduleCommit(); void ScheduleCommit();
// Return the next request handle.
int GetNextRequestHandle();
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
// //
// Keywords. // Keywords.
...@@ -565,6 +460,11 @@ class WebDataService ...@@ -565,6 +460,11 @@ class WebDataService
void RemoveAutofillProfilesAndCreditCardsModifiedBetweenImpl( void RemoveAutofillProfilesAndCreditCardsModifiedBetweenImpl(
GenericRequest2<base::Time, base::Time>* request); GenericRequest2<base::Time, base::Time>* request);
// Callbacks to ensure that sensitive info is destroyed if request is
// cancelled.
void DestroyAutofillProfileResult(const WDTypedResult* result);
void DestroyAutofillCreditCardResult(const WDTypedResult* result);
// True once initialization has started. // True once initialization has started.
bool is_running_; bool is_running_;
...@@ -575,6 +475,9 @@ class WebDataService ...@@ -575,6 +475,9 @@ class WebDataService
// |db_| lifetime must be managed on the database thread. // |db_| lifetime must be managed on the database thread.
WebDatabase* db_; WebDatabase* db_;
// Keeps track of all pending requests made to the db.
WebDataRequestManager request_manager_;
// Syncable services for the database data. We own the services, but don't // Syncable services for the database data. We own the services, but don't
// use |scoped_ptr|s because the lifetimes must be managed on the database // use |scoped_ptr|s because the lifetimes must be managed on the database
// thread. // thread.
...@@ -590,15 +493,6 @@ class WebDataService ...@@ -590,15 +493,6 @@ class WebDataService
// Whether we should commit the database. // Whether we should commit the database.
bool should_commit_; bool should_commit_;
// A lock to protect pending requests and next request handle.
base::Lock pending_lock_;
// Next handle to be used for requests. Incremented for each use.
Handle next_request_handle_;
typedef std::map<Handle, WebDataRequest*> RequestMap;
RequestMap pending_requests_;
// MessageLoop the WebDataService is created on. // MessageLoop the WebDataService is created on.
MessageLoop* main_loop_; MessageLoop* main_loop_;
......
...@@ -13,18 +13,14 @@ using base::Bind; ...@@ -13,18 +13,14 @@ using base::Bind;
void WebDataService::AddIE7Login(const IE7PasswordInfo& info) { void WebDataService::AddIE7Login(const IE7PasswordInfo& info) {
GenericRequest<IE7PasswordInfo>* request = GenericRequest<IE7PasswordInfo>* request =
new GenericRequest<IE7PasswordInfo>(this, GetNextRequestHandle(), NULL, new GenericRequest<IE7PasswordInfo>(this, NULL, &request_manager_, info);
info);
RegisterRequest(request);
ScheduleTask(FROM_HERE, ScheduleTask(FROM_HERE,
Bind(&WebDataService::AddIE7LoginImpl, this, request)); Bind(&WebDataService::AddIE7LoginImpl, this, request));
} }
void WebDataService::RemoveIE7Login(const IE7PasswordInfo& info) { void WebDataService::RemoveIE7Login(const IE7PasswordInfo& info) {
GenericRequest<IE7PasswordInfo>* request = GenericRequest<IE7PasswordInfo>* request =
new GenericRequest<IE7PasswordInfo>(this, GetNextRequestHandle(), NULL, new GenericRequest<IE7PasswordInfo>(this, NULL, &request_manager_, info);
info);
RegisterRequest(request);
ScheduleTask(FROM_HERE, ScheduleTask(FROM_HERE,
Bind(&WebDataService::RemoveIE7LoginImpl, this, request)); Bind(&WebDataService::RemoveIE7LoginImpl, this, request));
} }
...@@ -33,16 +29,15 @@ WebDataService::Handle WebDataService::GetIE7Login( ...@@ -33,16 +29,15 @@ WebDataService::Handle WebDataService::GetIE7Login(
const IE7PasswordInfo& info, const IE7PasswordInfo& info,
WebDataServiceConsumer* consumer) { WebDataServiceConsumer* consumer) {
GenericRequest<IE7PasswordInfo>* request = GenericRequest<IE7PasswordInfo>* request =
new GenericRequest<IE7PasswordInfo>(this, GetNextRequestHandle(), new GenericRequest<IE7PasswordInfo>(this, consumer, &request_manager_,
consumer, info); info);
RegisterRequest(request);
ScheduleTask(FROM_HERE, ScheduleTask(FROM_HERE,
Bind(&WebDataService::GetIE7LoginImpl, this, request)); Bind(&WebDataService::GetIE7LoginImpl, this, request));
return request->GetHandle(); return request->GetHandle();
} }
void WebDataService::AddIE7LoginImpl(GenericRequest<IE7PasswordInfo>* request) { void WebDataService::AddIE7LoginImpl(GenericRequest<IE7PasswordInfo>* request) {
if (db_ && !request->IsCancelled(NULL)) { if (db_ && !request->IsCancelled()) {
if (db_->GetLoginsTable()->AddIE7Login(request->arg())) if (db_->GetLoginsTable()->AddIE7Login(request->arg()))
ScheduleCommit(); ScheduleCommit();
} }
...@@ -51,7 +46,7 @@ void WebDataService::AddIE7LoginImpl(GenericRequest<IE7PasswordInfo>* request) { ...@@ -51,7 +46,7 @@ void WebDataService::AddIE7LoginImpl(GenericRequest<IE7PasswordInfo>* request) {
void WebDataService::RemoveIE7LoginImpl( void WebDataService::RemoveIE7LoginImpl(
GenericRequest<IE7PasswordInfo>* request) { GenericRequest<IE7PasswordInfo>* request) {
if (db_ && !request->IsCancelled(NULL)) { if (db_ && !request->IsCancelled()) {
if (db_->GetLoginsTable()->RemoveIE7Login(request->arg())) if (db_->GetLoginsTable()->RemoveIE7Login(request->arg()))
ScheduleCommit(); ScheduleCommit();
} }
...@@ -60,7 +55,7 @@ void WebDataService::RemoveIE7LoginImpl( ...@@ -60,7 +55,7 @@ void WebDataService::RemoveIE7LoginImpl(
void WebDataService::GetIE7LoginImpl( void WebDataService::GetIE7LoginImpl(
GenericRequest<IE7PasswordInfo>* request) { GenericRequest<IE7PasswordInfo>* request) {
if (db_ && !request->IsCancelled(NULL)) { if (db_ && !request->IsCancelled()) {
IE7PasswordInfo result; IE7PasswordInfo result;
db_->GetLoginsTable()->GetIE7Login(request->arg(), &result); db_->GetLoginsTable()->GetIE7Login(request->arg(), &result);
request->SetResult( request->SetResult(
......
...@@ -116,6 +116,7 @@ ...@@ -116,6 +116,7 @@
'browser/api/sync/profile_sync_service_observer.h', 'browser/api/sync/profile_sync_service_observer.h',
'browser/api/webdata/autofill_web_data.h', 'browser/api/webdata/autofill_web_data.h',
'browser/api/webdata/autofill_web_data_service.h', 'browser/api/webdata/autofill_web_data_service.h',
'browser/api/webdata/web_data_results.cc',
'browser/api/webdata/web_data_results.h', 'browser/api/webdata/web_data_results.h',
'browser/api/webdata/web_data_service_base.h', 'browser/api/webdata/web_data_service_base.h',
'browser/api/webdata/web_data_service_consumer.h', 'browser/api/webdata/web_data_service_consumer.h',
...@@ -2208,6 +2209,8 @@ ...@@ -2208,6 +2209,8 @@
'browser/webdata/token_service_table.h', 'browser/webdata/token_service_table.h',
'browser/webdata/web_apps_table.cc', 'browser/webdata/web_apps_table.cc',
'browser/webdata/web_apps_table.h', 'browser/webdata/web_apps_table.h',
'browser/webdata/web_data_request_manager.cc',
'browser/webdata/web_data_request_manager.h',
'browser/webdata/web_data_service.cc', 'browser/webdata/web_data_service.cc',
'browser/webdata/web_data_service.h', 'browser/webdata/web_data_service.h',
'browser/webdata/web_data_service_factory.cc', 'browser/webdata/web_data_service_factory.cc',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment