Commit a3340f3d authored by groby@chromium.org's avatar groby@chromium.org

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
parent d6d70a49
......@@ -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);
......
......@@ -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.
......
......@@ -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]);
}
......@@ -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.
......
......@@ -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);
//////////////////////////////////////////////////////////////////////////////
//
......
......@@ -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]);
}
......@@ -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();
}
......@@ -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);
......
......@@ -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
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