Chromium Code Reviews| 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..6cd97154e76d0b827bae899fddc0988c2bed7d8b 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_; |
| } |
| +// A trampoline for showing the infobar if it is not already registered. |
|
James Hawkins
2011/10/05 22:27:17
Should not be mentioning the infobar in this file.
Greg Billock
2011/10/05 22:45:53
Oops. Copy-paste skew.
|
| +// Triggered by a return to a query to the WebIntentsRegistry. |
| +class ProviderCheckConsumer : public WebIntentsRegistry::Consumer { |
|
James Hawkins
2011/10/05 22:27:17
This makes me think we should cache the registrati
Greg Billock
2011/10/05 22:45:53
Yeah. Could be. Let's put that off for now. (DB or
|
| + 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()); |