Index: chrome/browser/intents/intents_registry.cc |
diff --git a/chrome/browser/intents/intents_registry.cc b/chrome/browser/intents/intents_registry.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..df0949fb4dc1ab68d96e6000de453d692f62ef9f |
--- /dev/null |
+++ b/chrome/browser/intents/intents_registry.cc |
@@ -0,0 +1,63 @@ |
+// 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/intents_registry.h" |
+#include "chrome/browser/webdata/web_data_service.h" |
+ |
+IntentsRegistry::IntentsRegistry() : next_query_id_(0) {} |
+ |
+IntentsRegistry::~IntentsRegistry() { |
+ // Cancel all pending queries, since we can't handle them any more. |
+ 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.
|
+ wds_->CancelRequest(it->first); |
+ } |
+} |
+ |
+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
|
+ wds_ = wds; |
+} |
+ |
+void IntentsRegistry::OnWebDataServiceRequestDone(WebDataService::Handle h, |
+ const WDTypedResult* result) { |
+ 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); |
+} |
+ |
+IntentsRegistry::QueryID IntentsRegistry::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 IntentsRegistry::RegisterIntentProvider(const WebIntentData& intent) { |
+ DCHECK(wds_.get()); |
+ wds_->AddWebIntent(intent); |
+} |
+ |
+void IntentsRegistry::UnregisterIntentProvider(const WebIntentData& intent) { |
+ DCHECK(wds_.get()); |
+ wds_->RemoveWebIntent(intent); |
+} |