| 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();
|
| +}
|
|
|