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_CWS_INTENTS_REGISTRY_H_ | |
6 #define CHROME_BROWSER_INTENTS_CWS_INTENTS_REGISTRY_H_ | |
7 | |
8 #include <vector> | |
9 | |
10 #include "base/callback_forward.h" | |
11 #include "base/gtest_prod_util.h" | |
12 #include "base/hash_tables.h" | |
13 #include "base/memory/ref_counted.h" | |
14 #include "chrome/browser/profiles/profile_keyed_service.h" | |
15 #include "googleurl/src/gurl.h" | |
16 #include "net/url_request/url_fetcher_delegate.h" | |
17 | |
18 namespace net { | |
19 class URLRequestContextGetter; | |
20 } | |
21 | |
22 class CWSIntentsRegistryForTest; | |
23 | |
24 // Handles storing and retrieving of web intents in the web database. | |
25 // The registry provides filtering logic to retrieve specific types of intents. | |
26 class CWSIntentsRegistry : public ProfileKeyedService, | |
27 public net::URLFetcherDelegate { | |
28 public: | |
29 // Data returned from CWS for a single service. | |
30 struct IntentExtensionInfo { | |
31 IntentExtensionInfo(); | |
32 ~IntentExtensionInfo(); | |
33 | |
34 std::string id; // The id of the extension. | |
35 string16 name; // The name of the extension. | |
36 int num_ratings; // Number of ratings in CWS store. | |
37 double average_rating; // The average CWS rating. | |
38 string16 manifest; // The containing extension's manifest info. | |
39 GURL icon_url; // Where to retrieve an icon for this service. | |
40 }; | |
41 | |
42 // List of Intent extensions, as returned by GetIntentServices's |callback| | |
43 typedef std::vector<IntentExtensionInfo> IntentExtensionList; | |
44 // Callback to return results from GetIntentServices upon completion. | |
45 typedef base::Callback<void(const IntentExtensionList&)> ResultsCallback; | |
46 | |
47 // Requests all intent services matching |action| and |mimetype|. | |
48 // |mimetype| must conform to definition as outlined for | |
49 // WebIntentsRegistry::GetIntentServices. | |
50 // |callback| will be invoked upon retrieving results from CWS, returning | |
51 // a list of matching Intent extensions. | |
52 void GetIntentServices(const string16& action, | |
53 const string16& mimetype, | |
54 const ResultsCallback& callback); | |
55 | |
56 // Build a REST query URL to retrieve intent info from CWS. | |
57 static GURL BuildQueryURL(const string16& action, const string16& type); | |
58 | |
59 private: | |
60 // Make sure that only CWSIntentsRegistryFactory can create an instance of | |
61 // CWSIntentsRegistry. | |
62 friend class CWSIntentsRegistryFactory; | |
63 friend class ::CWSIntentsRegistryForTest; | |
64 | |
65 struct IntentsQuery; | |
66 | |
67 // This is an opaque version of URLFetcher*, so we can use it as a hash key. | |
68 typedef intptr_t URLFetcherHandle; | |
69 | |
70 // Maps URL fetchers to queries. IntentsQuery objects are owned by the map. | |
71 typedef base::hash_map<URLFetcherHandle, IntentsQuery*> QueryMap; | |
72 | |
73 // |context| is a profile-dependent URL request context. Must not be NULL. | |
74 explicit CWSIntentsRegistry(net::URLRequestContextGetter* context); | |
75 virtual ~CWSIntentsRegistry(); | |
76 | |
77 // net::URLFetcherDelegate implementation. | |
78 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | |
79 | |
80 // Map for all in-flight web data requests/intent queries. | |
81 QueryMap queries_; | |
82 | |
83 // Request context for any CWS requests. | |
84 scoped_refptr<net::URLRequestContextGetter> request_context_; | |
85 | |
86 DISALLOW_COPY_AND_ASSIGN(CWSIntentsRegistry); | |
87 }; | |
88 | |
89 #endif // CHROME_BROWSER_INTENTS_CWS_INTENTS_REGISTRY_H_ | |
OLD | NEW |