| 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/callback_forward.h" | 9 #include "base/callback_forward.h" |
| 10 #include "base/hash_tables.h" | 10 #include "base/hash_tables.h" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "chrome/browser/extensions/extension_service.h" | 12 #include "chrome/browser/extensions/extension_service.h" |
| 13 #include "chrome/browser/profiles/profile_keyed_service.h" | 13 #include "chrome/browser/profiles/profile_keyed_service.h" |
| 14 #include "chrome/browser/webdata/web_data_service.h" | 14 #include "chrome/browser/webdata/web_data_service.h" |
| 15 #include "webkit/glue/web_intent_service_data.h" | 15 #include "webkit/glue/web_intent_service_data.h" |
| 16 | 16 |
| 17 struct DefaultWebIntentService; |
| 18 |
| 17 // Handles storing and retrieving of web intents services in the web database. | 19 // Handles storing and retrieving of web intents services in the web database. |
| 18 // The registry provides filtering logic to retrieve specific types of services. | 20 // The registry provides filtering logic to retrieve specific types of services. |
| 19 class WebIntentsRegistry | 21 class WebIntentsRegistry |
| 20 : public WebDataServiceConsumer, | 22 : public WebDataServiceConsumer, |
| 21 public ProfileKeyedService { | 23 public ProfileKeyedService { |
| 22 public: | 24 public: |
| 23 // Unique identifier for service queries. | 25 // Unique identifier for service queries. |
| 24 typedef int QueryID; | 26 typedef int QueryID; |
| 25 | 27 |
| 26 typedef std::vector<webkit_glue::WebIntentServiceData> IntentServiceList; | 28 typedef std::vector<webkit_glue::WebIntentServiceData> IntentServiceList; |
| 27 | 29 |
| 28 // An interface the WebIntentsRegistry uses to notify its clients when | 30 // An interface the WebIntentsRegistry uses to notify its clients when |
| 29 // it has finished loading service data from the web database. | 31 // it has finished loading service data from the web database. |
| 30 class Consumer { | 32 class Consumer { |
| 31 public: | 33 public: |
| 32 // Notifies the observer that the request has been | 34 // Notifies the observer that the request has been |
| 33 // completed. | 35 // completed. |
| 34 virtual void OnIntentsQueryDone( | 36 virtual void OnIntentsQueryDone( |
| 35 QueryID query_id, | 37 QueryID query_id, |
| 36 const IntentServiceList& services) = 0; | 38 const IntentServiceList& services) = 0; |
| 37 | 39 |
| 40 // Notifies the observer that a request for intents default service |
| 41 // has been completed. If no default is found, the |default_service| |
| 42 // service_url field will be empty. |
| 43 virtual void OnIntentsDefaultsQueryDone( |
| 44 QueryID query_id, |
| 45 const DefaultWebIntentService& default_service) = 0; |
| 46 |
| 38 protected: | 47 protected: |
| 39 virtual ~Consumer() {} | 48 virtual ~Consumer() {} |
| 40 }; | 49 }; |
| 41 | 50 |
| 42 // Initializes, binds to a valid WebDataService. | 51 // Initializes, binds to a valid WebDataService. |
| 43 void Initialize(scoped_refptr<WebDataService> wds, | 52 void Initialize(scoped_refptr<WebDataService> wds, |
| 44 ExtensionServiceInterface* extension_service); | 53 ExtensionServiceInterface* extension_service); |
| 45 | 54 |
| 46 // Registers a service. | 55 // Registers a service. |
| 47 virtual void RegisterIntentService( | 56 virtual void RegisterIntentService( |
| (...skipping 13 matching lines...) Expand all Loading... |
| 61 // Requests all services. |consumer| must not be NULL | 70 // Requests all services. |consumer| must not be NULL |
| 62 QueryID GetAllIntentServices(Consumer* consumer); | 71 QueryID GetAllIntentServices(Consumer* consumer); |
| 63 | 72 |
| 64 // Tests for the existence of the given |service|. Calls the | 73 // Tests for the existence of the given |service|. Calls the |
| 65 // provided |callback| with true if it exists, false if it does not. | 74 // provided |callback| with true if it exists, false if it does not. |
| 66 // Checks for |service| equality with ==. | 75 // Checks for |service| equality with ==. |
| 67 QueryID IntentServiceExists( | 76 QueryID IntentServiceExists( |
| 68 const webkit_glue::WebIntentServiceData& service, | 77 const webkit_glue::WebIntentServiceData& service, |
| 69 const base::Callback<void(bool)>& callback); | 78 const base::Callback<void(bool)>& callback); |
| 70 | 79 |
| 80 // Record the given default service entry. |
| 81 virtual void RegisterDefaultIntentService( |
| 82 const DefaultWebIntentService& default_service); |
| 83 |
| 84 // Delete the given default service entry. Deletes entries matching |
| 85 // the |action|, |type|, and |url_pattern| of |default_service|. |
| 86 virtual void UnregisterDefaultIntentService( |
| 87 const DefaultWebIntentService& default_service); |
| 88 |
| 89 // Requests the best default intent service for the given invocation |
| 90 // parameters. |
| 91 QueryID GetDefaultIntentService(const string16& action, |
| 92 const string16& type, |
| 93 const GURL& invoking_url, |
| 94 Consumer* consumer); |
| 95 |
| 71 protected: | 96 protected: |
| 72 // Make sure that only WebIntentsRegistryFactory can create an instance of | 97 // Make sure that only WebIntentsRegistryFactory can create an instance of |
| 73 // WebIntentsRegistry. | 98 // WebIntentsRegistry. |
| 74 friend class WebIntentsRegistryFactory; | 99 friend class WebIntentsRegistryFactory; |
| 75 friend class WebIntentsRegistryTest; | 100 friend class WebIntentsRegistryTest; |
| 76 friend class WebIntentsModelTest; | 101 friend class WebIntentsModelTest; |
| 77 | 102 |
| 78 WebIntentsRegistry(); | 103 WebIntentsRegistry(); |
| 79 virtual ~WebIntentsRegistry(); | 104 virtual ~WebIntentsRegistry(); |
| 80 | 105 |
| 81 private: | 106 private: |
| 107 bool IsContainingExtensionDisabled(const std::string& url); |
| 108 |
| 82 struct IntentsQuery; | 109 struct IntentsQuery; |
| 83 | 110 |
| 84 // Maps web data requests to intents queries. | 111 // Maps web data requests to intents queries. |
| 85 // Allows OnWebDataServiceRequestDone to forward to appropriate consumer. | 112 // Allows OnWebDataServiceRequestDone to forward to appropriate consumer. |
| 86 typedef base::hash_map<WebDataService::Handle, IntentsQuery*> QueryMap; | 113 typedef base::hash_map<WebDataService::Handle, IntentsQuery*> QueryMap; |
| 87 | 114 |
| 88 // WebDataServiceConsumer implementation. | 115 // WebDataServiceConsumer implementation. |
| 89 virtual void OnWebDataServiceRequestDone( | 116 virtual void OnWebDataServiceRequestDone( |
| 90 WebDataService::Handle h, | 117 WebDataService::Handle h, |
| 91 const WDTypedResult* result) OVERRIDE; | 118 const WDTypedResult* result) OVERRIDE; |
| 92 | 119 |
| 120 // Delegate for defaults requests from OnWebDataServiceRequestDone. |
| 121 virtual void OnWebDataServiceDefaultsRequestDone( |
| 122 WebDataService::Handle h, |
| 123 const WDTypedResult* result); |
| 124 |
| 93 // Map for all in-flight web data requests/intent queries. | 125 // Map for all in-flight web data requests/intent queries. |
| 94 QueryMap queries_; | 126 QueryMap queries_; |
| 95 | 127 |
| 96 // Unique identifier for next intent query. | 128 // Unique identifier for next intent query. |
| 97 QueryID next_query_id_; | 129 QueryID next_query_id_; |
| 98 | 130 |
| 99 // Local reference to Web Data Service. | 131 // Local reference to Web Data Service. |
| 100 scoped_refptr<WebDataService> wds_; | 132 scoped_refptr<WebDataService> wds_; |
| 101 | 133 |
| 102 // Local reference to the ExtensionService. | 134 // Local reference to the ExtensionService. |
| 103 // Shutdown/cleanup is handled by ProfileImpl. We are guaranteed that any | 135 // Shutdown/cleanup is handled by ProfileImpl. We are guaranteed that any |
| 104 // ProfileKeyedService will be shut down before data on ProfileImpl is | 136 // ProfileKeyedService will be shut down before data on ProfileImpl is |
| 105 // destroyed (i.e. |extension_service_|), so |extension_service_| is valid | 137 // destroyed (i.e. |extension_service_|), so |extension_service_| is valid |
| 106 // for the lifetime of the WebIntentsRegistry object. | 138 // for the lifetime of the WebIntentsRegistry object. |
| 107 ExtensionServiceInterface* extension_service_; | 139 ExtensionServiceInterface* extension_service_; |
| 108 | 140 |
| 109 DISALLOW_COPY_AND_ASSIGN(WebIntentsRegistry); | 141 DISALLOW_COPY_AND_ASSIGN(WebIntentsRegistry); |
| 110 }; | 142 }; |
| 111 | 143 |
| 112 #endif // CHROME_BROWSER_INTENTS_WEB_INTENTS_REGISTRY_H_ | 144 #endif // CHROME_BROWSER_INTENTS_WEB_INTENTS_REGISTRY_H_ |
| OLD | NEW |