| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 #include "chrome/browser/webdata/web_data_service.h" | 6 #include "chrome/browser/webdata/web_data_service.h" |
| 7 | 7 |
| 8 // Internal object representing all data associated with a single query. | 8 // Internal object representing all data associated with a single query. |
| 9 struct WebIntentsRegistry::IntentsQuery { | 9 struct WebIntentsRegistry::IntentsQuery { |
| 10 // Unique query identifier. | 10 // Unique query identifier. |
| 11 QueryID query_id_; | 11 QueryID query_id_; |
| 12 | 12 |
| 13 // Underlying data query. | 13 // Underlying data query. |
| 14 WebDataService::Handle pending_query_; | 14 WebDataService::Handle pending_query_; |
| 15 | 15 |
| 16 // the consumer for this particular query. | 16 // the consumer for this particular query. |
| 17 Consumer* consumer_; | 17 Consumer* consumer_; |
| 18 | 18 |
| 19 // TODO(groby): Additional filter data will go here - filtering is handled | 19 // TODO(groby): Additional filter data will go here - filtering is handled |
| 20 // per query. | 20 // per query. |
| 21 }; | 21 }; |
| 22 | 22 |
| 23 WebIntentsRegistry::WebIntentsRegistry() : next_query_id_(0) {} | 23 WebIntentsRegistry::WebIntentsRegistry() : next_query_id_(0) {} |
| 24 | 24 |
| 25 WebIntentsRegistry::~WebIntentsRegistry() { | 25 WebIntentsRegistry::~WebIntentsRegistry() { |
| 26 // Cancel all pending queries, since we can't handle them any more. | 26 // Cancel all pending queries, since we can't handle them any more. |
| 27 for (QueryMap::iterator it(queries.begin()); it != queries.end(); ++it) { | 27 for (QueryMap::iterator it(queries_.begin()); it != queries_.end(); ++it) { |
| 28 wds_->CancelRequest(it->first); | 28 wds_->CancelRequest(it->first); |
| 29 delete it->second; | 29 delete it->second; |
| 30 } | 30 } |
| 31 } | 31 } |
| 32 | 32 |
| 33 void WebIntentsRegistry::Initialize(scoped_refptr<WebDataService> wds) { | 33 void WebIntentsRegistry::Initialize(scoped_refptr<WebDataService> wds) { |
| 34 wds_ = wds; | 34 wds_ = wds; |
| 35 } | 35 } |
| 36 | 36 |
| 37 void WebIntentsRegistry::OnWebDataServiceRequestDone( | 37 void WebIntentsRegistry::OnWebDataServiceRequestDone( |
| 38 WebDataService::Handle h, | 38 WebDataService::Handle h, |
| 39 const WDTypedResult* result) { | 39 const WDTypedResult* result) { |
| 40 DCHECK(result); | 40 DCHECK(result); |
| 41 DCHECK(result->GetType() == WEB_INTENTS_RESULT); | 41 DCHECK(result->GetType() == WEB_INTENTS_RESULT); |
| 42 | 42 |
| 43 QueryMap::iterator it = queries.find(h); | 43 QueryMap::iterator it = queries_.find(h); |
| 44 DCHECK(it != queries.end()); | 44 DCHECK(it != queries_.end()); |
| 45 | 45 |
| 46 IntentsQuery* query(it->second); | 46 IntentsQuery* query(it->second); |
| 47 DCHECK(query); | 47 DCHECK(query); |
| 48 queries.erase(it); | 48 queries_.erase(it); |
| 49 | 49 |
| 50 // TODO(groby): Filtering goes here. | 50 // TODO(groby): Filtering goes here. |
| 51 std::vector<WebIntentData> intents = static_cast< | 51 std::vector<WebIntentData> intents = static_cast< |
| 52 const WDResult<std::vector<WebIntentData> >*>(result)->GetValue(); | 52 const WDResult<std::vector<WebIntentData> >*>(result)->GetValue(); |
| 53 | 53 |
| 54 query->consumer_->OnIntentsQueryDone(query->query_id_, intents); | 54 query->consumer_->OnIntentsQueryDone(query->query_id_, intents); |
| 55 delete query; |
| 55 } | 56 } |
| 56 | 57 |
| 57 WebIntentsRegistry::QueryID WebIntentsRegistry::GetIntentProviders( | 58 WebIntentsRegistry::QueryID WebIntentsRegistry::GetIntentProviders( |
| 58 const string16& action, | 59 const string16& action, |
| 59 Consumer* consumer) { | 60 Consumer* consumer) { |
| 60 DCHECK(consumer); | 61 DCHECK(consumer); |
| 61 DCHECK(wds_.get()); | 62 DCHECK(wds_.get()); |
| 62 | 63 |
| 63 IntentsQuery* query = new IntentsQuery; | 64 IntentsQuery* query = new IntentsQuery; |
| 64 query->query_id_ = next_query_id_++; | 65 query->query_id_ = next_query_id_++; |
| 65 query->consumer_ = consumer; | 66 query->consumer_ = consumer; |
| 66 query->pending_query_ = wds_->GetWebIntents(action, this); | 67 query->pending_query_ = wds_->GetWebIntents(action, this); |
| 67 queries[query->pending_query_] = query; | 68 queries_[query->pending_query_] = query; |
| 68 | 69 |
| 69 return query->query_id_; | 70 return query->query_id_; |
| 70 } | 71 } |
| 71 | 72 |
| 72 void WebIntentsRegistry::RegisterIntentProvider(const WebIntentData& intent) { | 73 void WebIntentsRegistry::RegisterIntentProvider(const WebIntentData& intent) { |
| 73 DCHECK(wds_.get()); | 74 DCHECK(wds_.get()); |
| 74 wds_->AddWebIntent(intent); | 75 wds_->AddWebIntent(intent); |
| 75 } | 76 } |
| 76 | 77 |
| 77 void WebIntentsRegistry::UnregisterIntentProvider(const WebIntentData& intent) { | 78 void WebIntentsRegistry::UnregisterIntentProvider(const WebIntentData& intent) { |
| 78 DCHECK(wds_.get()); | 79 DCHECK(wds_.get()); |
| 79 wds_->RemoveWebIntent(intent); | 80 wds_->RemoveWebIntent(intent); |
| 80 } | 81 } |
| OLD | NEW |