| OLD | NEW |
| (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_INTENTS_WEB_INTENTS_REGISTRY_H_ | |
| 6 #define CHROME_BROWSER_INTENTS_WEB_INTENTS_REGISTRY_H_ | |
| 7 | |
| 8 #include "base/callback_forward.h" | |
| 9 #include "base/hash_tables.h" | |
| 10 #include "base/memory/ref_counted.h" | |
| 11 #include "chrome/browser/extensions/extension_service.h" | |
| 12 #include "chrome/browser/profiles/profile_keyed_service.h" | |
| 13 #include "chrome/browser/webdata/web_data_service.h" | |
| 14 #include "webkit/glue/web_intent_service_data.h" | |
| 15 | |
| 16 struct DefaultWebIntentService; | |
| 17 | |
| 18 namespace extensions { | |
| 19 class Extension; | |
| 20 } | |
| 21 | |
| 22 namespace web_intents { | |
| 23 class NativeServiceRegistry; | |
| 24 } | |
| 25 | |
| 26 // Handles storing and retrieving of web intents services in the web database. | |
| 27 // The registry provides filtering logic to retrieve specific types of services. | |
| 28 class WebIntentsRegistry : public ProfileKeyedService { | |
| 29 public: | |
| 30 typedef std::vector<webkit_glue::WebIntentServiceData> IntentServiceList; | |
| 31 typedef std::vector<DefaultWebIntentService> DefaultIntentServiceList; | |
| 32 | |
| 33 // Callback used by callers to accept results of a query for | |
| 34 // a list of |WebIntentServiceData|. | |
| 35 typedef base::Callback<void(const IntentServiceList&)> | |
| 36 QueryCallback; | |
| 37 | |
| 38 // Callback used by callers to accept results of a query for | |
| 39 // a list of |DefaultWebIntentService|. | |
| 40 typedef base::Callback<void(const DefaultIntentServiceList&)> | |
| 41 DefaultIntentServicesCallback; | |
| 42 | |
| 43 // Callback used by callers to accept results of a query for | |
| 44 // a |DefaultWebIntentService|. | |
| 45 typedef base::Callback<void(const DefaultWebIntentService&)> | |
| 46 DefaultQueryCallback; | |
| 47 | |
| 48 // Initializes, binds to a valid WebDataService. | |
| 49 void Initialize(scoped_refptr<WebDataService> wds, | |
| 50 ExtensionServiceInterface* extension_service); | |
| 51 | |
| 52 // Registers a service. | |
| 53 virtual void RegisterIntentService( | |
| 54 const webkit_glue::WebIntentServiceData& service); | |
| 55 | |
| 56 // Removes a service from the registry. | |
| 57 void UnregisterIntentService( | |
| 58 const webkit_glue::WebIntentServiceData& service); | |
| 59 | |
| 60 // Requests all services matching |action| and |type|. | |
| 61 // |type| can contain wildcards, i.e. "image/*" or "*". | |
| 62 // |callback| must not be null. | |
| 63 void GetIntentServices(const string16& action, | |
| 64 const string16& type, | |
| 65 const QueryCallback& callback); | |
| 66 | |
| 67 // Requests all services. | |
| 68 // |callback| must not be null. | |
| 69 void GetAllIntentServices(const QueryCallback& callback); | |
| 70 | |
| 71 // Requests all default services. | |
| 72 // |callback| must not be null. | |
| 73 void GetAllDefaultIntentServices( | |
| 74 const DefaultIntentServicesCallback& callback); | |
| 75 | |
| 76 // Tests for the existence of the given |service|. Calls the | |
| 77 // provided |callback| with true if it exists, false if it does not. | |
| 78 // Checks for |service| equality with ==. | |
| 79 // |callback| must not be null. | |
| 80 void IntentServiceExists( | |
| 81 const webkit_glue::WebIntentServiceData& service, | |
| 82 const base::Callback<void(bool)>& callback); | |
| 83 | |
| 84 // Requests all extension services matching |action|, |type| and | |
| 85 // |extension_id|. | |
| 86 // |type| must conform to definition as outlined for GetIntentServices. | |
| 87 // |callback| must not be null. | |
| 88 void GetIntentServicesForExtensionFilter(const string16& action, | |
| 89 const string16& type, | |
| 90 const std::string& extension_id, | |
| 91 IntentServiceList* services); | |
| 92 | |
| 93 // Record the given default service entry. | |
| 94 virtual void RegisterDefaultIntentService( | |
| 95 const DefaultWebIntentService& default_service); | |
| 96 | |
| 97 // Delete the given default service entry. Deletes entries matching | |
| 98 // the |action|, |type|, and |url_pattern| of |default_service|. | |
| 99 virtual void UnregisterDefaultIntentService( | |
| 100 const DefaultWebIntentService& default_service); | |
| 101 | |
| 102 // Delete all default service entries associated with |service_url|. | |
| 103 virtual void UnregisterServiceDefaults(const GURL& service_url); | |
| 104 | |
| 105 // Requests the best default intent service for the given invocation | |
| 106 // parameters. | |
| 107 // |callback| must not be null. | |
| 108 void GetDefaultIntentService(const string16& action, | |
| 109 const string16& type, | |
| 110 const GURL& invoking_url, | |
| 111 const DefaultQueryCallback& callback); | |
| 112 | |
| 113 protected: | |
| 114 // Make sure that only WebIntentsRegistryFactory can create an instance of | |
| 115 // WebIntentsRegistry. | |
| 116 friend class WebIntentsRegistryFactory; | |
| 117 friend class WebIntentsRegistryTest; | |
| 118 FRIEND_TEST_ALL_PREFIXES(WebIntentsRegistryTest, CollapseIntents); | |
| 119 | |
| 120 WebIntentsRegistry(); | |
| 121 virtual ~WebIntentsRegistry(); | |
| 122 | |
| 123 // Collapses a list of IntentServices by joining intents that have identical | |
| 124 // service URLs, actions, and mime types. | |
| 125 // |services| is the list of intent services to be collapsed when passed in | |
| 126 // and will be modified with the new list in-place. | |
| 127 void CollapseIntents(IntentServiceList* services); | |
| 128 | |
| 129 private: | |
| 130 struct QueryParams; | |
| 131 class QueryAdapter; | |
| 132 typedef std::vector<QueryAdapter*> QueryVector; | |
| 133 | |
| 134 // Handles services loaded | |
| 135 void OnWebIntentsResultReceived( | |
| 136 const QueryParams& params, | |
| 137 const QueryCallback& callback, | |
| 138 const WDTypedResult* result); | |
| 139 | |
| 140 // Handles default services loaded, supplying an unfiltered list | |
| 141 // to the callback. | |
| 142 void OnAllDefaultIntentServicesReceived( | |
| 143 const DefaultIntentServicesCallback& callback, | |
| 144 const WDTypedResult* result); | |
| 145 | |
| 146 // Handles default services loaded | |
| 147 void OnWebIntentsDefaultsResultReceived( | |
| 148 const QueryParams& params, | |
| 149 const DefaultQueryCallback& callback, | |
| 150 const WDTypedResult* result); | |
| 151 | |
| 152 const extensions::Extension* ExtensionForURL(const std::string& url); | |
| 153 | |
| 154 // Adds a query to the list of pending queries. | |
| 155 void TrackQuery(QueryAdapter* query); | |
| 156 | |
| 157 // Takes ownership of a query. This removes a query from the list | |
| 158 // of pending queries. | |
| 159 void ReleaseQuery(QueryAdapter* query); | |
| 160 | |
| 161 // Map for all in-flight web data requests/intent queries. | |
| 162 QueryVector pending_queries_; | |
| 163 | |
| 164 // Local reference to Web Data Service. | |
| 165 scoped_refptr<WebDataService> wds_; | |
| 166 | |
| 167 // Local reference to the ExtensionService. | |
| 168 // Shutdown/cleanup is handled by ProfileImpl. We are guaranteed that any | |
| 169 // ProfileKeyedService will be shut down before data on ProfileImpl is | |
| 170 // destroyed (i.e. |extension_service_|), so |extension_service_| is valid | |
| 171 // for the lifetime of the WebIntentsRegistry object. | |
| 172 ExtensionServiceInterface* extension_service_; | |
| 173 | |
| 174 // Registry used to obtain list of supported native services. | |
| 175 scoped_ptr<web_intents::NativeServiceRegistry> native_services_; | |
| 176 | |
| 177 DISALLOW_COPY_AND_ASSIGN(WebIntentsRegistry); | |
| 178 }; | |
| 179 | |
| 180 #endif // CHROME_BROWSER_INTENTS_WEB_INTENTS_REGISTRY_H_ | |
| OLD | NEW |