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