| 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_CWS_INTENTS_REGISTRY_H_ | 5 #ifndef CHROME_BROWSER_INTENTS_CWS_INTENTS_REGISTRY_H_ |
| 6 #define CHROME_BROWSER_INTENTS_CWS_INTENTS_REGISTRY_H_ | 6 #define CHROME_BROWSER_INTENTS_CWS_INTENTS_REGISTRY_H_ |
| 7 | 7 |
| 8 #include "base/callback_forward.h" | 8 #include "base/callback_forward.h" |
| 9 #include "base/gtest_prod_util.h" | 9 #include "base/gtest_prod_util.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/profiles/profile_keyed_service.h" | 12 #include "chrome/browser/profiles/profile_keyed_service.h" |
| 13 #include "googleurl/src/gurl.h" | 13 #include "googleurl/src/gurl.h" |
| 14 #include "net/url_request/url_fetcher_delegate.h" | 14 #include "net/url_request/url_fetcher_delegate.h" |
| 15 | 15 |
| 16 namespace net { | 16 namespace net { |
| 17 class URLRequestContextGetter; | 17 class URLRequestContextGetter; |
| 18 } | 18 } |
| 19 | 19 |
| 20 class CWSIntentsRegistryForTest; |
| 21 |
| 20 // Handles storing and retrieving of web intents in the web database. | 22 // Handles storing and retrieving of web intents in the web database. |
| 21 // The registry provides filtering logic to retrieve specific types of intents. | 23 // The registry provides filtering logic to retrieve specific types of intents. |
| 22 class CWSIntentsRegistry : public ProfileKeyedService, | 24 class CWSIntentsRegistry : public ProfileKeyedService, |
| 23 public net::URLFetcherDelegate { | 25 public net::URLFetcherDelegate { |
| 24 public: | 26 public: |
| 25 // Data returned from CWS for a single service. | 27 // Data returned from CWS for a single service. |
| 26 struct IntentExtensionInfo { | 28 struct IntentExtensionInfo { |
| 27 IntentExtensionInfo(); | 29 IntentExtensionInfo(); |
| 28 ~IntentExtensionInfo(); | 30 ~IntentExtensionInfo(); |
| 29 | 31 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 49 const string16& mimetype, | 51 const string16& mimetype, |
| 50 const ResultsCallback& callback); | 52 const ResultsCallback& callback); |
| 51 | 53 |
| 52 // Build a REST query URL to retrieve intent info from CWS. | 54 // Build a REST query URL to retrieve intent info from CWS. |
| 53 static GURL BuildQueryURL(const string16& action, const string16& type); | 55 static GURL BuildQueryURL(const string16& action, const string16& type); |
| 54 | 56 |
| 55 private: | 57 private: |
| 56 // Make sure that only CWSIntentsRegistryFactory can create an instance of | 58 // Make sure that only CWSIntentsRegistryFactory can create an instance of |
| 57 // CWSIntentsRegistry. | 59 // CWSIntentsRegistry. |
| 58 friend class CWSIntentsRegistryFactory; | 60 friend class CWSIntentsRegistryFactory; |
| 59 FRIEND_TEST_ALL_PREFIXES(CWSIntentsRegistryTest, ValidQuery); | 61 friend class ::CWSIntentsRegistryForTest; |
| 60 FRIEND_TEST_ALL_PREFIXES(CWSIntentsRegistryTest, InvalidQuery); | |
| 61 | 62 |
| 62 struct IntentsQuery; | 63 struct IntentsQuery; |
| 63 | 64 |
| 64 // This is an opaque version of URLFetcher*, so we can use it as a hash key. | 65 // This is an opaque version of URLFetcher*, so we can use it as a hash key. |
| 65 typedef intptr_t URLFetcherHandle; | 66 typedef intptr_t URLFetcherHandle; |
| 66 | 67 |
| 67 // Maps URL fetchers to queries. IntentsQuery objects are owned by the map. | 68 // Maps URL fetchers to queries. IntentsQuery objects are owned by the map. |
| 68 typedef base::hash_map<URLFetcherHandle, IntentsQuery*> QueryMap; | 69 typedef base::hash_map<URLFetcherHandle, IntentsQuery*> QueryMap; |
| 69 | 70 |
| 70 // |context| is a profile-dependent URL request context. Must not be NULL. | 71 // |context| is a profile-dependent URL request context. Must not be NULL. |
| 71 explicit CWSIntentsRegistry(net::URLRequestContextGetter* context); | 72 explicit CWSIntentsRegistry(net::URLRequestContextGetter* context); |
| 72 virtual ~CWSIntentsRegistry(); | 73 virtual ~CWSIntentsRegistry(); |
| 73 | 74 |
| 74 // net::URLFetcherDelegate implementation. | 75 // net::URLFetcherDelegate implementation. |
| 75 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 76 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
| 76 | 77 |
| 77 // Map for all in-flight web data requests/intent queries. | 78 // Map for all in-flight web data requests/intent queries. |
| 78 QueryMap queries_; | 79 QueryMap queries_; |
| 79 | 80 |
| 80 // Request context for any CWS requests. | 81 // Request context for any CWS requests. |
| 81 scoped_refptr<net::URLRequestContextGetter> request_context_; | 82 scoped_refptr<net::URLRequestContextGetter> request_context_; |
| 82 | 83 |
| 83 DISALLOW_COPY_AND_ASSIGN(CWSIntentsRegistry); | 84 DISALLOW_COPY_AND_ASSIGN(CWSIntentsRegistry); |
| 84 }; | 85 }; |
| 85 | 86 |
| 86 #endif // CHROME_BROWSER_INTENTS_CWS_INTENTS_REGISTRY_H_ | 87 #endif // CHROME_BROWSER_INTENTS_CWS_INTENTS_REGISTRY_H_ |
| OLD | NEW |