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 2df590b2881c22ff6d5f4ccc7e8a741e3d34d8a1..fff7008c680309fd68b3d8771fe1dab2bf336f75 100644 |
| --- a/chrome/browser/intents/web_intents_registry.cc |
| +++ b/chrome/browser/intents/web_intents_registry.cc |
| @@ -6,6 +6,7 @@ |
| #include "base/callback.h" |
| #include "base/utf_string_conversions.h" |
| +#include "chrome/browser/intents/default_web_intent_service.h" |
| #include "chrome/browser/webdata/web_data_service.h" |
| #include "net/base/mime_util.h" |
| @@ -44,6 +45,9 @@ struct WebIntentsRegistry::IntentsQuery { |
| // The MIME type that was requested for this service query. |
| // Suppports wild cards. |
| string16 type_; |
| + |
| + // The url of the invoking page. |
| + GURL url_; |
|
groby-ooo-7-16
2012/02/22 01:40:18
IWYU: #include "googleurl/src/gurl.h"
Greg Billock
2012/02/23 23:39:00
Done.
|
| }; |
| WebIntentsRegistry::WebIntentsRegistry() : next_query_id_(0) {} |
| @@ -67,6 +71,10 @@ void WebIntentsRegistry::OnWebDataServiceRequestDone( |
| WebDataService::Handle h, |
| const WDTypedResult* result) { |
| DCHECK(result); |
| + if (result->GetType() == WEB_INTENTS_DEFAULTS_RESULT) { |
| + OnWebDataServiceDefaultsRequestDone(h, result); |
| + return; |
| + } |
| DCHECK(result->GetType() == WEB_INTENTS_RESULT); |
| QueryMap::iterator it = queries_.find(h); |
| @@ -109,6 +117,50 @@ void WebIntentsRegistry::OnWebDataServiceRequestDone( |
| delete query; |
| } |
| +void WebIntentsRegistry::OnWebDataServiceDefaultsRequestDone( |
| + WebDataService::Handle h, |
| + const WDTypedResult* result) { |
| + QueryMap::iterator it = queries_.find(h); |
| + DCHECK(it != queries_.end()); |
| + |
| + IntentsQuery* query(it->second); |
| + DCHECK(query); |
| + queries_.erase(it); |
| + |
| + std::vector<DefaultWebIntentService> services = static_cast< |
| + const WDResult<std::vector<DefaultWebIntentService> >*>(result)-> |
| + GetValue(); |
| + |
| + DefaultWebIntentService default_service; |
| + std::vector<DefaultWebIntentService>::iterator iter(services.begin()); |
| + for (; iter != services.end(); ++iter) { |
| + if (!MimeTypesAreEqual(iter->type, query->type_)) { |
| + continue; |
| + } |
| + if (!iter->url_pattern.MatchesURL(query->url_)) { |
| + continue; |
| + } |
| + |
| + // Found a match. If it is better than default_service, use it. |
| + // Currently the metric is that if the new value is user-set, |
| + // prefer it. If the present value is suppressed, prefer it. |
| + // If the new value has a more specific pattern, prefer it. |
| + if (default_service.user_date <= 0 && iter->user_date >= 0) |
|
groby-ooo-7-16
2012/02/22 01:40:18
We should probably check if the default service is
Greg Billock
2012/02/23 23:39:00
Done.
|
| + default_service = *iter; |
| + else if (default_service.suppression > 0 && iter->suppression <= 0) |
| + default_service = *iter; |
| + else if (default_service.url_pattern.match_all_urls() && |
| + !iter->url_pattern.match_all_urls()) |
| + default_service = *iter; |
| + else if (iter->url_pattern < default_service.url_pattern) |
| + default_service = *iter; |
| + } |
| + |
| + query->consumer_->OnIntentsDefaultsQueryDone(query->query_id_, |
| + default_service); |
| + delete query; |
| +} |
| + |
| WebIntentsRegistry::QueryID WebIntentsRegistry::GetIntentServices( |
| const string16& action, const string16& mimetype, Consumer* consumer) { |
| DCHECK(consumer); |
| @@ -168,6 +220,10 @@ class ServiceCheckConsumer : public WebIntentsRegistry::Consumer { |
| callback_.Run(false); |
| } |
| + virtual void OnIntentsDefaultsQueryDone( |
| + WebIntentsRegistry::QueryID query_id, |
| + const DefaultWebIntentService& default_service) {} |
| + |
| private: |
| base::Callback<void(bool)> callback_; |
| WebIntentServiceData service_; |
| @@ -187,6 +243,36 @@ WebIntentsRegistry::QueryID WebIntentsRegistry::IntentServiceExists( |
| return query->query_id_; |
| } |
| +void WebIntentsRegistry::RegisterDefaultIntentService( |
| + const DefaultWebIntentService& default_service) { |
| + DCHECK(wds_.get()); |
| + wds_->AddDefaultWebIntentService(default_service); |
| +} |
| + |
| +void WebIntentsRegistry::UnregisterDefaultIntentService( |
| + const DefaultWebIntentService& default_service) { |
| + DCHECK(wds_.get()); |
| + wds_->RemoveDefaultWebIntentService(default_service); |
| +} |
| + |
| +WebIntentsRegistry::QueryID WebIntentsRegistry::GetDefaultIntentService( |
| + const string16& action, |
| + const string16& type, |
| + const GURL& invoking_url, |
| + Consumer* consumer) { |
| + IntentsQuery* query = new IntentsQuery; |
| + query->query_id_ = next_query_id_++; |
|
groby-ooo-7-16
2012/02/22 01:40:18
Since we now have three places that build a query,
Greg Billock
2012/02/23 23:39:00
Created some constructors. That condenses things a
|
| + query->action_ = action; |
| + query->type_ = type; |
| + query->url_ = invoking_url; |
| + query->consumer_ = consumer; |
| + query->pending_query_ = |
| + wds_->GetDefaultWebIntentServicesForAction(action, this); |
| + queries_[query->pending_query_] = query; |
|
groby-ooo-7-16
2012/02/22 01:40:18
And similarly, a RegisterQuery() for the previous
Greg Billock
2012/02/23 23:39:00
I don't think that'd buy that much. This looks cle
|
| + |
| + return query->query_id_; |
| +} |
| + |
| void WebIntentsRegistry::RegisterIntentService( |
| const WebIntentServiceData& service) { |
| DCHECK(wds_.get()); |