| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/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/intents/web_intent_data.h" | 11 #include "chrome/browser/intents/web_intent_data.h" |
| 12 #include "chrome/browser/webdata/web_data_service.h" | 12 #include "chrome/browser/webdata/web_data_service.h" |
| 13 | 13 |
| 14 // Handles storing and retrieving of web intents in the web database. | 14 // Handles storing and retrieving of web intents in the web database. |
| 15 // The registry provides filtering logic to retrieve specific types of intents. | 15 // The registry provides filtering logic to retrieve specific types of intents. |
| 16 class WebIntentsRegistry : public WebDataServiceConsumer { | 16 class WebIntentsRegistry |
| 17 : public WebDataServiceConsumer, |
| 18 public base::RefCountedThreadSafe<WebIntentsRegistry> { |
| 17 public: | 19 public: |
| 18 // Unique identifier for intent queries. | 20 // Unique identifier for intent queries. |
| 19 typedef int QueryID; | 21 typedef int QueryID; |
| 20 | 22 |
| 21 // An interface the WebIntentsRegistry uses to notify its clients when | 23 // An interface the WebIntentsRegistry uses to notify its clients when |
| 22 // it has finished loading intents data from the web database. | 24 // it has finished loading intents data from the web database. |
| 23 class Consumer { | 25 class Consumer { |
| 24 public: | 26 public: |
| 25 // Notifies the observer that the intents request has been completed. | 27 // Notifies the observer that the intents request has been completed. |
| 26 virtual void OnIntentsQueryDone( | 28 virtual void OnIntentsQueryDone( |
| 27 QueryID query_id, | 29 QueryID query_id, |
| 28 const std::vector<WebIntentData>& intents) = 0; | 30 const std::vector<WebIntentData>& intents) = 0; |
| 29 | 31 |
| 30 protected: | 32 protected: |
| 31 virtual ~Consumer() {} | 33 virtual ~Consumer() {} |
| 32 }; | 34 }; |
| 33 | 35 |
| 34 WebIntentsRegistry(); | |
| 35 virtual ~WebIntentsRegistry(); | |
| 36 | |
| 37 // Initializes, binds to a valid WebDataService. | 36 // Initializes, binds to a valid WebDataService. |
| 38 void Initialize(scoped_refptr<WebDataService> wds); | 37 void Initialize(scoped_refptr<WebDataService> wds); |
| 39 | 38 |
| 40 // Registers a web intent provider. | 39 // Registers a web intent provider. |
| 41 void RegisterIntentProvider(const WebIntentData& intent); | 40 virtual void RegisterIntentProvider(const WebIntentData& intent); |
| 42 | 41 |
| 43 // Removes a web intent provider from the registry. | 42 // Removes a web intent provider from the registry. |
| 44 void UnregisterIntentProvider(const WebIntentData& intent); | 43 void UnregisterIntentProvider(const WebIntentData& intent); |
| 45 | 44 |
| 46 // Requests all intent providers matching |action|. | 45 // Requests all intent providers matching |action|. |
| 47 // |consumer| must not be NULL. | 46 // |consumer| must not be NULL. |
| 48 QueryID GetIntentProviders(const string16& action, Consumer* consumer); | 47 QueryID GetIntentProviders(const string16& action, Consumer* consumer); |
| 49 | 48 |
| 49 protected: |
| 50 // Make sure that only Profile can create an instance of WebIntentsRegistry. |
| 51 friend class base::RefCountedThreadSafe<WebIntentsRegistry>; |
| 52 friend class ProfileImpl; |
| 53 friend class WebIntentsRegistryTest; |
| 54 |
| 55 WebIntentsRegistry(); |
| 56 virtual ~WebIntentsRegistry(); |
| 57 |
| 50 private: | 58 private: |
| 51 struct IntentsQuery; | 59 struct IntentsQuery; |
| 52 | 60 |
| 53 // Maps web data requests to intents queries. | 61 // Maps web data requests to intents queries. |
| 54 // Allows OnWebDataServiceRequestDone to forward to appropiate consumer. | 62 // Allows OnWebDataServiceRequestDone to forward to appropriate consumer. |
| 55 typedef base::hash_map<WebDataService::Handle, IntentsQuery*> QueryMap; | 63 typedef base::hash_map<WebDataService::Handle, IntentsQuery*> QueryMap; |
| 56 | 64 |
| 57 // WebDataServiceConsumer implementation. | 65 // WebDataServiceConsumer implementation. |
| 58 virtual void OnWebDataServiceRequestDone(WebDataService::Handle h, | 66 virtual void OnWebDataServiceRequestDone(WebDataService::Handle h, |
| 59 const WDTypedResult* result); | 67 const WDTypedResult* result); |
| 60 | 68 |
| 61 // Map for all in-flight web data requests/intent queries. | 69 // Map for all in-flight web data requests/intent queries. |
| 62 QueryMap queries_; | 70 QueryMap queries_; |
| 63 | 71 |
| 64 // Unique identifier for next intent query. | 72 // Unique identifier for next intent query. |
| 65 QueryID next_query_id_; | 73 QueryID next_query_id_; |
| 66 | 74 |
| 67 // Local reference to Web Data Service. | 75 // Local reference to Web Data Service. |
| 68 scoped_refptr<WebDataService> wds_; | 76 scoped_refptr<WebDataService> wds_; |
| 69 | 77 |
| 70 DISALLOW_COPY_AND_ASSIGN(WebIntentsRegistry); | 78 DISALLOW_COPY_AND_ASSIGN(WebIntentsRegistry); |
| 71 }; | 79 }; |
| 72 | 80 |
| 73 #endif // CHROME_BROWSER_INTENTS_WEB_INTENTS_REGISTRY_H_ | 81 #endif // CHROME_BROWSER_INTENTS_WEB_INTENTS_REGISTRY_H_ |
| OLD | NEW |