diff options
author | groby@chromium.org <groby@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-18 02:47:12 +0000 |
---|---|---|
committer | groby@chromium.org <groby@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-18 02:47:12 +0000 |
commit | a8bdb9ad8736e7c7260efb533ca09977d99d0857 (patch) | |
tree | a6817fb6782a07831a7a8a784740318afd21627d /chrome/browser/intents | |
parent | 32945657177a594a5ec0f4e64d6b8efbeee8eaf6 (diff) | |
download | chromium_src-a8bdb9ad8736e7c7260efb533ca09977d99d0857.zip chromium_src-a8bdb9ad8736e7c7260efb533ca09977d99d0857.tar.gz chromium_src-a8bdb9ad8736e7c7260efb533ca09977d99d0857.tar.bz2 |
Refactored WebIntentsRegistry to use callbacks instead of Consumer
BUG=
TEST=
Review URL: http://codereview.chromium.org/10033005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@132734 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/intents')
-rw-r--r-- | chrome/browser/intents/web_intents_registry.cc | 138 | ||||
-rw-r--r-- | chrome/browser/intents/web_intents_registry.h | 60 | ||||
-rw-r--r-- | chrome/browser/intents/web_intents_registry_unittest.cc | 159 |
3 files changed, 163 insertions, 194 deletions
diff --git a/chrome/browser/intents/web_intents_registry.cc b/chrome/browser/intents/web_intents_registry.cc index 6e2e4fa..ff9c139 100644 --- a/chrome/browser/intents/web_intents_registry.cc +++ b/chrome/browser/intents/web_intents_registry.cc @@ -10,6 +10,7 @@ #include "base/bind_helpers.h" #include "base/callback.h" #include "base/string_util.h" +#include "base/string16.h" #include "base/utf_string_conversions.h" #include "chrome/browser/intents/default_web_intent_service.h" #include "chrome/browser/webdata/web_data_service.h" @@ -108,6 +109,22 @@ void FilterServicesByMimetype(const string16& mimetype, } } +// Callback for existence checks. Converts a callback for a list of services +// into a callback that returns true if the list contains a specific service. +void ExistenceCallback(const webkit_glue::WebIntentServiceData& service, + const base::Callback<void(bool)>& callback, + const WebIntentsRegistry::IntentServiceList& list) { + for (WebIntentsRegistry::IntentServiceList::const_iterator i = list.begin(); + i != list.end(); ++i) { + if (*i == service) { + callback.Run(true); + return; + } + } + + callback.Run(false); +} + // Functor object for intent ordering. struct IntentOrdering { // Implements StrictWeakOrdering for intents, based on intent-equivalence. @@ -146,14 +163,14 @@ using webkit_glue::WebIntentServiceData; // Internal object representing all data associated with a single query. struct WebIntentsRegistry::IntentsQuery { - // Unique query identifier. - QueryID query_id_; - // Underlying data query. WebDataService::Handle pending_query_; - // The consumer for this particular query. - Consumer* consumer_; + // The callback for this particular query. + QueryCallback callback_; + + // Callback for a query for defaults. + DefaultQueryCallback default_callback_; // The particular action to filter for while searching through extensions. // If |action_| is empty, return all extension-provided services. @@ -167,22 +184,21 @@ struct WebIntentsRegistry::IntentsQuery { GURL url_; // Create a new IntentsQuery for services with the specified action/type. - IntentsQuery(QueryID id, Consumer* consumer, + IntentsQuery(const QueryCallback& callback, const string16& action, const string16& type) - : query_id_(id), consumer_(consumer), action_(action), type_(type) {} + : callback_(callback), action_(action), type_(type) {} // Create a new IntentsQuery for all intent services or for existence checks. - IntentsQuery(QueryID id, Consumer* consumer) - : query_id_(id), consumer_(consumer), type_(ASCIIToUTF16("*")) {} + explicit IntentsQuery(const QueryCallback callback) + : callback_(callback), type_(ASCIIToUTF16("*")) {} // Create a new IntentsQuery for default services. - IntentsQuery(QueryID id, Consumer* consumer, + IntentsQuery(const DefaultQueryCallback& callback, const string16& action, const string16& type, const GURL& url) - : query_id_(id), consumer_(consumer), - action_(action), type_(type), url_(url) {} + : default_callback_(callback), action_(action), type_(type), url_(url) {} }; -WebIntentsRegistry::WebIntentsRegistry() : next_query_id_(0) {} +WebIntentsRegistry::WebIntentsRegistry() {} WebIntentsRegistry::~WebIntentsRegistry() { // Cancel all pending queries, since we can't handle them any more. @@ -238,7 +254,7 @@ void WebIntentsRegistry::OnWebDataServiceRequestDone( // Collapse intents that are equivalent for all but |type|. CollapseIntents(&matching_services); - query->consumer_->OnIntentsQueryDone(query->query_id_, matching_services); + query->callback_.Run(matching_services); delete query; } @@ -298,105 +314,59 @@ void WebIntentsRegistry::OnWebDataServiceDefaultsRequestDone( default_service = *iter; } - query->consumer_->OnIntentsDefaultsQueryDone(query->query_id_, - default_service); + query->default_callback_.Run(default_service); delete query; } -WebIntentsRegistry::QueryID WebIntentsRegistry::GetIntentServices( - const string16& action, const string16& mimetype, Consumer* consumer) { - DCHECK(consumer); +void WebIntentsRegistry::GetIntentServices( + const string16& action, const string16& mimetype, + const QueryCallback& callback) { DCHECK(wds_.get()); + DCHECK(!callback.is_null()); - IntentsQuery* query = - new IntentsQuery(next_query_id_++, consumer, action, mimetype); + IntentsQuery* query = new IntentsQuery(callback, action, mimetype); query->pending_query_ = wds_->GetWebIntentServices(action, this); queries_[query->pending_query_] = query; - - return query->query_id_; } -WebIntentsRegistry::QueryID WebIntentsRegistry::GetAllIntentServices( - Consumer* consumer) { - DCHECK(consumer); +void WebIntentsRegistry::GetAllIntentServices( + const QueryCallback& callback) { DCHECK(wds_.get()); + DCHECK(!callback.is_null()); - IntentsQuery* query = new IntentsQuery(next_query_id_++, consumer); + IntentsQuery* query = new IntentsQuery(callback); query->pending_query_ = wds_->GetAllWebIntentServices(this); queries_[query->pending_query_] = query; - - return query->query_id_; } -// Trampoline consumer for calls to IntentServiceExists. Forwards existence -// of the provided |service| to the provided |callback|. -class ServiceCheckConsumer : public WebIntentsRegistry::Consumer { - public: - ServiceCheckConsumer(const WebIntentServiceData& service, - const base::Callback<void(bool)>& callback) - : callback_(callback), - service_(service) {} - virtual ~ServiceCheckConsumer() {} - - // Gets the list of all services for a particular action. Check them all - // to see if |service_| is already registered. - virtual void OnIntentsQueryDone( - WebIntentsRegistry::QueryID id, - const WebIntentsRegistry::IntentServiceList& list) OVERRIDE { - scoped_ptr<ServiceCheckConsumer> self_deleter(this); - - for (WebIntentsRegistry::IntentServiceList::const_iterator i = list.begin(); - i != list.end(); ++i) { - if (*i == service_) { - callback_.Run(true); - return; - } - } - - callback_.Run(false); - } - - virtual void OnIntentsDefaultsQueryDone( - WebIntentsRegistry::QueryID query_id, - const DefaultWebIntentService& default_service) {} - - private: - base::Callback<void(bool)> callback_; - WebIntentServiceData service_; -}; - -WebIntentsRegistry::QueryID WebIntentsRegistry::IntentServiceExists( +void WebIntentsRegistry::IntentServiceExists( const WebIntentServiceData& service, const base::Callback<void(bool)>& callback) { + DCHECK(!callback.is_null()); + IntentsQuery* query = new IntentsQuery( - next_query_id_++, new ServiceCheckConsumer(service, callback)); + base::Bind(&ExistenceCallback, service, callback)); query->pending_query_ = wds_->GetWebIntentServicesForURL( UTF8ToUTF16(service.service_url.spec()), this); queries_[query->pending_query_] = query; - - return query->query_id_; } -WebIntentsRegistry::QueryID - WebIntentsRegistry::GetIntentServicesForExtensionFilter( +void WebIntentsRegistry::GetIntentServicesForExtensionFilter( const string16& action, const string16& mimetype, const std::string& extension_id, - Consumer* consumer) { - DCHECK(consumer); + const QueryCallback& callback) { DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); + DCHECK(!callback.is_null()); scoped_ptr<IntentsQuery> query( - new IntentsQuery(next_query_id_++, consumer, action, mimetype)); - int query_id = query->query_id_; + new IntentsQuery(callback, action, mimetype)); content::BrowserThread::PostTask( content::BrowserThread::UI, FROM_HERE, base::Bind(&WebIntentsRegistry::DoGetIntentServicesForExtensionFilter, base::Unretained(this), base::Passed(&query), extension_id)); - - return query_id; } void WebIntentsRegistry::DoGetIntentServicesForExtensionFilter( @@ -413,7 +383,7 @@ void WebIntentsRegistry::DoGetIntentServicesForExtensionFilter( FilterServicesByMimetype(query->type_, &matching_services); } - query->consumer_->OnIntentsQueryDone(query->query_id_, matching_services); + query->callback_.Run(matching_services); } void WebIntentsRegistry::RegisterDefaultIntentService( @@ -428,18 +398,18 @@ void WebIntentsRegistry::UnregisterDefaultIntentService( wds_->RemoveDefaultWebIntentService(default_service); } -WebIntentsRegistry::QueryID WebIntentsRegistry::GetDefaultIntentService( +void WebIntentsRegistry::GetDefaultIntentService( const string16& action, const string16& type, const GURL& invoking_url, - Consumer* consumer) { + const DefaultQueryCallback& callback) { + DCHECK(!callback.is_null()); + IntentsQuery* query = - new IntentsQuery(next_query_id_++, consumer, action, type, invoking_url); + new IntentsQuery(callback, action, type, invoking_url); query->pending_query_ = wds_->GetDefaultWebIntentServicesForAction(action, this); queries_[query->pending_query_] = query; - - return query->query_id_; } void WebIntentsRegistry::RegisterIntentService( diff --git a/chrome/browser/intents/web_intents_registry.h b/chrome/browser/intents/web_intents_registry.h index d2ff0a1..2faa81c 100644 --- a/chrome/browser/intents/web_intents_registry.h +++ b/chrome/browser/intents/web_intents_registry.h @@ -22,31 +22,15 @@ class WebIntentsRegistry : public WebDataServiceConsumer, public ProfileKeyedService { public: - // Unique identifier for service queries. - typedef int QueryID; - typedef std::vector<webkit_glue::WebIntentServiceData> IntentServiceList; - // An interface the WebIntentsRegistry uses to notify its clients when - // it has finished loading service data from the web database. - class Consumer { - public: - // Notifies the observer that the request has been - // completed. - virtual void OnIntentsQueryDone( - QueryID query_id, - const IntentServiceList& services) = 0; - - // Notifies the observer that a request for intents default service - // has been completed. If no default is found, the |default_service| - // service_url field will be empty. - virtual void OnIntentsDefaultsQueryDone( - QueryID query_id, - const DefaultWebIntentService& default_service) = 0; - - protected: - virtual ~Consumer() {} - }; + // Callback used by WebIntentsRegistry to return results of data fetch. + typedef base::Callback<void(const IntentServiceList&)> + QueryCallback; + + // Callback to return results of a defaults query. + typedef base::Callback<void(const DefaultWebIntentService&)> + DefaultQueryCallback; // Initializes, binds to a valid WebDataService. void Initialize(scoped_refptr<WebDataService> wds, @@ -62,29 +46,31 @@ class WebIntentsRegistry // Requests all services matching |action| and |mimetype|. // |mimetype| can contain wildcards, i.e. "image/*" or "*". - // |consumer| must not be NULL. - QueryID GetIntentServices(const string16& action, - const string16& mimetype, - Consumer* consumer); + // |callback| must not be null. + void GetIntentServices(const string16& action, + const string16& mimetype, + const QueryCallback& callback); - // Requests all services. |consumer| must not be NULL - QueryID GetAllIntentServices(Consumer* consumer); + // Requests all services. + // |callback| must not be null. + void GetAllIntentServices(const QueryCallback& callback); // Tests for the existence of the given |service|. Calls the // provided |callback| with true if it exists, false if it does not. // Checks for |service| equality with ==. - QueryID IntentServiceExists( + // |callback| must not be null. + void IntentServiceExists( const webkit_glue::WebIntentServiceData& service, const base::Callback<void(bool)>& callback); // Requests all extension services matching |action|, |mimetype| and // |extension_id|. // |mimetype| must conform to definition as outlined for GetIntentServices. - // |consumer| must not be NULL. - QueryID GetIntentServicesForExtensionFilter(const string16& action, + // |callback| must not be null. + void GetIntentServicesForExtensionFilter(const string16& action, const string16& mimetype, const std::string& extension_id, - Consumer* consumer); + const QueryCallback& callback); // Record the given default service entry. virtual void RegisterDefaultIntentService( @@ -97,10 +83,11 @@ class WebIntentsRegistry // Requests the best default intent service for the given invocation // parameters. - QueryID GetDefaultIntentService(const string16& action, + // |callback| must not be null. + void GetDefaultIntentService(const string16& action, const string16& type, const GURL& invoking_url, - Consumer* consumer); + const DefaultQueryCallback& callback); protected: // Make sure that only WebIntentsRegistryFactory can create an instance of @@ -145,9 +132,6 @@ class WebIntentsRegistry // Map for all in-flight web data requests/intent queries. QueryMap queries_; - // Unique identifier for next intent query. - QueryID next_query_id_; - // Local reference to Web Data Service. scoped_refptr<WebDataService> wds_; diff --git a/chrome/browser/intents/web_intents_registry_unittest.cc b/chrome/browser/intents/web_intents_registry_unittest.cc index 497f4f1..0554029 100644 --- a/chrome/browser/intents/web_intents_registry_unittest.cc +++ b/chrome/browser/intents/web_intents_registry_unittest.cc @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "base/bind.h" #include "base/file_util.h" #include "base/json/json_file_value_serializer.h" #include "base/message_loop.h" @@ -132,12 +133,10 @@ class WebIntentsRegistryTest : public testing::Test { // Simple consumer for WebIntentsRegistry notifications. Stores result data and // terminates UI thread when callback is invoked. -class TestConsumer: public WebIntentsRegistry::Consumer { +class TestConsumer { public: - virtual void OnIntentsQueryDone( - WebIntentsRegistry::QueryID id, + void OnIntentsQueryDone( const std::vector<webkit_glue::WebIntentServiceData>& services) { - DCHECK(id == expected_id_); services_ = services; DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); @@ -152,10 +151,8 @@ class TestConsumer: public WebIntentsRegistry::Consumer { return false; } - virtual void OnIntentsDefaultsQueryDone( - WebIntentsRegistry::QueryID id, + void OnIntentsDefaultsQueryDone( const DefaultWebIntentService& default_service) { - DCHECK(id == expected_id_); default_ = default_service; DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); @@ -169,9 +166,6 @@ class TestConsumer: public WebIntentsRegistry::Consumer { MessageLoop::current()->Run(); } - // QueryID callback is tied to. - WebIntentsRegistry::QueryID expected_id_; - // Result data from callback. std::vector<webkit_glue::WebIntentServiceData> services_; @@ -196,15 +190,15 @@ TEST_F(WebIntentsRegistryTest, BasicTests) { registry_.RegisterIntentService(service); TestConsumer consumer; - consumer.expected_id_ = registry_.GetIntentServices(ASCIIToUTF16("share"), - ASCIIToUTF16("*"), - &consumer); + registry_.GetIntentServices(ASCIIToUTF16("share"), ASCIIToUTF16("*"), + base::Bind(&TestConsumer::OnIntentsQueryDone, + base::Unretained(&consumer))); consumer.WaitForData(); EXPECT_EQ(2U, consumer.services_.size()); - consumer.expected_id_ = registry_.GetIntentServices(ASCIIToUTF16("search"), - ASCIIToUTF16("*"), - &consumer); + registry_.GetIntentServices(ASCIIToUTF16("search"), ASCIIToUTF16("*"), + base::Bind(&TestConsumer::OnIntentsQueryDone, + base::Unretained(&consumer))); consumer.WaitForData(); EXPECT_EQ(1U, consumer.services_.size()); @@ -212,9 +206,9 @@ TEST_F(WebIntentsRegistryTest, BasicTests) { service.type = ASCIIToUTF16("image/*"); registry_.UnregisterIntentService(service); - consumer.expected_id_ = registry_.GetIntentServices(ASCIIToUTF16("share"), - ASCIIToUTF16("*"), - &consumer); + registry_.GetIntentServices(ASCIIToUTF16("share"), ASCIIToUTF16("*"), + base::Bind(&TestConsumer::OnIntentsQueryDone, + base::Unretained(&consumer))); consumer.WaitForData(); EXPECT_EQ(1U, consumer.services_.size()); } @@ -229,11 +223,12 @@ TEST_F(WebIntentsRegistryTest, GetIntentServicesForExtensionFilter) { ASSERT_EQ(2U, extensions_.size()); TestConsumer consumer; - consumer.expected_id_ = registry_.GetIntentServicesForExtensionFilter( + registry_.GetIntentServicesForExtensionFilter( ASCIIToUTF16("http://webintents.org/edit"), ASCIIToUTF16("image/*"), edit_extension->id(), - &consumer); + base::Bind(&TestConsumer::OnIntentsQueryDone, + base::Unretained(&consumer))); consumer.WaitForData(); ASSERT_EQ(1U, consumer.services_.size()); } @@ -250,7 +245,8 @@ TEST_F(WebIntentsRegistryTest, GetAllIntents) { registry_.RegisterIntentService(service); TestConsumer consumer; - consumer.expected_id_ = registry_.GetAllIntentServices(&consumer); + registry_.GetAllIntentServices(base::Bind(&TestConsumer::OnIntentsQueryDone, + base::Unretained(&consumer))); consumer.WaitForData(); ASSERT_EQ(2U, consumer.services_.size()); @@ -270,7 +266,8 @@ TEST_F(WebIntentsRegistryTest, GetExtensionIntents) { ASSERT_EQ(2U, extensions_.size()); TestConsumer consumer; - consumer.expected_id_ = registry_.GetAllIntentServices(&consumer); + registry_.GetAllIntentServices(base::Bind(&TestConsumer::OnIntentsQueryDone, + base::Unretained(&consumer))); consumer.WaitForData(); ASSERT_EQ(2U, consumer.services_.size()); } @@ -281,9 +278,10 @@ TEST_F(WebIntentsRegistryTest, GetSomeExtensionIntents) { ASSERT_EQ(2U, extensions_.size()); TestConsumer consumer; - consumer.expected_id_ = registry_.GetIntentServices( - ASCIIToUTF16("http://webintents.org/edit"), ASCIIToUTF16("*"), - &consumer); + registry_.GetIntentServices(ASCIIToUTF16("http://webintents.org/edit"), + ASCIIToUTF16("*"), + base::Bind(&TestConsumer::OnIntentsQueryDone, + base::Unretained(&consumer))); consumer.WaitForData(); ASSERT_EQ(1U, consumer.services_.size()); } @@ -301,15 +299,17 @@ TEST_F(WebIntentsRegistryTest, GetIntentsFromMixedSources) { registry_.RegisterIntentService(service); TestConsumer consumer; - consumer.expected_id_ = registry_.GetIntentServices( + registry_.GetIntentServices( ASCIIToUTF16("http://webintents.org/edit"), ASCIIToUTF16("*"), - &consumer); + base::Bind(&TestConsumer::OnIntentsQueryDone, + base::Unretained(&consumer))); consumer.WaitForData(); ASSERT_EQ(2U, consumer.services_.size()); - consumer.expected_id_ = registry_.GetIntentServices( - ASCIIToUTF16("http://webintents.org/share"), ASCIIToUTF16("*"), - &consumer); + registry_.GetIntentServices(ASCIIToUTF16("http://webintents.org/share"), + ASCIIToUTF16("*"), + base::Bind(&TestConsumer::OnIntentsQueryDone, + base::Unretained(&consumer))); consumer.WaitForData(); ASSERT_EQ(1U, consumer.services_.size()); } @@ -391,43 +391,48 @@ TEST_F(WebIntentsRegistryTest, GetIntentsWithMimeAndLiteralMatching) { TestConsumer consumer; // Test specific match on both sides. - consumer.expected_id_ = registry_.GetIntentServices( - ASCIIToUTF16("http://webintents.org/share"), - ASCIIToUTF16("text/uri-list"), &consumer); + registry_.GetIntentServices(ASCIIToUTF16("http://webintents.org/share"), + ASCIIToUTF16("text/uri-list"), + base::Bind(&TestConsumer::OnIntentsQueryDone, + base::Unretained(&consumer))); consumer.WaitForData(); ASSERT_EQ(1U, consumer.services_.size()); EXPECT_EQ(services[2], consumer.services_[0]); // Test specific query, wildcard registration. - consumer.expected_id_ = registry_.GetIntentServices( - ASCIIToUTF16("http://webintents.org/share"), - ASCIIToUTF16("image/png"), &consumer); + registry_.GetIntentServices(ASCIIToUTF16("http://webintents.org/share"), + ASCIIToUTF16("image/png"), + base::Bind(&TestConsumer::OnIntentsQueryDone, + base::Unretained(&consumer))); consumer.WaitForData(); ASSERT_EQ(1U, consumer.services_.size()); EXPECT_EQ(services[0], consumer.services_[0]); // Test wildcard query, specific registration. - consumer.expected_id_ = registry_.GetIntentServices( - ASCIIToUTF16("http://webintents.org/share"), - ASCIIToUTF16("text/*"), &consumer); + registry_.GetIntentServices(ASCIIToUTF16("http://webintents.org/share"), + ASCIIToUTF16("text/*"), + base::Bind(&TestConsumer::OnIntentsQueryDone, + base::Unretained(&consumer))); consumer.WaitForData(); ASSERT_EQ(2U, consumer.services_.size()); EXPECT_EQ(services[2], consumer.services_[0]); EXPECT_EQ(services[3], consumer.services_[1]); // Test wildcard query, wildcard registration. - consumer.expected_id_ = registry_.GetIntentServices( - ASCIIToUTF16("http://webintents.org/share"), - ASCIIToUTF16("image/*"), &consumer); + registry_.GetIntentServices(ASCIIToUTF16("http://webintents.org/share"), + ASCIIToUTF16("image/*"), + base::Bind(&TestConsumer::OnIntentsQueryDone, + base::Unretained(&consumer))); consumer.WaitForData(); ASSERT_EQ(2U, consumer.services_.size()); EXPECT_EQ(services[0], consumer.services_[0]); EXPECT_EQ(services[1], consumer.services_[1]); // Test "catch-all" query. - consumer.expected_id_ = registry_.GetIntentServices( - ASCIIToUTF16("http://webintents.org/share"), - ASCIIToUTF16("*"), &consumer); + registry_.GetIntentServices(ASCIIToUTF16("http://webintents.org/share"), + ASCIIToUTF16("*"), + base::Bind(&TestConsumer::OnIntentsQueryDone, + base::Unretained(&consumer))); consumer.WaitForData(); ASSERT_EQ(5U, consumer.services_.size()); EXPECT_TRUE(consumer.ServicesContains(services[0])); @@ -437,32 +442,39 @@ TEST_F(WebIntentsRegistryTest, GetIntentsWithMimeAndLiteralMatching) { EXPECT_TRUE(consumer.ServicesContains(services[12])); // Test retrieve string literal match. - consumer.expected_id_ = registry_.GetIntentServices( - ASCIIToUTF16("http://webintents.org/share"), - ASCIIToUTF16("elsewhere"), &consumer); + registry_.GetIntentServices( + ASCIIToUTF16("http://webintents.org/share"), ASCIIToUTF16("elsewhere"), + base::Bind(&TestConsumer::OnIntentsQueryDone, + base::Unretained(&consumer))); consumer.WaitForData(); ASSERT_EQ(1U, consumer.services_.size()); EXPECT_EQ(services[4], consumer.services_[0]); // Test retrieve MIME-looking type but actually isn't // doesn't wildcard match. - consumer.expected_id_ = registry_.GetIntentServices( + registry_.GetIntentServices( ASCIIToUTF16("http://webintents.org/share"), - ASCIIToUTF16("nota/mimetype"), &consumer); + ASCIIToUTF16("nota/mimetype"), + base::Bind(&TestConsumer::OnIntentsQueryDone, + base::Unretained(&consumer))); consumer.WaitForData(); ASSERT_EQ(0U, consumer.services_.size()); // Also a MIME-ish type that actually isn't. - consumer.expected_id_ = registry_.GetIntentServices( + registry_.GetIntentServices( ASCIIToUTF16("http://webintents.org/share"), - ASCIIToUTF16("x-/mimetype"), &consumer); + ASCIIToUTF16("x-/mimetype"), + base::Bind(&TestConsumer::OnIntentsQueryDone, + base::Unretained(&consumer))); consumer.WaitForData(); ASSERT_EQ(0U, consumer.services_.size()); // Extension MIME type will match wildcard. - consumer.expected_id_ = registry_.GetIntentServices( + registry_.GetIntentServices( ASCIIToUTF16("http://webintents.org/share"), - ASCIIToUTF16("x-type/mimetype"), &consumer); + ASCIIToUTF16("x-type/mimetype"), + base::Bind(&TestConsumer::OnIntentsQueryDone, + base::Unretained(&consumer))); consumer.WaitForData(); ASSERT_EQ(1U, consumer.services_.size()); } @@ -480,11 +492,11 @@ TEST_F(WebIntentsRegistryTest, TestGetDefaults) { TestConsumer consumer; // Test we can retrieve default entries by action. - consumer.expected_id_ = registry_.GetDefaultIntentService( - ASCIIToUTF16("share"), - ASCIIToUTF16("text/plain"), + registry_.GetDefaultIntentService( + ASCIIToUTF16("share"), ASCIIToUTF16("text/plain"), GURL("http://www.google.com/"), - &consumer); + base::Bind(&TestConsumer::OnIntentsDefaultsQueryDone, + base::Unretained(&consumer))); consumer.WaitForData(); @@ -496,11 +508,11 @@ TEST_F(WebIntentsRegistryTest, TestGetDefaults) { // default entries. consumer.default_ = DefaultWebIntentService(); ASSERT_EQ("", consumer.default_.service_url); - consumer.expected_id_ = registry_.GetDefaultIntentService( - ASCIIToUTF16("no-share"), - ASCIIToUTF16("text/plain"), + registry_.GetDefaultIntentService( + ASCIIToUTF16("no-share"), ASCIIToUTF16("text/plain"), GURL("http://www.google.com/"), - &consumer); + base::Bind(&TestConsumer::OnIntentsDefaultsQueryDone, + base::Unretained(&consumer))); consumer.WaitForData(); @@ -510,11 +522,11 @@ TEST_F(WebIntentsRegistryTest, TestGetDefaults) { // default entries (they get filtered out). consumer.default_ = DefaultWebIntentService(); ASSERT_EQ("", consumer.default_.service_url); - consumer.expected_id_ = registry_.GetDefaultIntentService( - ASCIIToUTF16("share"), - ASCIIToUTF16("image/plain"), + registry_.GetDefaultIntentService( + ASCIIToUTF16("share"), ASCIIToUTF16("image/plain"), GURL("http://www.google.com/"), - &consumer); + base::Bind(&TestConsumer::OnIntentsDefaultsQueryDone, + base::Unretained(&consumer))); consumer.WaitForData(); @@ -523,11 +535,12 @@ TEST_F(WebIntentsRegistryTest, TestGetDefaults) { // Check that a string-literal type won't match. consumer.default_ = DefaultWebIntentService(); ASSERT_EQ("", consumer.default_.service_url); - consumer.expected_id_ = registry_.GetDefaultIntentService( + registry_.GetDefaultIntentService( ASCIIToUTF16("share"), ASCIIToUTF16("literal"), GURL("http://www.google.com/"), - &consumer); + base::Bind(&TestConsumer::OnIntentsDefaultsQueryDone, + base::Unretained(&consumer))); consumer.WaitForData(); @@ -609,9 +622,11 @@ TEST_F(WebIntentsRegistryTest, GetIntentsCollapsesEquivalentIntents) { registry_.RegisterIntentService(services[1]); TestConsumer consumer; - consumer.expected_id_ = registry_.GetIntentServices( - ASCIIToUTF16("http://webintents.org/share"), - ASCIIToUTF16("image/*"), &consumer); + registry_.GetIntentServices(ASCIIToUTF16("http://webintents.org/share"), + ASCIIToUTF16("image/*"), + base::Bind(&TestConsumer::OnIntentsQueryDone, + base::Unretained(&consumer))); + consumer.WaitForData(); ASSERT_EQ(1U, consumer.services_.size()); EXPECT_EQ(ASCIIToUTF16("image/png,image/jpg"), consumer.services_[0].type); |