Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/intents/intents_registry.h" | |
| 6 #include "chrome/browser/webdata/web_data_service.h" | |
| 7 | |
| 8 IntentsRegistry::IntentsRegistry() : next_query_id_(0) {} | |
| 9 | |
| 10 IntentsRegistry::~IntentsRegistry() { | |
| 11 // Cancel all pending queries, since we can't handle them any more. | |
| 12 for (QueryMap::iterator it(queries.begin()); it != queries.end(); ++it) { | |
|
James Hawkins
2011/08/04 17:34:51
Also, `delete iter->second`?
groby-ooo-7-16
2011/08/05 20:40:09
Done.
| |
| 13 wds_->CancelRequest(it->first); | |
| 14 } | |
| 15 } | |
| 16 | |
| 17 void IntentsRegistry::Initialize(scoped_refptr<WebDataService> wds) { | |
|
James Hawkins
2011/08/04 17:34:51
Why do we need an Initialize method (as opposed to
groby-ooo-7-16
2011/08/05 20:40:09
Skipped - need Initialize for dependency injection
| |
| 18 wds_ = wds; | |
| 19 } | |
| 20 | |
| 21 void IntentsRegistry::OnWebDataServiceRequestDone(WebDataService::Handle h, | |
| 22 const WDTypedResult* result) { | |
| 23 DCHECK(result); | |
| 24 DCHECK(result->GetType() == WEB_INTENTS_RESULT); | |
| 25 | |
| 26 QueryMap::iterator it = queries.find(h); | |
| 27 DCHECK(it != queries.end()); | |
| 28 | |
| 29 IntentsQuery* query(it->second); | |
| 30 DCHECK(query); | |
| 31 queries.erase(it); | |
| 32 | |
| 33 // TODO(groby): Filtering goes here. | |
| 34 std::vector<WebIntentData> intents = static_cast< | |
| 35 const WDResult<std::vector<WebIntentData> >*>(result)->GetValue(); | |
| 36 | |
| 37 query->consumer_->OnIntentsQueryDone(query->query_id_, intents); | |
| 38 } | |
| 39 | |
| 40 IntentsRegistry::QueryID IntentsRegistry::GetIntentProviders( | |
| 41 const string16& action, | |
| 42 Consumer* consumer) { | |
| 43 DCHECK(consumer); | |
| 44 DCHECK(wds_.get()); | |
| 45 | |
| 46 IntentsQuery* query = new IntentsQuery; | |
| 47 query->query_id_ = next_query_id_++; | |
| 48 query->consumer_ = consumer; | |
| 49 query->pending_query_ = wds_->GetWebIntents(action, this); | |
| 50 queries[query->pending_query_] = query; | |
| 51 | |
| 52 return query->query_id_; | |
| 53 } | |
| 54 | |
| 55 void IntentsRegistry::RegisterIntentProvider(const WebIntentData& intent) { | |
| 56 DCHECK(wds_.get()); | |
| 57 wds_->AddWebIntent(intent); | |
| 58 } | |
| 59 | |
| 60 void IntentsRegistry::UnregisterIntentProvider(const WebIntentData& intent) { | |
| 61 DCHECK(wds_.get()); | |
| 62 wds_->RemoveWebIntent(intent); | |
| 63 } | |
| OLD | NEW |