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

Side by Side Diff: chrome/browser/extensions/web_intent_callbacks.h

Issue 10828172: Allow platform apps to respond to Web Intents (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: comments 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_EXTENSIONS_WEB_INTENT_CALLBACKS_H_
6 #define CHROME_BROWSER_EXTENSIONS_WEB_INTENT_CALLBACKS_H_
7
8 #include <set>
9
10 #include "base/compiler_specific.h"
11 #include "base/memory/singleton.h"
12 #include "base/observer_list.h"
13 #include "chrome/browser/profiles/profile_keyed_service.h"
14 #include "chrome/browser/profiles/profile_keyed_service_factory.h"
15 #include "content/public/browser/web_contents_observer.h"
16 #include "ui/gfx/native_widget_types.h"
17 #include "webkit/glue/web_intent_reply_data.h"
18
19 class Profile;
20
21 namespace content {
22 class WebIntentsDispatcher;
23 }
24
25 namespace extensions {
26 class Extension;
27
28 // The WebIntentCallbacks class tracks the pending callbacks for web intents
29 // that have been delivered to platform apps, for a particular profile.
30 class WebIntentCallbacks : public ProfileKeyedService {
31 public:
32 WebIntentCallbacks();
33 virtual ~WebIntentCallbacks();
34
35 // Returns the instance for the given profile. This is a convenience wrapper
36 // around WebIntentCallbacks::Factory::GetForProfile.
37 static WebIntentCallbacks* Get(Profile* profile);
38
39 // Registers the callback for the Web Intent we're about to dispatch to the
40 // given extension. Returns an identifier that should later be dispatched to
41 // RetrieveCallback in order to invoke the callback registered here.
42 int RegisterCallback(const Extension* extension,
43 content::WebIntentsDispatcher* dispatcher);
44
45 // Retrieves the callback for the given identifier, for a response from the
46 // specified extension. This will clear the callback. If there is no callback
47 // registered under this identifier, then this will return NULL.
48 content::WebIntentsDispatcher* RetrieveCallback(const Extension* extension,
49 int intent_id);
50
51 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.
52
53 private:
54 typedef std::map<std::string, content::WebIntentsDispatcher*> CallbackMap;
55
56 class Factory : public ProfileKeyedServiceFactory {
57 public:
58 static WebIntentCallbacks* GetForProfile(Profile* profile);
59
60 static Factory* GetInstance();
61 private:
62 friend struct DefaultSingletonTraits<Factory>;
63
64 Factory();
65 virtual ~Factory();
66
67 // ProfileKeyedServiceFactory
68 virtual ProfileKeyedService* BuildServiceInstanceFor(
69 Profile* profile) const OVERRIDE;
70 };
71
72 // Provided as a closure to WebIntentsDispatcher::RegisterReplyNotification.
73 // This is invoked when either the intent is replied to, or the service page
74 // (aka, the caller) disappears. This allows us to clear callbacks when the
75 // call is complete.
76 void OnIntentReply(std::string key,
77 webkit_glue::WebIntentReplyType reply_type);
78
79 // Used as an incrementing ID for callback keys.
80 int last_id_;
81
82 // Stores all pending callbacks. Callbacks are automatically cleared via
83 // OnIntentReply.
84 CallbackMap pending_;
85 };
86
87 } // namespace extensions
88
89 #endif // CHROME_BROWSER_EXTENSIONS_WEB_INTENT_CALLBACKS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698