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 9c136e3eadd0f7102c897bfa4be01da766464e63..8dbcd0948516fd481ca4d1928659278f27b21eca 100644 |
--- a/chrome/browser/intents/web_intents_registry.cc |
+++ b/chrome/browser/intents/web_intents_registry.cc |
@@ -151,9 +151,12 @@ bool IntentsAreEquivalent(const webkit_glue::WebIntentServiceData& lhs, |
using webkit_glue::WebIntentServiceData; |
// Internal object representing all data associated with a single query. |
-struct WebIntentsRegistry::IntentsQuery { |
+struct WebIntentsRegistry::IntentsQuery : public WebDataServiceConsumer { |
+ |
+ WebIntentsRegistry* registry_; |
groby-ooo-7-16
2012/07/27 00:11:26
Please document variable and ownership. (I.e. I as
Steve McKay
2012/07/27 00:54:46
Done.
|
+ |
// Underlying data query. |
- WebDataService::Handle pending_query_; |
+ WebDataService::Handle query_handle_; |
// The callback for this particular query. |
QueryCallback callback_; |
@@ -173,27 +176,49 @@ struct WebIntentsRegistry::IntentsQuery { |
GURL url_; |
// Create a new IntentsQuery for services with the specified action/type. |
- IntentsQuery(const QueryCallback& callback, |
+ IntentsQuery(WebIntentsRegistry* registry, |
+ const QueryCallback& callback, |
const string16& action, const string16& type) |
- : callback_(callback), action_(action), type_(type) {} |
+ : registry_(registry), callback_(callback), action_(action), |
+ type_(type) {} |
// Create a new IntentsQuery for all intent services or for existence checks. |
- explicit IntentsQuery(const QueryCallback callback) |
- : callback_(callback), type_(ASCIIToUTF16("*")) {} |
+ IntentsQuery(WebIntentsRegistry* registry, |
+ const QueryCallback callback) |
+ : registry_(registry), callback_(callback), type_(ASCIIToUTF16("*")) {} |
// Create a new IntentsQuery for default services. |
- IntentsQuery(const DefaultQueryCallback& callback, |
+ IntentsQuery(WebIntentsRegistry* registry, |
+ const DefaultQueryCallback& callback, |
const string16& action, const string16& type, const GURL& url) |
- : default_callback_(callback), action_(action), type_(type), url_(url) {} |
+ : registry_(registry), default_callback_(callback), action_(action), |
+ type_(type), url_(url) {} |
+ |
+ void OnWebDataServiceRequestDone( |
+ WebDataService::Handle h, |
+ const WDTypedResult* result) OVERRIDE { |
+ |
+ // dispatch the request |
+ if (result->GetType() == WEB_INTENTS_RESULT) { |
groby-ooo-7-16
2012/07/27 00:11:26
Why is this not a callback? This way we can save o
Greg Billock
2012/07/27 00:41:29
We discussed doing that. With that design, we'd ne
Steve McKay
2012/07/27 00:54:46
IntentsQuery will be decomposed into sub-classes i
|
+ registry_->OnWebIntentsResultReceived(this, h, result); |
+ } else if (result->GetType() == WEB_INTENTS_DEFAULTS_RESULT) { |
+ registry_->OnWebIntentsDefaultsResultReceived(this, h, result); |
+ } else { |
+ NOTREACHED(); |
+ } |
+ } |
}; |
WebIntentsRegistry::WebIntentsRegistry() {} |
WebIntentsRegistry::~WebIntentsRegistry() { |
+ |
// Cancel all pending queries, since we can't handle them any more. |
- for (QueryMap::iterator it(queries_.begin()); it != queries_.end(); ++it) { |
- wds_->CancelRequest(it->first); |
- delete it->second; |
+ for (QueryVector::iterator it = pending_queries_.begin(); |
+ it != pending_queries_.end(); ++it) { |
+ IntentsQuery* query = *it; |
+ wds_->CancelRequest(query->query_handle_); |
+ delete query; |
} |
} |
@@ -204,22 +229,16 @@ void WebIntentsRegistry::Initialize( |
extension_service_ = extension_service; |
} |
-void WebIntentsRegistry::OnWebDataServiceRequestDone( |
+void WebIntentsRegistry::OnWebIntentsResultReceived( |
+ IntentsQuery* query, |
WebDataService::Handle h, |
Greg Billock
2012/07/27 00:41:29
Can get rid of handle param
Steve McKay
2012/07/27 00:54:46
Done.
|
const WDTypedResult* result) { |
+ DCHECK(query); |
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); |
- DCHECK(it != queries_.end()); |
- |
- IntentsQuery* query(it->second); |
- DCHECK(query); |
- queries_.erase(it); |
+ bool query_found = ClaimQuery(query); |
+ DCHECK(query_found); |
IntentServiceList matching_services = static_cast< |
const WDResult<IntentServiceList>*>(result)->GetValue(); |
@@ -247,27 +266,16 @@ void WebIntentsRegistry::OnWebDataServiceRequestDone( |
delete query; |
} |
-const Extension* WebIntentsRegistry::ExtensionForURL(const std::string& url) { |
- const ExtensionSet* extensions = extension_service_->extensions(); |
- if (!extensions) |
- return NULL; |
- |
- // Use the unsafe ExtensionURLInfo constructor: we don't care if the extension |
- // is running or not. |
- GURL gurl(url); |
- ExtensionURLInfo info(gurl); |
- return extensions->GetExtensionOrAppByURL(info); |
-} |
- |
-void WebIntentsRegistry::OnWebDataServiceDefaultsRequestDone( |
+void WebIntentsRegistry::OnWebIntentsDefaultsResultReceived( |
+ IntentsQuery* query, |
WebDataService::Handle h, |
Greg Billock
2012/07/27 00:41:29
We don't need the handle anymore, right?
Steve McKay
2012/07/27 00:54:46
Done.
|
const WDTypedResult* result) { |
- QueryMap::iterator it = queries_.find(h); |
- DCHECK(it != queries_.end()); |
- |
- IntentsQuery* query(it->second); |
DCHECK(query); |
- queries_.erase(it); |
+ DCHECK(result); |
+ DCHECK(result->GetType() == WEB_INTENTS_DEFAULTS_RESULT); |
+ |
+ bool query_found = ClaimQuery(query); |
+ DCHECK(query_found); |
std::vector<DefaultWebIntentService> services = static_cast< |
const WDResult<std::vector<DefaultWebIntentService> >*>(result)-> |
@@ -325,14 +333,14 @@ void WebIntentsRegistry::OnWebDataServiceDefaultsRequestDone( |
} |
void WebIntentsRegistry::GetIntentServices( |
- const string16& action, const string16& mimetype, |
+ const string16& action, const string16& type, |
const QueryCallback& callback) { |
DCHECK(wds_.get()); |
DCHECK(!callback.is_null()); |
- IntentsQuery* query = new IntentsQuery(callback, action, mimetype); |
- query->pending_query_ = wds_->GetWebIntentServices(action, this); |
- queries_[query->pending_query_] = query; |
+ IntentsQuery* query = new IntentsQuery(this, callback, action, type); |
+ query->query_handle_ = wds_->GetWebIntentServices(action, query); |
+ TrackQuery(query); |
} |
void WebIntentsRegistry::GetAllIntentServices( |
@@ -340,9 +348,9 @@ void WebIntentsRegistry::GetAllIntentServices( |
DCHECK(wds_.get()); |
DCHECK(!callback.is_null()); |
- IntentsQuery* query = new IntentsQuery(callback); |
- query->pending_query_ = wds_->GetAllWebIntentServices(this); |
- queries_[query->pending_query_] = query; |
+ IntentsQuery* query = new IntentsQuery(this, callback); |
+ query->query_handle_ = wds_->GetAllWebIntentServices(query); |
+ TrackQuery(query); |
} |
void WebIntentsRegistry::IntentServiceExists( |
@@ -351,10 +359,10 @@ void WebIntentsRegistry::IntentServiceExists( |
DCHECK(!callback.is_null()); |
IntentsQuery* query = new IntentsQuery( |
- base::Bind(&ExistenceCallback, service, callback)); |
- query->pending_query_ = wds_->GetWebIntentServicesForURL( |
- UTF8ToUTF16(service.service_url.spec()), this); |
- queries_[query->pending_query_] = query; |
+ this, base::Bind(&ExistenceCallback, service, callback)); |
+ query->query_handle_ = wds_->GetWebIntentServicesForURL( |
+ UTF8ToUTF16(service.service_url.spec()), query); |
+ TrackQuery(query); |
} |
void WebIntentsRegistry::GetIntentServicesForExtensionFilter( |
@@ -365,8 +373,10 @@ void WebIntentsRegistry::GetIntentServicesForExtensionFilter( |
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
DCHECK(!callback.is_null()); |
+ // This isn't a WDS query, so we don't track it, |
+ // or claim the query later. |
scoped_ptr<IntentsQuery> query( |
- new IntentsQuery(callback, action, mimetype)); |
+ new IntentsQuery(this, callback, action, mimetype)); |
content::BrowserThread::PostTask( |
content::BrowserThread::UI, |
FROM_HERE, |
@@ -412,10 +422,10 @@ void WebIntentsRegistry::GetDefaultIntentService( |
DCHECK(!callback.is_null()); |
IntentsQuery* query = |
- new IntentsQuery(callback, action, type, invoking_url); |
- query->pending_query_ = |
- wds_->GetDefaultWebIntentServicesForAction(action, this); |
- queries_[query->pending_query_] = query; |
+ new IntentsQuery(this, callback, action, type, invoking_url); |
+ query->query_handle_ = |
+ wds_->GetDefaultWebIntentServicesForAction(action, query); |
+ TrackQuery(query); |
} |
void WebIntentsRegistry::RegisterIntentService( |
@@ -460,3 +470,32 @@ void WebIntentsRegistry::CollapseIntents(IntentServiceList* services) { |
if (++write_iter != services->end()) |
services->erase(write_iter, services->end()); |
} |
+ |
+const Extension* WebIntentsRegistry::ExtensionForURL(const std::string& url) { |
groby-ooo-7-16
2012/07/27 00:11:26
Technically, functions should be in order of decla
Greg Billock
2012/07/27 00:41:29
Yeah, update the header.
On 2012/07/27 00:11:26,
Steve McKay
2012/07/27 00:54:46
Done.
|
+ const ExtensionSet* extensions = extension_service_->extensions(); |
+ if (!extensions) |
+ return NULL; |
+ |
+ // Use the unsafe ExtensionURLInfo constructor: we don't care if the extension |
+ // is running or not. |
+ GURL gurl(url); |
+ ExtensionURLInfo info(gurl); |
+ return extensions->GetExtensionOrAppByURL(info); |
+} |
+ |
+void WebIntentsRegistry::TrackQuery(IntentsQuery* query) { |
+ DCHECK(query); |
+ pending_queries_.push_back(query); |
+} |
+ |
+bool WebIntentsRegistry::ClaimQuery(IntentsQuery* query) { |
+ DCHECK(query); |
+ QueryVector::iterator it = std::find( |
+ pending_queries_.begin(), pending_queries_.end(), query); |
+ if (it != pending_queries_.end()) { |
+ pending_queries_.erase(it); |
+ return true; |
+ } else { |
+ return false; |
+ } |
+} |