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

Unified Diff: chrome/browser/extensions/web_intent_callbacks.cc

Issue 10828172: Allow platform apps to respond to Web Intents (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Added WebIntentCallbacks profile keyed class to manage callbacks Created 8 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/extensions/web_intent_callbacks.cc
diff --git a/chrome/browser/extensions/web_intent_callbacks.cc b/chrome/browser/extensions/web_intent_callbacks.cc
new file mode 100644
index 0000000000000000000000000000000000000000..5412596dce6152ae3909c14960ee89837819601c
--- /dev/null
+++ b/chrome/browser/extensions/web_intent_callbacks.cc
@@ -0,0 +1,63 @@
+// Copyright (c) 2012 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 "base/stringprintf.h"
+#include "chrome/browser/extensions/web_intent_callbacks.h"
+#include "chrome/browser/profiles/profile_dependency_manager.h"
+#include "content/public/browser/web_intents_dispatcher.h"
+
+WebIntentCallbacks::WebIntentCallbacks() {}
+
+WebIntentCallbacks::~WebIntentCallbacks() {}
+
+// static
+WebIntentCallbacks* WebIntentCallbacks::Get(Profile* profile) {
+ return Factory::GetForProfile(profile);
+}
+
+std::string WebIntentCallbacks::RegisterCallback(
+ content::WebIntentsDispatcher* dispatcher) {
+ std::string key = StringPrintf("key_%d", last_id_++);
+
+ // TODO(thorogood): cleanup task, perhaps we can watch renderer threads.
+ pending_[key] = dispatcher;
+ return key;
+}
+
+content::WebIntentsDispatcher* WebIntentCallbacks::RetrieveCallback(
+ std::string key) {
+ if (key.empty() || !pending_.count(key))
+ return NULL;
+
+ content::WebIntentsDispatcher* dispatcher = pending_[key];
+ pending_.erase(key);
+ return dispatcher;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// Factory boilerplate
+
+// static
+WebIntentCallbacks* WebIntentCallbacks::Factory::GetForProfile(
+ Profile* profile) {
+ return static_cast<WebIntentCallbacks*>(
+ GetInstance()->GetServiceForProfile(profile, true));
+}
+
+WebIntentCallbacks::Factory* WebIntentCallbacks::Factory::GetInstance() {
+ return Singleton<WebIntentCallbacks::Factory>::get();
+}
+
+WebIntentCallbacks::Factory::Factory()
+ : ProfileKeyedServiceFactory("WebIntentCallbacks",
+ ProfileDependencyManager::GetInstance()) {
+}
+
+WebIntentCallbacks::Factory::~Factory() {
+}
+
+ProfileKeyedService* WebIntentCallbacks::Factory::BuildServiceInstanceFor(
+ Profile* profile) const {
+ return new WebIntentCallbacks();
+}

Powered by Google App Engine
This is Rietveld 408576698