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 |
new file mode 100644 |
index 0000000000000000000000000000000000000000..84eb3a3b42c1e48f438c49a0024d25707f1903f6 |
--- /dev/null |
+++ b/chrome/browser/intents/web_intents_registry.cc |
@@ -0,0 +1,76 @@ |
+// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/intents/web_intents_registry.h" |
+#include "chrome/browser/webdata/web_data_service.h" |
+ |
+ // Internal object representing a single intents query. |
James Hawkins
2011/08/05 20:47:12
Indentation
groby-ooo-7-16
2011/08/05 20:54:11
Done.
|
+struct WebIntentsRegistry::IntentsQuery { |
+ // WebDataService returns data asynchronously from a separate thread, so |
+ // registry records the query handle until we get called back. |
+ QueryID query_id_; // unique query identifier. |
James Hawkins
2011/08/05 20:47:12
Indentation
groby-ooo-7-16
2011/08/05 20:54:11
Done.
|
+ WebDataService::Handle pending_query_; // Underlying data query. |
+ Consumer* consumer_; // the consumer for this particular query. |
+ |
+ // TODO(groby): Additional filter data will go here - filtering is handled |
+ // per query. |
+ }; |
+ |
+WebIntentsRegistry::WebIntentsRegistry() : next_query_id_(0) {} |
+ |
+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; |
+ } |
+} |
+ |
+void WebIntentsRegistry::Initialize(scoped_refptr<WebDataService> wds) { |
+ wds_ = wds; |
+} |
+ |
+void WebIntentsRegistry::OnWebDataServiceRequestDone(WebDataService::Handle h, |
+ const WDTypedResult* result) { |
James Hawkins
2011/08/05 20:47:12
line up params
groby-ooo-7-16
2011/08/05 20:54:11
Done.
|
+ DCHECK(result); |
+ 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); |
+ |
+ // TODO(groby): Filtering goes here. |
+ std::vector<WebIntentData> intents = static_cast< |
+ const WDResult<std::vector<WebIntentData> >*>(result)->GetValue(); |
+ |
+ query->consumer_->OnIntentsQueryDone(query->query_id_, intents); |
+} |
+ |
+WebIntentsRegistry::QueryID WebIntentsRegistry::GetIntentProviders( |
+ const string16& action, |
+ Consumer* consumer) { |
+ DCHECK(consumer); |
+ DCHECK(wds_.get()); |
+ |
+ IntentsQuery* query = new IntentsQuery; |
+ query->query_id_ = next_query_id_++; |
+ query->consumer_ = consumer; |
+ query->pending_query_ = wds_->GetWebIntents(action, this); |
+ queries[query->pending_query_] = query; |
+ |
+ return query->query_id_; |
+} |
+ |
+void WebIntentsRegistry::RegisterIntentProvider(const WebIntentData& intent) { |
+ DCHECK(wds_.get()); |
+ wds_->AddWebIntent(intent); |
+} |
+ |
+void WebIntentsRegistry::UnregisterIntentProvider(const WebIntentData& intent) { |
+ DCHECK(wds_.get()); |
+ wds_->RemoveWebIntent(intent); |
+} |