OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_INTENTS_WEB_INTENTS_REGISTRY_H_ | 5 #ifndef CHROME_BROWSER_INTENTS_WEB_INTENTS_REGISTRY_H_ |
6 #define CHROME_BROWSER_INTENTS_WEB_INTENTS_REGISTRY_H_ | 6 #define CHROME_BROWSER_INTENTS_WEB_INTENTS_REGISTRY_H_ |
7 | 7 |
8 #include "base/callback_forward.h" | 8 #include "base/callback_forward.h" |
9 #include "base/hash_tables.h" | 9 #include "base/hash_tables.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
11 #include "chrome/browser/extensions/extension_service.h" | 11 #include "chrome/browser/extensions/extension_service.h" |
12 #include "chrome/browser/profiles/profile_keyed_service.h" | 12 #include "chrome/browser/profiles/profile_keyed_service.h" |
13 #include "chrome/browser/webdata/web_data_service.h" | 13 #include "chrome/browser/webdata/web_data_service.h" |
14 #include "webkit/glue/web_intent_service_data.h" | 14 #include "webkit/glue/web_intent_service_data.h" |
15 | 15 |
16 struct DefaultWebIntentService; | 16 struct DefaultWebIntentService; |
17 | 17 |
18 namespace extensions { | 18 namespace extensions { |
19 class Extension; | 19 class Extension; |
20 } | 20 } |
21 | 21 |
22 // Handles storing and retrieving of web intents services in the web database. | 22 // Handles storing and retrieving of web intents services in the web database. |
23 // The registry provides filtering logic to retrieve specific types of services. | 23 // The registry provides filtering logic to retrieve specific types of services. |
24 class WebIntentsRegistry | 24 class WebIntentsRegistry : public ProfileKeyedService { |
25 : public WebDataServiceConsumer, | |
26 public ProfileKeyedService { | |
27 public: | 25 public: |
28 typedef std::vector<webkit_glue::WebIntentServiceData> IntentServiceList; | 26 typedef std::vector<webkit_glue::WebIntentServiceData> IntentServiceList; |
29 | 27 |
30 // Callback used by WebIntentsRegistry to return results of data fetch. | 28 // Callback used by WebIntentsRegistry to return results of data fetch. |
31 typedef base::Callback<void(const IntentServiceList&)> | 29 typedef base::Callback<void(const IntentServiceList&)> |
32 QueryCallback; | 30 QueryCallback; |
33 | 31 |
34 // Callback to return results of a defaults query. | 32 // Callback to return results of a defaults query. |
35 typedef base::Callback<void(const DefaultWebIntentService&)> | 33 typedef base::Callback<void(const DefaultWebIntentService&)> |
36 DefaultQueryCallback; | 34 DefaultQueryCallback; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
103 WebIntentsRegistry(); | 101 WebIntentsRegistry(); |
104 virtual ~WebIntentsRegistry(); | 102 virtual ~WebIntentsRegistry(); |
105 | 103 |
106 // Collapses a list of IntentServices by joining intents that have identical | 104 // Collapses a list of IntentServices by joining intents that have identical |
107 // service URLs, actions, and mime types. | 105 // service URLs, actions, and mime types. |
108 // |services| is the list of intent services to be collapsed when passed in | 106 // |services| is the list of intent services to be collapsed when passed in |
109 // and will be modified with the new list in-place. | 107 // and will be modified with the new list in-place. |
110 void CollapseIntents(IntentServiceList* services); | 108 void CollapseIntents(IntentServiceList* services); |
111 | 109 |
112 private: | 110 private: |
113 const extensions::Extension* ExtensionForURL(const std::string& url); | 111 const extensions::Extension* ExtensionForURL(const std::string& url); |
114 | 112 |
115 struct IntentsQuery; | 113 struct IntentsQuery; |
114 typedef std::vector<IntentsQuery*> QueryVector; | |
116 | 115 |
117 // Maps web data requests to intents queries. | 116 // Handles services loaded |
118 // Allows OnWebDataServiceRequestDone to forward to appropriate consumer. | 117 void OnWebIntentsResultReceived( |
119 typedef base::hash_map<WebDataService::Handle, IntentsQuery*> QueryMap; | 118 IntentsQuery* query, |
120 | |
121 // WebDataServiceConsumer implementation. | |
122 virtual void OnWebDataServiceRequestDone( | |
123 WebDataService::Handle h, | |
124 const WDTypedResult* result) OVERRIDE; | |
125 | |
126 // Delegate for defaults requests from OnWebDataServiceRequestDone. | |
127 virtual void OnWebDataServiceDefaultsRequestDone( | |
128 WebDataService::Handle h, | 119 WebDataService::Handle h, |
129 const WDTypedResult* result); | 120 const WDTypedResult* result); |
130 | 121 |
122 // Handles default services loaded | |
123 void OnWebIntentsDefaultsResultReceived( | |
124 IntentsQuery* query, | |
125 WebDataService::Handle h, | |
126 const WDTypedResult* result); | |
127 | |
131 // Implementation of GetIntentServicesForExtensionFilter. | 128 // Implementation of GetIntentServicesForExtensionFilter. |
132 void DoGetIntentServicesForExtensionFilter(scoped_ptr<IntentsQuery> query, | 129 void DoGetIntentServicesForExtensionFilter(scoped_ptr<IntentsQuery> query, |
133 const std::string& extension_id); | 130 const std::string& extension_id); |
134 | 131 |
132 // Adds a query to the list of pending queries. | |
133 void TrackQuery(IntentsQuery* query); | |
134 | |
135 // Takes ownership of a query. This removes a query from the list | |
136 // of pending queries. | |
137 bool ClaimQuery(IntentsQuery* query); | |
Greg Billock
2012/07/27 00:41:29
How about UntrackQuery?
| |
138 | |
135 // Map for all in-flight web data requests/intent queries. | 139 // Map for all in-flight web data requests/intent queries. |
136 QueryMap queries_; | 140 QueryVector pending_queries_; |
groby-ooo-7-16
2012/07/27 00:11:26
Why no map?
Steve McKay
2012/07/27 00:54:46
The map only existed to associate wds handles with
| |
137 | 141 |
138 // Local reference to Web Data Service. | 142 // Local reference to Web Data Service. |
139 scoped_refptr<WebDataService> wds_; | 143 scoped_refptr<WebDataService> wds_; |
140 | 144 |
141 // Local reference to the ExtensionService. | 145 // Local reference to the ExtensionService. |
142 // Shutdown/cleanup is handled by ProfileImpl. We are guaranteed that any | 146 // Shutdown/cleanup is handled by ProfileImpl. We are guaranteed that any |
143 // ProfileKeyedService will be shut down before data on ProfileImpl is | 147 // ProfileKeyedService will be shut down before data on ProfileImpl is |
144 // destroyed (i.e. |extension_service_|), so |extension_service_| is valid | 148 // destroyed (i.e. |extension_service_|), so |extension_service_| is valid |
145 // for the lifetime of the WebIntentsRegistry object. | 149 // for the lifetime of the WebIntentsRegistry object. |
146 ExtensionServiceInterface* extension_service_; | 150 ExtensionServiceInterface* extension_service_; |
147 | 151 |
148 DISALLOW_COPY_AND_ASSIGN(WebIntentsRegistry); | 152 DISALLOW_COPY_AND_ASSIGN(WebIntentsRegistry); |
149 }; | 153 }; |
150 | 154 |
151 #endif // CHROME_BROWSER_INTENTS_WEB_INTENTS_REGISTRY_H_ | 155 #endif // CHROME_BROWSER_INTENTS_WEB_INTENTS_REGISTRY_H_ |
OLD | NEW |