summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgroby@chromium.org <groby@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-13 03:48:42 +0000
committergroby@chromium.org <groby@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-13 03:48:42 +0000
commita3340f3d323f769460a1b269eb8198faf071e2a2 (patch)
tree8609985fe10a87e25ec2f0e004255dee97a65bfa
parentd6d70a49322b7848322d715068e29fa722e8fcd5 (diff)
downloadchromium_src-a3340f3d323f769460a1b269eb8198faf071e2a2.zip
chromium_src-a3340f3d323f769460a1b269eb8198faf071e2a2.tar.gz
chromium_src-a3340f3d323f769460a1b269eb8198faf071e2a2.tar.bz2
Added WebIntents GetAll support
R=jhawkins@chromium.org BUG=none TEST=WebIntentsTableTest.GetAllIntents,WebDataServiceTest.WebIntents.GetAll,WebIntentsRegistryTest.GetAllIntents, Review URL: http://codereview.chromium.org/7633011 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@96673 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/intents/web_intents_registry.cc14
-rw-r--r--chrome/browser/intents/web_intents_registry.h3
-rw-r--r--chrome/browser/intents/web_intents_registry_unittest.cc26
-rw-r--r--chrome/browser/webdata/web_data_service.cc24
-rw-r--r--chrome/browser/webdata/web_data_service.h4
-rw-r--r--chrome/browser/webdata/web_data_service_unittest.cc24
-rw-r--r--chrome/browser/webdata/web_intents_table.cc34
-rw-r--r--chrome/browser/webdata/web_intents_table.h3
-rw-r--r--chrome/browser/webdata/web_intents_table_unittest.cc28
9 files changed, 154 insertions, 6 deletions
diff --git a/chrome/browser/intents/web_intents_registry.cc b/chrome/browser/intents/web_intents_registry.cc
index fb51579..0e59ebf 100644
--- a/chrome/browser/intents/web_intents_registry.cc
+++ b/chrome/browser/intents/web_intents_registry.cc
@@ -70,6 +70,20 @@ WebIntentsRegistry::QueryID WebIntentsRegistry::GetIntentProviders(
return query->query_id_;
}
+WebIntentsRegistry::QueryID WebIntentsRegistry::GetAllIntentProviders(
+ Consumer* consumer) {
+ DCHECK(consumer);
+ DCHECK(wds_.get());
+
+ IntentsQuery* query = new IntentsQuery;
+ query->query_id_ = next_query_id_++;
+ query->consumer_ = consumer;
+ query->pending_query_ = wds_->GetAllWebIntents(this);
+ queries_[query->pending_query_] = query;
+
+ return query->query_id_;
+}
+
void WebIntentsRegistry::RegisterIntentProvider(const WebIntentData& intent) {
DCHECK(wds_.get());
wds_->AddWebIntent(intent);
diff --git a/chrome/browser/intents/web_intents_registry.h b/chrome/browser/intents/web_intents_registry.h
index 02ab4fd..f5d724a 100644
--- a/chrome/browser/intents/web_intents_registry.h
+++ b/chrome/browser/intents/web_intents_registry.h
@@ -47,6 +47,9 @@ class WebIntentsRegistry
// |consumer| must not be NULL.
QueryID GetIntentProviders(const string16& action, Consumer* consumer);
+ // Requests all intent providers. |consumer| must not be NULL
+ QueryID GetAllIntentProviders(Consumer* consumer);
+
protected:
// Make sure that only WebIntentsRegistryFactory can create an instance of
// WebIntentsRegistry.
diff --git a/chrome/browser/intents/web_intents_registry_unittest.cc b/chrome/browser/intents/web_intents_registry_unittest.cc
index 5a5e6f6..72460f7 100644
--- a/chrome/browser/intents/web_intents_registry_unittest.cc
+++ b/chrome/browser/intents/web_intents_registry_unittest.cc
@@ -102,3 +102,29 @@ TEST_F(WebIntentsRegistryTest, BasicTests) {
consumer.WaitForData();
EXPECT_EQ(1U, consumer.intents_.size());
}
+
+TEST_F(WebIntentsRegistryTest, GetAllIntents) {
+ WebIntentData intent;
+ intent.service_url = GURL("http://google.com");
+ intent.action = ASCIIToUTF16("share");
+ intent.type = ASCIIToUTF16("image/*");
+ intent.title = ASCIIToUTF16("Google's Sharing Service");
+ registry_.RegisterIntentProvider(intent);
+
+ intent.action = ASCIIToUTF16("search");
+ registry_.RegisterIntentProvider(intent);
+
+ TestConsumer consumer;
+ consumer.expected_id_ = registry_.GetAllIntentProviders(&consumer);
+ consumer.WaitForData();
+ ASSERT_EQ(2U, consumer.intents_.size());
+
+ if (consumer.intents_[0].action != ASCIIToUTF16("share"))
+ std::swap(consumer.intents_[0],consumer.intents_[1]);
+
+ intent.action = ASCIIToUTF16("share");
+ EXPECT_EQ(intent, consumer.intents_[0]);
+
+ intent.action = ASCIIToUTF16("search");
+ EXPECT_EQ(intent, consumer.intents_[1]);
+}
diff --git a/chrome/browser/webdata/web_data_service.cc b/chrome/browser/webdata/web_data_service.cc
index 80d75f1..5f52154 100644
--- a/chrome/browser/webdata/web_data_service.cc
+++ b/chrome/browser/webdata/web_data_service.cc
@@ -250,6 +250,18 @@ WebDataService::Handle WebDataService::GetWebIntents(const string16& action,
return request->GetHandle();
}
+WebDataService::Handle WebDataService::GetAllWebIntents(
+ WebDataServiceConsumer* consumer) {
+ DCHECK(consumer);
+ GenericRequest<std::string>* request = new GenericRequest<std::string>(
+ this, GetNextRequestHandle(), consumer, std::string());
+ RegisterRequest(request);
+ ScheduleTask(
+ NewRunnableMethod(this,
+ &WebDataService::GetAllWebIntentsImpl,
+ request));
+ return request->GetHandle();
+}
////////////////////////////////////////////////////////////////////////////////
//
@@ -861,6 +873,18 @@ void WebDataService::GetWebIntentsImpl(GenericRequest<string16>* request) {
request->RequestComplete();
}
+void WebDataService::GetAllWebIntentsImpl(
+ GenericRequest<std::string>* request) {
+ InitializeDatabaseIfNecessary();
+ if (db_ && !request->IsCancelled()) {
+ std::vector<WebIntentData> result;
+ db_->GetWebIntentsTable()->GetAllWebIntents(&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 c1a60ee..3215103 100644
--- a/chrome/browser/webdata/web_data_service.h
+++ b/chrome/browser/webdata/web_data_service.h
@@ -351,6 +351,9 @@ class WebDataService
Handle GetWebIntents(const string16& action,
WebDataServiceConsumer* consumer);
+ // Get all web intent providers registered. |consumer| must not be NULL.
+ Handle GetAllWebIntents(WebDataServiceConsumer* consumer);
+
//////////////////////////////////////////////////////////////////////////////
//
// Token Service
@@ -581,6 +584,7 @@ class WebDataService
void AddWebIntentImpl(GenericRequest<WebIntentData>* request);
void RemoveWebIntentImpl(GenericRequest<WebIntentData>* request);
void GetWebIntentsImpl(GenericRequest<string16>* request);
+ void GetAllWebIntentsImpl(GenericRequest<std::string>* request);
//////////////////////////////////////////////////////////////////////////////
//
diff --git a/chrome/browser/webdata/web_data_service_unittest.cc b/chrome/browser/webdata/web_data_service_unittest.cc
index 5c439db..33fc6e0 100644
--- a/chrome/browser/webdata/web_data_service_unittest.cc
+++ b/chrome/browser/webdata/web_data_service_unittest.cc
@@ -638,3 +638,27 @@ TEST_F(WebDataServiceTest, WebIntents) {
EXPECT_EQ(intent.type, consumer.intents[0].type);
}
+TEST_F(WebDataServiceTest, WebIntentsGetAll) {
+ WebIntentsConsumer consumer;
+
+ WebIntentData intent;
+ intent.service_url = GURL("http://google.com");
+ intent.action = ASCIIToUTF16("share");
+ intent.type = ASCIIToUTF16("image/*");
+ wds_->AddWebIntent(intent);
+
+ intent.action = ASCIIToUTF16("edit");
+ wds_->AddWebIntent(intent);
+
+ wds_->GetAllWebIntents(&consumer);
+ WebIntentsConsumer::WaitUntilCalled();
+ ASSERT_EQ(2U, consumer.intents.size());
+
+ if (consumer.intents[0].action != ASCIIToUTF16("edit"))
+ std::swap(consumer.intents[0],consumer.intents[1]);
+
+ EXPECT_EQ(intent, consumer.intents[0]);
+ intent.action = ASCIIToUTF16("share");
+ EXPECT_EQ(intent, consumer.intents[1]);
+}
+
diff --git a/chrome/browser/webdata/web_intents_table.cc b/chrome/browser/webdata/web_intents_table.cc
index 4d59a8f..03060ed 100644
--- a/chrome/browser/webdata/web_intents_table.cc
+++ b/chrome/browser/webdata/web_intents_table.cc
@@ -69,6 +69,28 @@ bool WebIntentsTable::GetWebIntents(const string16& action,
return true;
}
+bool WebIntentsTable::GetAllWebIntents(std::vector<WebIntentData>* intents) {
+ DCHECK(intents);
+ sql::Statement s(db_->GetUniqueStatement(
+ "SELECT service_url, action, type FROM web_intents"));
+ if (!s) {
+ NOTREACHED() << "Statement prepare failed";
+ return false;
+ }
+
+ while (s.Step()) {
+ WebIntentData intent;
+ string16 tmp = s.ColumnString16(0);
+ intent.service_url = GURL(tmp);
+
+ intent.action = s.ColumnString16(1);
+ intent.type = s.ColumnString16(2);
+
+ intents->push_back(intent);
+ }
+ return true;
+}
+
bool WebIntentsTable::SetWebIntent(const WebIntentData& intent) {
sql::Statement s(db_->GetUniqueStatement(
"INSERT OR REPLACE INTO web_intents (service_url, type, action, title) "
@@ -89,17 +111,17 @@ bool WebIntentsTable::SetWebIntent(const WebIntentData& intent) {
// |intent.service_url|. It's unlikely the user will be given the ability to
// remove at the granularity of actions or types.
bool WebIntentsTable::RemoveWebIntent(const WebIntentData& intent) {
- sql::Statement delete_s(db_->GetUniqueStatement(
+ sql::Statement s(db_->GetUniqueStatement(
"DELETE FROM web_intents "
"WHERE service_url = ? AND action = ? AND type = ?"));
- if (!delete_s) {
+ if (!s) {
NOTREACHED() << "Statement prepare failed";
return false;
}
- delete_s.BindString(0, intent.service_url.spec());
- delete_s.BindString16(1, intent.action);
- delete_s.BindString16(2, intent.type);
- return delete_s.Run();
+ s.BindString(0, intent.service_url.spec());
+ s.BindString16(1, intent.action);
+ s.BindString16(2, intent.type);
+ return s.Run();
}
diff --git a/chrome/browser/webdata/web_intents_table.h b/chrome/browser/webdata/web_intents_table.h
index 7142fb9..65fd56b 100644
--- a/chrome/browser/webdata/web_intents_table.h
+++ b/chrome/browser/webdata/web_intents_table.h
@@ -46,6 +46,9 @@ class WebIntentsTable : public WebDatabaseTable {
bool GetWebIntents(const string16& action,
std::vector<WebIntentData>* intents);
+ // Retrieve all intents from WebIntents table.
+ bool GetAllWebIntents(std::vector<WebIntentData>* intents);
+
// Removes intent from WebIntents table - must match all parameters exactly.
bool RemoveWebIntent(const WebIntentData& intent);
diff --git a/chrome/browser/webdata/web_intents_table_unittest.cc b/chrome/browser/webdata/web_intents_table_unittest.cc
index f6367bc..6955aff 100644
--- a/chrome/browser/webdata/web_intents_table_unittest.cc
+++ b/chrome/browser/webdata/web_intents_table_unittest.cc
@@ -18,6 +18,7 @@ namespace {
GURL test_url("http://google.com/");
string16 test_action = ASCIIToUTF16("http://webintents.org/intents/share");
+string16 test_action_2 = ASCIIToUTF16("http://webintents.org/intents/view");
string16 mime_image = ASCIIToUTF16("image/*");
string16 mime_video = ASCIIToUTF16("video/*");
@@ -92,4 +93,31 @@ TEST_F(WebIntentsTableTest, SetMultipleIntents) {
intent.type = mime_image;
EXPECT_EQ(intent, intents[0]);
}
+
+// Test we support getting all intents independent of action.
+TEST_F(WebIntentsTableTest, GetAllIntents) {
+ std::vector<WebIntentData> intents;
+
+ WebIntentData intent;
+ intent.service_url = test_url;
+ intent.action = test_action;
+ intent.type = mime_image;
+ EXPECT_TRUE(IntentsTable()->SetWebIntent(intent));
+
+ intent.action = test_action_2;
+ EXPECT_TRUE(IntentsTable()->SetWebIntent(intent));
+
+ // Recover stored intents from DB.
+ EXPECT_TRUE(IntentsTable()->GetAllWebIntents(&intents));
+ ASSERT_EQ(2U, intents.size());
+
+ // WebIntentsTable does not guarantee order, so ensure order here.
+ if (intents[0].type == test_action_2)
+ std::swap(intents[0], intents[1]);
+
+ EXPECT_EQ(intent, intents[1]);
+
+ intent.action = test_action;
+ EXPECT_EQ(intent, intents[0]);
+}
} // namespace