Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6743)

Unified Diff: chrome/browser/intents/web_intents_registry.cc

Issue 8144013: Add a check to the registry before the intent infobar is shown. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge to head Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..e404e6693339e763076fb270472b4b344dec71e0 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(
+ provider.action, UTF8ToUTF16(provider.service_url.spec()), this);
+ queries_[query->pending_query_] = query;
+
+ return query->query_id_;
+}
+
void WebIntentsRegistry::RegisterIntentProvider(
const WebIntentServiceData& service) {
DCHECK(wds_.get());

Powered by Google App Engine
This is Rietveld 408576698