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

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

Issue 9430027: Add default query method to WebIntentsRegistry. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 10 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 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());

Powered by Google App Engine
This is Rietveld 408576698