OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 COMPONENTS_PHYSICAL_WEB_DATA_SOURCE_PHYSICAL_WEB_DATA_SOURCE_H_ | 5 #ifndef COMPONENTS_PHYSICAL_WEB_DATA_SOURCE_PHYSICAL_WEB_DATA_SOURCE_H_ |
6 #define COMPONENTS_PHYSICAL_WEB_DATA_SOURCE_PHYSICAL_WEB_DATA_SOURCE_H_ | 6 #define COMPONENTS_PHYSICAL_WEB_DATA_SOURCE_PHYSICAL_WEB_DATA_SOURCE_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
| 9 #include <string> |
| 10 #include <vector> |
| 11 |
| 12 #include "base/time/time.h" |
| 13 #include "url/gurl.h" |
9 | 14 |
10 namespace base { | 15 namespace base { |
11 class ListValue; | 16 class ListValue; |
12 } | 17 } |
13 | 18 |
14 namespace physical_web { | 19 namespace physical_web { |
15 | 20 |
16 class PhysicalWebListener; | 21 class PhysicalWebListener; |
17 | 22 |
18 // Dictionary keys for reading Physical Web URL metadata. | 23 // Dictionary keys for reading Physical Web URL metadata. |
| 24 // TODO(cco3): Remove these when we are no longer dependent. |
19 extern const char kDescriptionKey[]; | 25 extern const char kDescriptionKey[]; |
20 extern const char kDistanceEstimateKey[]; | 26 extern const char kDistanceEstimateKey[]; |
21 extern const char kGroupIdKey[]; | 27 extern const char kGroupIdKey[]; |
22 extern const char kIconUrlKey[]; | 28 extern const char kIconUrlKey[]; |
23 extern const char kResolvedUrlKey[]; | 29 extern const char kResolvedUrlKey[]; |
24 extern const char kScanTimestampKey[]; | 30 extern const char kScanTimestampKey[]; |
25 extern const char kScannedUrlKey[]; | 31 extern const char kScannedUrlKey[]; |
26 extern const char kTitleKey[]; | 32 extern const char kTitleKey[]; |
27 | 33 |
| 34 // Metadata struct for associating data with Physical Web URLs. |
| 35 struct Metadata { |
| 36 Metadata(); |
| 37 Metadata(const Metadata& other); |
| 38 ~Metadata(); |
| 39 // The URL broadcasted by the beacon and scanned by the client device. |
| 40 // REQUIRED |
| 41 GURL scanned_url; |
| 42 // The URL that the scanned_url redirects to. |
| 43 // This is the URL that users should be directed to. |
| 44 // REQUIRED |
| 45 GURL resolved_url; |
| 46 // The favicon URL. |
| 47 // OPTIONAL |
| 48 GURL icon_url; |
| 49 // The title of the web page. |
| 50 // REQUIRED |
| 51 std::string title; |
| 52 // The description of the web page. |
| 53 // OPTIONAL: When the website has not specified a description, the PWS |
| 54 // generates one based on the initial text of the site, but this is not |
| 55 // guaranteed behavior. |
| 56 std::string description; |
| 57 // An identifier that associates multiple resolved URLs. These URLs will |
| 58 // most typically be associated because their metadata is near-identical |
| 59 // (same icon, title, description, URL minus the fragment). e.g., |
| 60 // https://mymuseum/exhibits#e1 |
| 61 // https://mymuseum/exhibits#e2 |
| 62 // If two URLs have the same group id, only one should be shown (typically, |
| 63 // the one with the smallest distance estimate). |
| 64 // OPTIONAL: Treat the item as its own unique group if this is empty. |
| 65 std::string group_id; |
| 66 // The estimated distance between the user and the Physical Web device (e.g., |
| 67 // beacon) in meters. |
| 68 // OPTIONAL: This will be a value <= 0 if no distance estimate has been |
| 69 // calculated. The distance may not be calculated if we aren't able to |
| 70 // receive an estimate from the underlying scanning service in time, or if |
| 71 // (in the future) we begin sourcing Physical Web URLs from a non-BLE |
| 72 // transport (e.g. mDNS). |
| 73 double distance_estimate; |
| 74 // The timestamp corresponding to when this URL was last scanned. |
| 75 // REQUIRED |
| 76 base::Time scan_timestamp; |
| 77 }; |
| 78 |
| 79 using MetadataList = std::vector<Metadata>; |
| 80 |
28 // Helper class for accessing Physical Web metadata and controlling the scanner. | 81 // Helper class for accessing Physical Web metadata and controlling the scanner. |
29 class PhysicalWebDataSource { | 82 class PhysicalWebDataSource { |
30 public: | 83 public: |
31 virtual ~PhysicalWebDataSource() {} | 84 virtual ~PhysicalWebDataSource() {} |
32 | 85 |
33 // Starts scanning for Physical Web URLs. If |network_request_enabled| is | 86 // Starts scanning for Physical Web URLs. If |network_request_enabled| is |
34 // true, discovered URLs will be sent to a resolution service. | 87 // true, discovered URLs will be sent to a resolution service. |
35 virtual void StartDiscovery(bool network_request_enabled) = 0; | 88 virtual void StartDiscovery(bool network_request_enabled) = 0; |
36 | 89 |
37 // Stops scanning for Physical Web URLs and clears cached URL content. | 90 // Stops scanning for Physical Web URLs and clears cached URL content. |
38 virtual void StopDiscovery() = 0; | 91 virtual void StopDiscovery() = 0; |
39 | 92 |
40 // Returns a list of resolved URLs and associated page metadata. If network | 93 // Returns a list of resolved URLs and associated page metadata. If network |
41 // requests are disabled or if discovery is not active, the list will be | 94 // requests are disabled or if discovery is not active, the list will be |
42 // empty. The method can be called at any time to receive the current metadata | 95 // empty. The method can be called at any time to receive the current metadata |
43 // list. | 96 // list. |
| 97 virtual std::unique_ptr<MetadataList> GetMetadataList() = 0; |
| 98 |
| 99 // Returns a list of resolved URLs and associated page metadata. If network |
| 100 // requests are disabled or if discovery is not active, the list will be |
| 101 // empty. The method can be called at any time to receive the current metadata |
| 102 // list. |
| 103 // DEPRECATED |
| 104 // TODO(cco3): Remove this when we are no longer dependent on it. |
44 virtual std::unique_ptr<base::ListValue> GetMetadata() = 0; | 105 virtual std::unique_ptr<base::ListValue> GetMetadata() = 0; |
45 | 106 |
46 // Returns boolean |true| if network requests are disabled and there are one | 107 // Returns boolean |true| if network requests are disabled and there are one |
47 // or more discovered URLs that have not been sent to the resolution service. | 108 // or more discovered URLs that have not been sent to the resolution service. |
48 // The method can be called at any time to check for unresolved discoveries. | 109 // The method can be called at any time to check for unresolved discoveries. |
49 // If discovery is inactive or network requests are enabled, it will always | 110 // If discovery is inactive or network requests are enabled, it will always |
50 // return false. | 111 // return false. |
51 virtual bool HasUnresolvedDiscoveries() = 0; | 112 virtual bool HasUnresolvedDiscoveries() = 0; |
52 | 113 |
53 // Register for changes to Physical Web URLs and associated page metadata. | 114 // Register for changes to Physical Web URLs and associated page metadata. |
54 virtual void RegisterListener(PhysicalWebListener* physical_web_listener) = 0; | 115 virtual void RegisterListener(PhysicalWebListener* physical_web_listener) = 0; |
55 | 116 |
56 // Unregister for changes to Physical Web URLs and associated page metadata. | 117 // Unregister for changes to Physical Web URLs and associated page metadata. |
57 virtual void UnregisterListener( | 118 virtual void UnregisterListener( |
58 PhysicalWebListener* physical_web_listener) = 0; | 119 PhysicalWebListener* physical_web_listener) = 0; |
59 }; | 120 }; |
60 | 121 |
61 } // namespace physical_web | 122 } // namespace physical_web |
62 | 123 |
63 #endif // COMPONENTS_PHYSICAL_WEB_DATA_SOURCE_PHYSICAL_WEB_DATA_SOURCE_H_ | 124 #endif // COMPONENTS_PHYSICAL_WEB_DATA_SOURCE_PHYSICAL_WEB_DATA_SOURCE_H_ |
OLD | NEW |