Index: chrome/browser/intents/web_intents_registry.cc |
diff --git a/chrome/browser/intents/web_intents_registry.cc b/chrome/browser/intents/web_intents_registry.cc |
index 4771be5f05470525ad99dce5429b29433276be3a..a424cf6f83cd61ff569b719826330dc7d0e4357a 100644 |
--- a/chrome/browser/intents/web_intents_registry.cc |
+++ b/chrome/browser/intents/web_intents_registry.cc |
@@ -3,6 +3,9 @@ |
// found in the LICENSE file. |
#include "chrome/browser/intents/web_intents_registry.h" |
+ |
+#include "base/callback.h" |
+#include "base/utf_string_conversions.h" |
#include "chrome/browser/webdata/web_data_service.h" |
// Internal object representing all data associated with a single query. |
@@ -108,6 +111,52 @@ WebIntentsRegistry::QueryID WebIntentsRegistry::GetAllIntentProviders( |
return query->query_id_; |
} |
+// Trampoline consumer for calls to IntentProviderExists. Forwards existence |
+// of the provided |service| to the provided |callback|. |
+class ProviderCheckConsumer : public WebIntentsRegistry::Consumer { |
+ public: |
+ ProviderCheckConsumer(const WebIntentServiceData& service, |
+ const base::Callback<void(bool)>& callback) |
+ : callback_(callback), |
+ service_(service) {} |
+ virtual ~ProviderCheckConsumer() {} |
+ |
+ // Gets the list of all providers for a particular action. Check them all |
+ // to see if |provider_| is already registered. |
+ virtual void OnIntentsQueryDone( |
+ WebIntentsRegistry::QueryID id, |
+ const WebIntentsRegistry::IntentList& list) OVERRIDE { |
+ scoped_ptr<ProviderCheckConsumer> self_deleter(this); |
+ |
+ for (WebIntentsRegistry::IntentList::const_iterator i = list.begin(); |
+ i != list.end(); ++i) { |
+ if (*i == service_) { |
+ callback_.Run(true); |
+ return; |
+ } |
+ } |
+ |
+ callback_.Run(false); |
+ } |
+ |
+ private: |
+ base::Callback<void(bool)> callback_; |
+ WebIntentServiceData service_; |
+}; |
+ |
+WebIntentsRegistry::QueryID WebIntentsRegistry::IntentProviderExists( |
+ const WebIntentServiceData& provider, |
+ const base::Callback<void(bool)>& callback) { |
+ IntentsQuery* query = new IntentsQuery; |
+ query->query_id_ = next_query_id_++; |
+ query->consumer_ = new ProviderCheckConsumer(provider, callback); |
+ query->pending_query_ = wds_->GetWebIntentsForURL( |
+ UTF8ToUTF16(provider.service_url.spec()), this); |
+ queries_[query->pending_query_] = query; |
+ |
+ return query->query_id_; |
+} |
+ |
void WebIntentsRegistry::RegisterIntentProvider( |
const WebIntentServiceData& service) { |
DCHECK(wds_.get()); |