summaryrefslogtreecommitdiffstats
path: root/chrome/browser/webdata
diff options
context:
space:
mode:
authorgroby@chromium.org <groby@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-03 00:04:28 +0000
committergroby@chromium.org <groby@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-03 00:04:28 +0000
commit2610a16a797456cdc8ef29f7210fe6e6d309f0aa (patch)
tree38ed07058fb745d15e451b9854e52d35ec90bbfe /chrome/browser/webdata
parentad283b2e2d2cf2ffdbb4c88e9b8993eae9ebf7fc (diff)
downloadchromium_src-2610a16a797456cdc8ef29f7210fe6e6d309f0aa.zip
chromium_src-2610a16a797456cdc8ef29f7210fe6e6d309f0aa.tar.gz
chromium_src-2610a16a797456cdc8ef29f7210fe6e6d309f0aa.tar.bz2
Make WebIntents table available via WebDataService
BUG=none TEST=none Review URL: http://codereview.chromium.org/7529028 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@95182 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/webdata')
-rw-r--r--chrome/browser/webdata/web_data_service.cc80
-rw-r--r--chrome/browser/webdata/web_data_service.h30
-rw-r--r--chrome/browser/webdata/web_data_service_unittest.cc72
3 files changed, 181 insertions, 1 deletions
diff --git a/chrome/browser/webdata/web_data_service.cc b/chrome/browser/webdata/web_data_service.cc
index e92864e..bc943e01 100644
--- a/chrome/browser/webdata/web_data_service.cc
+++ b/chrome/browser/webdata/web_data_service.cc
@@ -19,6 +19,7 @@
#include "chrome/browser/webdata/logins_table.h"
#include "chrome/browser/webdata/token_service_table.h"
#include "chrome/browser/webdata/web_apps_table.h"
+#include "chrome/browser/webdata/web_intents_table.h"
#include "chrome/browser/webdata/web_database.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_notification_types.h"
@@ -214,6 +215,42 @@ WebDataService::Handle WebDataService::GetWebAppImages(
return request->GetHandle();
}
+//////////////////////////////////////////////////////////////////////////////
+//
+// Web Intents.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+void WebDataService::AddWebIntent(const WebIntentData& intent) {
+ GenericRequest<WebIntentData>* request = new GenericRequest<WebIntentData>(
+ this, GetNextRequestHandle(), NULL, intent);
+ RegisterRequest(request);
+ ScheduleTask(NewRunnableMethod(this, &WebDataService::AddWebIntentImpl,
+ request));
+}
+
+void WebDataService::RemoveWebIntent(const WebIntentData& intent) {
+ GenericRequest<WebIntentData>* request = new GenericRequest<WebIntentData>(
+ this, GetNextRequestHandle(), NULL, intent);
+ RegisterRequest(request);
+ ScheduleTask(NewRunnableMethod(this, &WebDataService::RemoveWebIntentImpl,
+ request));
+}
+
+WebDataService::Handle WebDataService::GetWebIntents(const string16& action,
+ WebDataServiceConsumer* consumer) {
+ DCHECK(consumer);
+ GenericRequest<string16>* request = new GenericRequest<string16>(
+ this, GetNextRequestHandle(), consumer, action);
+ RegisterRequest(request);
+ ScheduleTask(
+ NewRunnableMethod(this,
+ &WebDataService::GetWebIntentsImpl,
+ request));
+ return request->GetHandle();
+}
+
+
////////////////////////////////////////////////////////////////////////////////
//
// Token Service
@@ -787,6 +824,49 @@ void WebDataService::GetWebAppImagesImpl(GenericRequest<GURL>* request) {
////////////////////////////////////////////////////////////////////////////////
//
+// Web Intents implementation.
+//
+////////////////////////////////////////////////////////////////////////////////
+
+void WebDataService::RemoveWebIntentImpl(
+ GenericRequest<WebIntentData>* request) {
+ InitializeDatabaseIfNecessary();
+ if (db_ && !request->IsCancelled()) {
+ const WebIntentData& intent = request->arg();
+ db_->GetWebIntentsTable()->RemoveWebIntent(intent.action,
+ intent.type,
+ intent.service_url);
+ ScheduleCommit();
+ }
+ request->RequestComplete();
+}
+
+void WebDataService::AddWebIntentImpl(GenericRequest<WebIntentData>* request) {
+ InitializeDatabaseIfNecessary();
+ if (db_ && !request->IsCancelled()) {
+ const WebIntentData& intent = request->arg();
+ db_->GetWebIntentsTable()->SetWebIntent(intent.action,
+ intent.type,
+ intent.service_url);
+ ScheduleCommit();
+ }
+ request->RequestComplete();
+}
+
+
+void WebDataService::GetWebIntentsImpl(GenericRequest<string16>* request) {
+ InitializeDatabaseIfNecessary();
+ if (db_ && !request->IsCancelled()) {
+ std::vector<WebIntentData> result;
+ db_->GetWebIntentsTable()->GetWebIntents(request->arg(), &result);
+ request->SetResult(
+ new WDResult<std::vector<WebIntentData> >(WEB_INTENTS_RESULT, result));
+ }
+ request->RequestComplete();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+//
// Token Service implementation.
//
////////////////////////////////////////////////////////////////////////////////
diff --git a/chrome/browser/webdata/web_data_service.h b/chrome/browser/webdata/web_data_service.h
index a120001..c1a60ee 100644
--- a/chrome/browser/webdata/web_data_service.h
+++ b/chrome/browser/webdata/web_data_service.h
@@ -29,6 +29,7 @@ class SkBitmap;
class Task;
class TemplateURL;
class WebDatabase;
+struct WebIntentData;
namespace base {
class Thread;
@@ -73,7 +74,8 @@ typedef enum {
AUTOFILL_PROFILE_RESULT, // WDResult<AutofillProfile>
AUTOFILL_PROFILES_RESULT, // WDResult<std::vector<AutofillProfile*>>
AUTOFILL_CREDITCARD_RESULT, // WDResult<CreditCard>
- AUTOFILL_CREDITCARDS_RESULT // WDResult<std::vector<CreditCard*>>
+ AUTOFILL_CREDITCARDS_RESULT, // WDResult<std::vector<CreditCard*>>
+ WEB_INTENTS_RESULT // WDResult<std::vector<string16>>
} WDResultType;
typedef std::vector<AutofillChange> AutofillChangeList;
@@ -334,6 +336,23 @@ class WebDataService
//////////////////////////////////////////////////////////////////////////////
//
+ // Web Intents
+ //
+ //////////////////////////////////////////////////////////////////////////////
+
+ // Adds a web intent provider registration.
+ void AddWebIntent(const WebIntentData& intent);
+
+ // Removes a web intent provider registration.
+ void RemoveWebIntent(const WebIntentData& intent);
+
+ // Get all web intent providers registered for the specified |action|.
+ // |consumer| must not be NULL.
+ Handle GetWebIntents(const string16& action,
+ WebDataServiceConsumer* consumer);
+
+ //////////////////////////////////////////////////////////////////////////////
+ //
// Token Service
//
//////////////////////////////////////////////////////////////////////////////
@@ -556,6 +575,15 @@ class WebDataService
//////////////////////////////////////////////////////////////////////////////
//
+ // Web Intents.
+ //
+ //////////////////////////////////////////////////////////////////////////////
+ void AddWebIntentImpl(GenericRequest<WebIntentData>* request);
+ void RemoveWebIntentImpl(GenericRequest<WebIntentData>* request);
+ void GetWebIntentsImpl(GenericRequest<string16>* request);
+
+ //////////////////////////////////////////////////////////////////////////////
+ //
// Token Service.
//
//////////////////////////////////////////////////////////////////////////////
diff --git a/chrome/browser/webdata/web_data_service_unittest.cc b/chrome/browser/webdata/web_data_service_unittest.cc
index 152fcb1..7a32881 100644
--- a/chrome/browser/webdata/web_data_service_unittest.cc
+++ b/chrome/browser/webdata/web_data_service_unittest.cc
@@ -24,6 +24,7 @@
#include "chrome/browser/webdata/autofill_entry.h"
#include "chrome/browser/webdata/web_data_service.h"
#include "chrome/browser/webdata/web_data_service_test_util.h"
+#include "chrome/browser/webdata/web_intents_table.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/guid.h"
@@ -151,6 +152,33 @@ class WebDataServiceAutofillTest : public WebDataServiceTest {
WaitableEvent done_event_;
};
+// Simple consumer for WebIntents data. Stores the result data and quits UI
+// message loop when callback is invoked.
+class WebIntentsConsumer: public WebDataServiceConsumer {
+ public:
+ virtual void OnWebDataServiceRequestDone(WebDataService::Handle h,
+ const WDTypedResult* result) {
+ intents.clear();
+ if (result) {
+ DCHECK(result->GetType() == WEB_INTENTS_RESULT);
+ intents = static_cast<
+ const WDResult<std::vector<WebIntentData> >*>(result)->GetValue();
+ }
+
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ MessageLoop::current()->Quit();
+ }
+
+ // Run the current message loop. OnWebDataServiceRequestDone will invoke
+ // MessageLoop::Quit on completion, so this call will finish at that point.
+ static void WaitUntilCalled() {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ MessageLoop::current()->Run();
+ }
+
+ std::vector<WebIntentData> intents; // Result data from completion callback.
+};
+
TEST_F(WebDataServiceAutofillTest, FormFillAdd) {
const AutofillChange expected_changes[] = {
AutofillChange(AutofillChange::ADD, AutofillKey(name1_, value1_)),
@@ -573,3 +601,47 @@ TEST_F(WebDataServiceAutofillTest, AutofillRemoveModifiedBetween) {
EXPECT_EQ(handle2, card_consumer2.handle());
ASSERT_EQ(0U, card_consumer2.result().size());
}
+
+TEST_F(WebDataServiceTest, WebIntents) {
+ WebIntentsConsumer consumer;
+
+ wds_->GetWebIntents(ASCIIToUTF16("share"), &consumer);
+ WebIntentsConsumer::WaitUntilCalled();
+ EXPECT_EQ(0U, consumer.intents.size());
+
+ WebIntentData intent;
+ intent.service_url = GURL("http://google.com");
+ intent.action = ASCIIToUTF16("share");
+ intent.type = ASCIIToUTF16("image/*");
+ wds_->AddWebIntent(intent);
+
+ intent.type = ASCIIToUTF16("video/*");
+ wds_->AddWebIntent(intent);
+
+ wds_->GetWebIntents(ASCIIToUTF16("share"), &consumer);
+ WebIntentsConsumer::WaitUntilCalled();
+ ASSERT_EQ(2U, consumer.intents.size());
+
+ if (consumer.intents[0].type != ASCIIToUTF16("image/*"))
+ std::swap(consumer.intents[0],consumer.intents[1]);
+
+ EXPECT_EQ(intent.service_url, consumer.intents[0].service_url);
+ EXPECT_EQ(intent.action, consumer.intents[0].action);
+ EXPECT_EQ(ASCIIToUTF16("image/*"), consumer.intents[0].type);
+ EXPECT_EQ(intent.service_url, consumer.intents[1].service_url);
+ EXPECT_EQ(intent.action, consumer.intents[1].action);
+ EXPECT_EQ(intent.type, consumer.intents[1].type);
+
+ intent.type = ASCIIToUTF16("image/*");
+ wds_->RemoveWebIntent(intent);
+
+ wds_->GetWebIntents(ASCIIToUTF16("share"), &consumer);
+ WebIntentsConsumer::WaitUntilCalled();
+ ASSERT_EQ(1U, consumer.intents.size());
+
+ intent.type = ASCIIToUTF16("video/*");
+ EXPECT_EQ(intent.service_url, consumer.intents[0].service_url);
+ EXPECT_EQ(intent.action, consumer.intents[0].action);
+ EXPECT_EQ(intent.type, consumer.intents[0].type);
+}
+