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

Unified Diff: chrome/browser/intents/intents_registry.cc

Issue 7511005: Initial version of web intents registry (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Created 9 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 side-by-side diff with in-line comments
Download patch
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);
+}

Powered by Google App Engine
This is Rietveld 408576698