Chromium Code Reviews| Index: chrome/browser/extensions/web_intent_callbacks.h |
| diff --git a/chrome/browser/extensions/web_intent_callbacks.h b/chrome/browser/extensions/web_intent_callbacks.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..8b3fca1a7a33f601205e7d9076bfa940ed0288c4 |
| --- /dev/null |
| +++ b/chrome/browser/extensions/web_intent_callbacks.h |
| @@ -0,0 +1,89 @@ |
| +// 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. |
| + |
| +#ifndef CHROME_BROWSER_EXTENSIONS_WEB_INTENT_CALLBACKS_H_ |
| +#define CHROME_BROWSER_EXTENSIONS_WEB_INTENT_CALLBACKS_H_ |
| + |
| +#include <set> |
| + |
| +#include "base/compiler_specific.h" |
| +#include "base/memory/singleton.h" |
| +#include "base/observer_list.h" |
| +#include "chrome/browser/profiles/profile_keyed_service.h" |
| +#include "chrome/browser/profiles/profile_keyed_service_factory.h" |
| +#include "content/public/browser/web_contents_observer.h" |
| +#include "ui/gfx/native_widget_types.h" |
| +#include "webkit/glue/web_intent_reply_data.h" |
| + |
| +class Profile; |
| + |
| +namespace content { |
| +class WebIntentsDispatcher; |
| +} |
| + |
| +namespace extensions { |
| +class Extension; |
| + |
| +// The WebIntentCallbacks class tracks the pending callbacks for web intents |
| +// that have been delivered to platform apps, for a particular profile. |
| +class WebIntentCallbacks : public ProfileKeyedService { |
| + public: |
| + WebIntentCallbacks(); |
| + virtual ~WebIntentCallbacks(); |
| + |
| + // Returns the instance for the given profile. This is a convenience wrapper |
| + // around WebIntentCallbacks::Factory::GetForProfile. |
| + static WebIntentCallbacks* Get(Profile* profile); |
| + |
| + // Registers the callback for the Web Intent we're about to dispatch to the |
| + // given extension. Returns an identifier that should later be dispatched to |
| + // RetrieveCallback in order to invoke the callback registered here. |
| + int RegisterCallback(const Extension* extension, |
| + content::WebIntentsDispatcher* dispatcher); |
| + |
| + // Retrieves the callback for the given identifier, for a response from the |
| + // specified extension. This will clear the callback. If there is no callback |
| + // registered under this identifier, then this will return NULL. |
| + content::WebIntentsDispatcher* RetrieveCallback(const Extension* extension, |
| + int intent_id); |
| + |
| + void InternalClearCallback(std::string key); |
|
Mihai Parparita -not on Chrome
2012/08/11 00:25:45
This appears to be unused (and undefined).
thorogood
2012/08/13 05:00:12
Removed, I used to use this internally.
|
| + |
| + private: |
| + typedef std::map<std::string, content::WebIntentsDispatcher*> CallbackMap; |
| + |
| + class Factory : public ProfileKeyedServiceFactory { |
| + public: |
| + static WebIntentCallbacks* GetForProfile(Profile* profile); |
| + |
| + static Factory* GetInstance(); |
| + private: |
| + friend struct DefaultSingletonTraits<Factory>; |
| + |
| + Factory(); |
| + virtual ~Factory(); |
| + |
| + // ProfileKeyedServiceFactory |
| + virtual ProfileKeyedService* BuildServiceInstanceFor( |
| + Profile* profile) const OVERRIDE; |
| + }; |
| + |
| + // Provided as a closure to WebIntentsDispatcher::RegisterReplyNotification. |
| + // This is invoked when either the intent is replied to, or the service page |
| + // (aka, the caller) disappears. This allows us to clear callbacks when the |
| + // call is complete. |
| + void OnIntentReply(std::string key, |
| + webkit_glue::WebIntentReplyType reply_type); |
| + |
| + // Used as an incrementing ID for callback keys. |
| + int last_id_; |
| + |
| + // Stores all pending callbacks. Callbacks are automatically cleared via |
| + // OnIntentReply. |
| + CallbackMap pending_; |
| +}; |
| + |
| +} // namespace extensions |
| + |
| +#endif // CHROME_BROWSER_EXTENSIONS_WEB_INTENT_CALLBACKS_H_ |