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

Side by Side Diff: chrome/browser/intents/web_intents_registry.cc

Issue 10834076: Refactor WebIntentsRegistry internals to use closures as WebDataService results handlers. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Small documentation and code improvements. Created 8 years, 4 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 unified diff | Download patch
« no previous file with comments | « chrome/browser/intents/web_intents_registry.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/intents/web_intents_registry.h" 5 #include "chrome/browser/intents/web_intents_registry.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 22 matching lines...) Expand all
33 33
34 const char* kQuickOfficeViewerMimeType[] = { 34 const char* kQuickOfficeViewerMimeType[] = {
35 "application/msword", 35 "application/msword",
36 "application/vnd.ms-powerpoint", 36 "application/vnd.ms-powerpoint",
37 "application/vnd.ms-excel", 37 "application/vnd.ms-excel",
38 "application/vnd.openxmlformats-officedocument.wordprocessingml.document", 38 "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
39 "application/vnd.openxmlformats-officedocument.presentationml.presentation", 39 "application/vnd.openxmlformats-officedocument.presentationml.presentation",
40 "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" 40 "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
41 }; 41 };
42 42
43 typedef base::Callback<void(const WDTypedResult* result)> ResultsHandler;
43 typedef WebIntentsRegistry::IntentServiceList IntentServiceList; 44 typedef WebIntentsRegistry::IntentServiceList IntentServiceList;
44 45
45 // Compares two mime types for equality. Supports wild cards in both 46 // Compares two mime types for equality. Supports wild cards in both
46 // |type1| and |type2|. Wild cards are of the form '<type>/*' or '*'. 47 // |type1| and |type2|. Wild cards are of the form '<type>/*' or '*'.
47 bool MimeTypesAreEqual(const string16& type1, const string16& type2) { 48 bool MimeTypesAreEqual(const string16& type1, const string16& type2) {
48 // We don't have a MIME matcher that allows patterns on both sides 49 // We don't have a MIME matcher that allows patterns on both sides
49 // Instead, we do two comparisons, treating each type in turn as a 50 // Instead, we do two comparisons, treating each type in turn as a
50 // pattern. If either one matches, we consider this a MIME match. 51 // pattern. If either one matches, we consider this a MIME match.
51 if (net::MatchesMimeType(UTF16ToUTF8(type1), UTF16ToUTF8(type2))) 52 if (net::MatchesMimeType(UTF16ToUTF8(type1), UTF16ToUTF8(type2)))
52 return true; 53 return true;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 ++iter; 96 ++iter;
96 else 97 else
97 iter = matching_services->erase(iter); 98 iter = matching_services->erase(iter);
98 } 99 }
99 } 100 }
100 101
101 // Callback for existence checks. Converts a callback for a list of services 102 // Callback for existence checks. Converts a callback for a list of services
102 // into a callback that returns true if the list contains a specific service. 103 // into a callback that returns true if the list contains a specific service.
103 void ExistenceCallback(const webkit_glue::WebIntentServiceData& service, 104 void ExistenceCallback(const webkit_glue::WebIntentServiceData& service,
104 const base::Callback<void(bool)>& callback, 105 const base::Callback<void(bool)>& callback,
105 const WebIntentsRegistry::IntentServiceList& list) { 106 const WDTypedResult* result) {
107
108 WebIntentsRegistry::IntentServiceList list = static_cast<
109 const WDResult<IntentServiceList>*>(result)->GetValue();
110
106 for (WebIntentsRegistry::IntentServiceList::const_iterator i = list.begin(); 111 for (WebIntentsRegistry::IntentServiceList::const_iterator i = list.begin();
107 i != list.end(); ++i) { 112 i != list.end(); ++i) {
108 if (*i == service) { 113 if (*i == service) {
109 callback.Run(true); 114 callback.Run(true);
110 return; 115 return;
111 } 116 }
112 } 117 }
113 118
114 callback.Run(false); 119 callback.Run(false);
115 } 120 }
(...skipping 27 matching lines...) Expand all
143 return !((lhs.service_url != rhs.service_url) || 148 return !((lhs.service_url != rhs.service_url) ||
144 (lhs.action != rhs.action) || 149 (lhs.action != rhs.action) ||
145 (lhs.title != rhs.title) || 150 (lhs.title != rhs.title) ||
146 (lhs.disposition != rhs.disposition)); 151 (lhs.disposition != rhs.disposition));
147 } 152 }
148 153
149 } // namespace 154 } // namespace
150 155
151 using webkit_glue::WebIntentServiceData; 156 using webkit_glue::WebIntentServiceData;
152 157
153 // Internal object representing all data associated with a single query. 158 // Internal object containing arguments to used in post processing
Greg Billock 2012/07/31 19:10:09 to be used
Steve McKay 2012/07/31 19:14:35 Done.
154 struct WebIntentsRegistry::IntentsQuery : public WebDataServiceConsumer { 159 // WDS results.
155 160 struct WebIntentsRegistry::QueryParams {
156 // Handle so we can call back into the WebIntentsRegistry when
157 // processing query results. The registry is guaranteed to be
158 // valid for the life of this object. We do not own this object.
159 WebIntentsRegistry* registry_;
160
161 // Underlying data query.
162 WebDataService::Handle query_handle_;
163
164 // The callback for this particular query.
165 QueryCallback callback_;
166
167 // Callback for a query for defaults.
168 DefaultQueryCallback default_callback_;
169 161
170 // The particular action to filter for while searching through extensions. 162 // The particular action to filter for while searching through extensions.
171 // If |action_| is empty, return all extension-provided services. 163 // If |action_| is empty, return all extension-provided services.
172 string16 action_; 164 string16 action_;
173 165
174 // The MIME type that was requested for this service query. 166 // The MIME type that was requested for this service query.
175 // Suppports wild cards. 167 // Suppports wild cards.
176 string16 type_; 168 string16 type_;
177 169
178 // The url of the invoking page. 170 // The url of the invoking page.
179 GURL url_; 171 GURL url_;
180 172
181 // Create a new IntentsQuery for services with the specified action/type. 173 // Create a new QueryParams for all intent services or for existence checks.
182 IntentsQuery(WebIntentsRegistry* registry, 174 QueryParams() : type_(ASCIIToUTF16("*")) {}
183 const QueryCallback& callback,
184 const string16& action, const string16& type)
185 : registry_(registry), callback_(callback), action_(action),
186 type_(type) {}
187 175
188 // Create a new IntentsQuery for all intent services or for existence checks. 176 QueryParams(const string16& action, const string16& type)
189 IntentsQuery(WebIntentsRegistry* registry, 177 : action_(action), type_(type) {}
190 const QueryCallback callback)
191 : registry_(registry), callback_(callback), type_(ASCIIToUTF16("*")) {}
192 178
193 // Create a new IntentsQuery for default services. 179 // Create a new QueryParams for default services.
194 IntentsQuery(WebIntentsRegistry* registry, 180 QueryParams(const string16& action, const string16& type, const GURL& url)
195 const DefaultQueryCallback& callback, 181 : action_(action), type_(type), url_(url) {}
196 const string16& action, const string16& type, const GURL& url) 182 };
197 : registry_(registry), default_callback_(callback), action_(action), 183
198 type_(type), url_(url) {} 184 // Internal object adapter the WDS consumer interface to an easier
Greg Billock 2012/07/31 19:10:09 for the
Steve McKay 2012/07/31 19:14:35 Reworded.
185 // to use closure/callback way of doing business.
186 class WebIntentsRegistry::QueryAdapter : public WebDataServiceConsumer {
187
188 public:
189 // Underlying data query.
190 WebDataService::Handle query_handle_;
191
192 // Create a new QueryAdapter that delegates results to |handler|.
193 QueryAdapter(WebIntentsRegistry* registry, const ResultsHandler& handler)
194 : registry_(registry), handler_(handler) {
195 registry_->TrackQuery(this);
196 }
199 197
200 void OnWebDataServiceRequestDone( 198 void OnWebDataServiceRequestDone(
201 WebDataService::Handle h, 199 WebDataService::Handle h,
202 const WDTypedResult* result) OVERRIDE { 200 const WDTypedResult* result) OVERRIDE {
203 201
204 // dispatch the request 202 handler_.Run(result);
205 if (result->GetType() == WEB_INTENTS_RESULT) { 203 registry_->ReleaseQuery(this);
206 registry_->OnWebIntentsResultReceived(this, result);
207 } else if (result->GetType() == WEB_INTENTS_DEFAULTS_RESULT) {
208 registry_->OnWebIntentsDefaultsResultReceived(this, result);
209 } else {
210 NOTREACHED();
211 }
212 } 204 }
205
206 private:
207 // Handle so we can call back into the WebIntentsRegistry when
208 // processing query results. The registry is guaranteed to be
209 // valid for the life of this object. We do not own this object.
210 WebIntentsRegistry* registry_;
211
212 // The callback for this particular query.
213 ResultsHandler handler_;
213 }; 214 };
214 215
215 WebIntentsRegistry::WebIntentsRegistry() {} 216 WebIntentsRegistry::WebIntentsRegistry() {}
216 217
217 WebIntentsRegistry::~WebIntentsRegistry() { 218 WebIntentsRegistry::~WebIntentsRegistry() {
218 219
219 // Cancel all pending queries, since we can't handle them any more. 220 // Cancel all pending queries, since we can't handle them any more.
220 for (QueryVector::iterator it = pending_queries_.begin(); 221 for (QueryVector::iterator it = pending_queries_.begin();
221 it != pending_queries_.end(); ++it) { 222 it != pending_queries_.end(); ++it) {
222 IntentsQuery* query = *it; 223 QueryAdapter* query = *it;
223 wds_->CancelRequest(query->query_handle_); 224 wds_->CancelRequest(query->query_handle_);
224 delete query; 225 delete query;
225 } 226 }
226 } 227 }
227 228
228 void WebIntentsRegistry::Initialize( 229 void WebIntentsRegistry::Initialize(
229 scoped_refptr<WebDataService> wds, 230 scoped_refptr<WebDataService> wds,
230 ExtensionServiceInterface* extension_service) { 231 ExtensionServiceInterface* extension_service) {
231 wds_ = wds; 232 wds_ = wds;
232 extension_service_ = extension_service; 233 extension_service_ = extension_service;
233 } 234 }
234 235
235 void WebIntentsRegistry::OnWebIntentsResultReceived( 236 void WebIntentsRegistry::OnWebIntentsResultReceived(
236 IntentsQuery* query, 237 const QueryParams& params,
238 const QueryCallback& callback,
237 const WDTypedResult* result) { 239 const WDTypedResult* result) {
238 DCHECK(query);
239 DCHECK(result); 240 DCHECK(result);
240 DCHECK(result->GetType() == WEB_INTENTS_RESULT); 241 DCHECK(result->GetType() == WEB_INTENTS_RESULT);
241 242
242 ReleaseQuery(query);
243
244 IntentServiceList matching_services = static_cast< 243 IntentServiceList matching_services = static_cast<
245 const WDResult<IntentServiceList>*>(result)->GetValue(); 244 const WDResult<IntentServiceList>*>(result)->GetValue();
246 245
247 // Loop over all services in all extensions, collect ones 246 // Loop over all services in all extensions, collect ones
248 // matching the query. 247 // matching the query.
249 if (extension_service_) { 248 if (extension_service_) {
250 const ExtensionSet* extensions = extension_service_->extensions(); 249 const ExtensionSet* extensions = extension_service_->extensions();
251 if (extensions) { 250 if (extensions) {
252 for (ExtensionSet::const_iterator i(extensions->begin()); 251 for (ExtensionSet::const_iterator i(extensions->begin());
253 i != extensions->end(); ++i) { 252 i != extensions->end(); ++i) {
254 AddMatchingServicesForExtension(**i, query->action_, 253 AddMatchingServicesForExtension(**i, params.action_,
255 &matching_services); 254 &matching_services);
256 } 255 }
257 } 256 }
258 } 257 }
259 258
260 // Filter out all services not matching the query type. 259 // Filter out all services not matching the query type.
261 FilterServicesByType(query->type_, &matching_services); 260 FilterServicesByType(params.type_, &matching_services);
262 261
263 // Collapse intents that are equivalent for all but |type|. 262 // Collapse intents that are equivalent for all but |type|.
264 CollapseIntents(&matching_services); 263 CollapseIntents(&matching_services);
265 264
266 query->callback_.Run(matching_services); 265 callback.Run(matching_services);
267 delete query;
268 } 266 }
269 267
270 void WebIntentsRegistry::OnWebIntentsDefaultsResultReceived( 268 void WebIntentsRegistry::OnWebIntentsDefaultsResultReceived(
271 IntentsQuery* query, 269 const QueryParams& params,
270 const DefaultQueryCallback& callback,
272 const WDTypedResult* result) { 271 const WDTypedResult* result) {
273 DCHECK(query);
274 DCHECK(result); 272 DCHECK(result);
275 DCHECK(result->GetType() == WEB_INTENTS_DEFAULTS_RESULT); 273 DCHECK(result->GetType() == WEB_INTENTS_DEFAULTS_RESULT);
276 274
277 ReleaseQuery(query);
278
279 std::vector<DefaultWebIntentService> services = static_cast< 275 std::vector<DefaultWebIntentService> services = static_cast<
280 const WDResult<std::vector<DefaultWebIntentService> >*>(result)-> 276 const WDResult<std::vector<DefaultWebIntentService> >*>(result)->
281 GetValue(); 277 GetValue();
282 278
283 DefaultWebIntentService default_service; 279 DefaultWebIntentService default_service;
284 std::vector<DefaultWebIntentService>::iterator iter(services.begin()); 280 std::vector<DefaultWebIntentService>::iterator iter(services.begin());
285 for (; iter != services.end(); ++iter) { 281 for (; iter != services.end(); ++iter) {
286 if (!WebIntentsTypesMatch(iter->type, query->type_)) { 282 if (!WebIntentsTypesMatch(iter->type, params.type_)) {
287 continue; 283 continue;
288 } 284 }
289 if (!iter->url_pattern.MatchesURL(query->url_)) { 285 if (!iter->url_pattern.MatchesURL(params.url_)) {
290 continue; 286 continue;
291 } 287 }
292 const Extension* extension = ExtensionForURL(iter->service_url); 288 const Extension* extension = ExtensionForURL(iter->service_url);
293 if (extension != NULL && 289 if (extension != NULL &&
294 !extension_service_->IsExtensionEnabled(extension->id())) { 290 !extension_service_->IsExtensionEnabled(extension->id())) {
295 continue; 291 continue;
296 } 292 }
297 293
298 // Found a match. If it is better than default_service, use it. 294 // Found a match. If it is better than default_service, use it.
299 // Currently the metric is that if the new value is user-set, 295 // Currently the metric is that if the new value is user-set,
(...skipping 13 matching lines...) Expand all
313 // TODO(hshi): Temporary workaround for http://crbug.com/134197. 309 // TODO(hshi): Temporary workaround for http://crbug.com/134197.
314 // If no user-set default service is found, use built-in QuickOffice Viewer as 310 // If no user-set default service is found, use built-in QuickOffice Viewer as
315 // default for MS office files. Remove this once full defaults is in place. 311 // default for MS office files. Remove this once full defaults is in place.
316 if (default_service.user_date <= 0) { 312 if (default_service.user_date <= 0) {
317 for (size_t i = 0; i < sizeof(kQuickOfficeViewerMimeType) / sizeof(char*); 313 for (size_t i = 0; i < sizeof(kQuickOfficeViewerMimeType) / sizeof(char*);
318 ++i) { 314 ++i) {
319 DefaultWebIntentService qoviewer_service; 315 DefaultWebIntentService qoviewer_service;
320 qoviewer_service.action = ASCIIToUTF16(kViewActionURL); 316 qoviewer_service.action = ASCIIToUTF16(kViewActionURL);
321 qoviewer_service.type = ASCIIToUTF16(kQuickOfficeViewerMimeType[i]); 317 qoviewer_service.type = ASCIIToUTF16(kQuickOfficeViewerMimeType[i]);
322 qoviewer_service.service_url = kQuickOfficeViewerServiceURL; 318 qoviewer_service.service_url = kQuickOfficeViewerServiceURL;
323 if (WebIntentsTypesMatch(qoviewer_service.type, query->type_)) { 319 if (WebIntentsTypesMatch(qoviewer_service.type, params.type_)) {
324 default_service = qoviewer_service; 320 default_service = qoviewer_service;
325 break; 321 break;
326 } 322 }
327 } 323 }
328 } 324 }
329 325
330 query->default_callback_.Run(default_service); 326 callback.Run(default_service);
331 delete query;
332 } 327 }
333 328
334 void WebIntentsRegistry::GetIntentServices( 329 void WebIntentsRegistry::GetIntentServices(
335 const string16& action, const string16& type, 330 const string16& action, const string16& type,
336 const QueryCallback& callback) { 331 const QueryCallback& callback) {
337 DCHECK(wds_.get()); 332 DCHECK(wds_.get());
338 DCHECK(!callback.is_null()); 333 DCHECK(!callback.is_null());
339 334
340 IntentsQuery* query = new IntentsQuery(this, callback, action, type); 335 const QueryParams params(action, type);
336 const ResultsHandler handler = base::Bind(
337 &WebIntentsRegistry::OnWebIntentsResultReceived,
338 base::Unretained(this),
339 params,
340 callback);
341
342 QueryAdapter* query = new QueryAdapter(this, handler);
341 query->query_handle_ = wds_->GetWebIntentServices(action, query); 343 query->query_handle_ = wds_->GetWebIntentServices(action, query);
342 TrackQuery(query);
343 } 344 }
344 345
345 void WebIntentsRegistry::GetAllIntentServices( 346 void WebIntentsRegistry::GetAllIntentServices(
346 const QueryCallback& callback) { 347 const QueryCallback& callback) {
347 DCHECK(wds_.get()); 348 DCHECK(wds_.get());
348 DCHECK(!callback.is_null()); 349 DCHECK(!callback.is_null());
349 350
350 IntentsQuery* query = new IntentsQuery(this, callback); 351 const QueryParams params;
352 const ResultsHandler handler = base::Bind(
353 &WebIntentsRegistry::OnWebIntentsResultReceived,
354 base::Unretained(this),
355 params,
356 callback);
357
358 QueryAdapter* query = new QueryAdapter(this, handler);
351 query->query_handle_ = wds_->GetAllWebIntentServices(query); 359 query->query_handle_ = wds_->GetAllWebIntentServices(query);
352 TrackQuery(query);
353 } 360 }
354 361
355 void WebIntentsRegistry::IntentServiceExists( 362 void WebIntentsRegistry::IntentServiceExists(
356 const WebIntentServiceData& service, 363 const WebIntentServiceData& service,
357 const base::Callback<void(bool)>& callback) { 364 const base::Callback<void(bool)>& callback) {
358 DCHECK(!callback.is_null()); 365 DCHECK(!callback.is_null());
359 366
360 IntentsQuery* query = new IntentsQuery( 367 ResultsHandler handler = base::Bind(
361 this, base::Bind(&ExistenceCallback, service, callback)); 368 &ExistenceCallback,
369 service,
370 callback);
371
372 QueryAdapter* query = new QueryAdapter(this, handler);
362 query->query_handle_ = wds_->GetWebIntentServicesForURL( 373 query->query_handle_ = wds_->GetWebIntentServicesForURL(
363 UTF8ToUTF16(service.service_url.spec()), query); 374 UTF8ToUTF16(service.service_url.spec()), query);
364 TrackQuery(query);
365 } 375 }
366 376
367 void WebIntentsRegistry::GetIntentServicesForExtensionFilter( 377 void WebIntentsRegistry::GetIntentServicesForExtensionFilter(
368 const string16& action, 378 const string16& action,
369 const string16& type, 379 const string16& type,
370 const std::string& extension_id, 380 const std::string& extension_id,
371 const QueryCallback& callback) { 381 const QueryCallback& callback) {
372 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 382 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
373 DCHECK(!callback.is_null()); 383 DCHECK(!callback.is_null());
374 384
375 // This isn't a WDS query, so we don't track it, 385 const QueryParams params(action, type);
376 // or claim the query later.
377 scoped_ptr<IntentsQuery> query(
378 new IntentsQuery(this, callback, action, type));
379 content::BrowserThread::PostTask( 386 content::BrowserThread::PostTask(
380 content::BrowserThread::UI, 387 content::BrowserThread::UI,
381 FROM_HERE, 388 FROM_HERE,
382 base::Bind(&WebIntentsRegistry::DoGetIntentServicesForExtensionFilter, 389 base::Bind(
383 base::Unretained(this), 390 &WebIntentsRegistry::DoGetIntentServicesForExtensionFilter,
384 base::Passed(&query), extension_id)); 391 base::Unretained(this),
392 params,
393 extension_id,
394 callback));
385 } 395 }
386 396
387 void WebIntentsRegistry::DoGetIntentServicesForExtensionFilter( 397 void WebIntentsRegistry::DoGetIntentServicesForExtensionFilter(
388 scoped_ptr<IntentsQuery> query, 398 const QueryParams& params,
389 const std::string& extension_id) { 399 const std::string& extension_id,
400 const QueryCallback& callback) {
390 IntentServiceList matching_services; 401 IntentServiceList matching_services;
391 402
392 if (extension_service_) { 403 if (extension_service_) {
393 const Extension* extension = 404 const Extension* extension =
394 extension_service_->GetExtensionById(extension_id, false); 405 extension_service_->GetExtensionById(extension_id, false);
395 AddMatchingServicesForExtension(*extension, 406 AddMatchingServicesForExtension(*extension,
396 query->action_, 407 params.action_,
397 &matching_services); 408 &matching_services);
398 FilterServicesByType(query->type_, &matching_services); 409 FilterServicesByType(params.type_, &matching_services);
399 } 410 }
400 411
401 query->callback_.Run(matching_services); 412 callback.Run(matching_services);
402 } 413 }
403 414
404 void WebIntentsRegistry::RegisterDefaultIntentService( 415 void WebIntentsRegistry::RegisterDefaultIntentService(
405 const DefaultWebIntentService& default_service) { 416 const DefaultWebIntentService& default_service) {
406 DCHECK(wds_.get()); 417 DCHECK(wds_.get());
407 wds_->AddDefaultWebIntentService(default_service); 418 wds_->AddDefaultWebIntentService(default_service);
408 } 419 }
409 420
410 void WebIntentsRegistry::UnregisterDefaultIntentService( 421 void WebIntentsRegistry::UnregisterDefaultIntentService(
411 const DefaultWebIntentService& default_service) { 422 const DefaultWebIntentService& default_service) {
412 DCHECK(wds_.get()); 423 DCHECK(wds_.get());
413 wds_->RemoveDefaultWebIntentService(default_service); 424 wds_->RemoveDefaultWebIntentService(default_service);
414 } 425 }
415 426
416 void WebIntentsRegistry::GetDefaultIntentService( 427 void WebIntentsRegistry::GetDefaultIntentService(
417 const string16& action, 428 const string16& action,
418 const string16& type, 429 const string16& type,
419 const GURL& invoking_url, 430 const GURL& invoking_url,
420 const DefaultQueryCallback& callback) { 431 const DefaultQueryCallback& callback) {
421 DCHECK(!callback.is_null()); 432 DCHECK(!callback.is_null());
422 433
423 IntentsQuery* query = 434 const QueryParams params(action, type);
424 new IntentsQuery(this, callback, action, type, invoking_url); 435
436 ResultsHandler handler = base::Bind(
437 &WebIntentsRegistry::OnWebIntentsDefaultsResultReceived,
438 base::Unretained(this),
439 params,
440 callback);
441
442 QueryAdapter* query = new QueryAdapter(this, handler);
425 query->query_handle_ = 443 query->query_handle_ =
426 wds_->GetDefaultWebIntentServicesForAction(action, query); 444 wds_->GetDefaultWebIntentServicesForAction(action, query);
427 TrackQuery(query);
428 } 445 }
429 446
430 void WebIntentsRegistry::RegisterIntentService( 447 void WebIntentsRegistry::RegisterIntentService(
431 const WebIntentServiceData& service) { 448 const WebIntentServiceData& service) {
432 DCHECK(wds_.get()); 449 DCHECK(wds_.get());
433 wds_->AddWebIntentService(service); 450 wds_->AddWebIntentService(service);
434 } 451 }
435 452
436 void WebIntentsRegistry::UnregisterIntentService( 453 void WebIntentsRegistry::UnregisterIntentService(
437 const WebIntentServiceData& service) { 454 const WebIntentServiceData& service) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 if (!extensions) 492 if (!extensions)
476 return NULL; 493 return NULL;
477 494
478 // Use the unsafe ExtensionURLInfo constructor: we don't care if the extension 495 // Use the unsafe ExtensionURLInfo constructor: we don't care if the extension
479 // is running or not. 496 // is running or not.
480 GURL gurl(url); 497 GURL gurl(url);
481 ExtensionURLInfo info(gurl); 498 ExtensionURLInfo info(gurl);
482 return extensions->GetExtensionOrAppByURL(info); 499 return extensions->GetExtensionOrAppByURL(info);
483 } 500 }
484 501
485 void WebIntentsRegistry::TrackQuery(IntentsQuery* query) { 502 void WebIntentsRegistry::TrackQuery(QueryAdapter* query) {
486 DCHECK(query); 503 DCHECK(query);
487 pending_queries_.push_back(query); 504 pending_queries_.push_back(query);
488 } 505 }
489 506
490 void WebIntentsRegistry::ReleaseQuery(IntentsQuery* query) { 507 void WebIntentsRegistry::ReleaseQuery(QueryAdapter* query) {
491 QueryVector::iterator it = std::find( 508 QueryVector::iterator it = std::find(
492 pending_queries_.begin(), pending_queries_.end(), query); 509 pending_queries_.begin(), pending_queries_.end(), query);
493 if (it != pending_queries_.end()) 510 if (it != pending_queries_.end()) {
494 pending_queries_.erase(it); 511 pending_queries_.erase(it);
495 else 512 delete query;
513 } else {
496 NOTREACHED(); 514 NOTREACHED();
515 }
497 } 516 }
OLDNEW
« no previous file with comments | « chrome/browser/intents/web_intents_registry.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698