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 #include "base/time/time.h" | |
12 #include "url/gurl.h" | |
9 | 13 |
10 namespace base { | 14 namespace base { |
11 class ListValue; | 15 class ListValue; |
12 } | 16 } |
13 | 17 |
14 namespace physical_web { | 18 namespace physical_web { |
15 | 19 |
16 class PhysicalWebListener; | 20 class PhysicalWebListener; |
17 | 21 |
18 // Dictionary keys for reading Physical Web URL metadata. | 22 // Dictionary keys for reading Physical Web URL metadata. |
23 // TODO(cco3): Remove these when we are no longer dependent. | |
19 extern const char kDescriptionKey[]; | 24 extern const char kDescriptionKey[]; |
20 extern const char kDistanceEstimateKey[]; | 25 extern const char kDistanceEstimateKey[]; |
21 extern const char kGroupIdKey[]; | 26 extern const char kGroupIdKey[]; |
22 extern const char kIconUrlKey[]; | 27 extern const char kIconUrlKey[]; |
23 extern const char kResolvedUrlKey[]; | 28 extern const char kResolvedUrlKey[]; |
24 extern const char kScanTimestampKey[]; | 29 extern const char kScanTimestampKey[]; |
25 extern const char kScannedUrlKey[]; | 30 extern const char kScannedUrlKey[]; |
26 extern const char kTitleKey[]; | 31 extern const char kTitleKey[]; |
27 | 32 |
33 // Metadata struct for associating data with Physical Web URLs. | |
34 struct Metadata { | |
35 Metadata(); | |
36 Metadata(const Metadata& other); | |
37 ~Metadata(); | |
38 // The URL broadcasted by the beacon and scanned by the client device. | |
39 // REQUIRED | |
40 GURL scanned_url; | |
41 // The URL that the scanned_url redirects to. | |
42 // This is the URL that users should be directed to. | |
43 // REQUIRED | |
44 GURL resolved_url; | |
vitaliii
2016/12/09 09:52:49
Then PhysicalWebListener methods (e.g. OnFound) sh
cco3
2016/12/10 00:25:23
Done.
Hm, good point.
| |
45 // The favicon URL. | |
46 // OPTIONAL | |
47 GURL icon_url; | |
48 // The title of the web page. | |
49 // REQUIRED | |
50 std::string title; | |
51 // The description of the web page. | |
52 // OPTIONAL | |
vitaliii
2016/12/09 09:52:49
Could you elaborate on when one should not expect
cco3
2016/12/10 00:25:23
Done.
| |
53 std::string description; | |
54 // An identifier that associates multiple resolved URLs. If two URLs have | |
vitaliii
2016/12/09 09:52:49
I do not understand this. Could you give an exampl
cco3
2016/12/10 00:25:23
Done.
| |
55 // the same group id, only one should be shown (typically, the one with the | |
56 // smallest distance estimate). | |
57 // OPTIONAL: treat the item as its own unique group if this doesn't exist. | |
vitaliii
2016/12/09 09:52:49
s/doesn't exist/empty
cco3
2016/12/10 00:25:23
Done.
| |
58 std::string group_id; | |
59 // The estimated distance between the user and the Physical Web device (e.g., | |
60 // beacon) in meters. | |
61 // OPTIONAL: This will be a value <= 0 if no distance estimate has been | |
62 // calculated. | |
vitaliii
2016/12/09 09:52:49
An example when the distance is not estimated?
cco3
2016/12/10 00:25:23
Done.
| |
63 double distance_estimate; | |
64 // The timestamp corresponding to when this URL was last scanned. | |
65 // REQUIRED | |
66 base::Time scan_timestamp; | |
67 }; | |
68 | |
69 using MetadataList = std::vector<Metadata>; | |
70 | |
28 // Helper class for accessing Physical Web metadata and controlling the scanner. | 71 // Helper class for accessing Physical Web metadata and controlling the scanner. |
29 class PhysicalWebDataSource { | 72 class PhysicalWebDataSource { |
30 public: | 73 public: |
31 virtual ~PhysicalWebDataSource() {} | 74 virtual ~PhysicalWebDataSource() {} |
32 | 75 |
33 // Starts scanning for Physical Web URLs. If |network_request_enabled| is | 76 // Starts scanning for Physical Web URLs. If |network_request_enabled| is |
34 // true, discovered URLs will be sent to a resolution service. | 77 // true, discovered URLs will be sent to a resolution service. |
35 virtual void StartDiscovery(bool network_request_enabled) = 0; | 78 virtual void StartDiscovery(bool network_request_enabled) = 0; |
36 | 79 |
37 // Stops scanning for Physical Web URLs and clears cached URL content. | 80 // Stops scanning for Physical Web URLs and clears cached URL content. |
38 virtual void StopDiscovery() = 0; | 81 virtual void StopDiscovery() = 0; |
39 | 82 |
40 // Returns a list of resolved URLs and associated page metadata. If network | 83 // 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 | 84 // 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 | 85 // empty. The method can be called at any time to receive the current metadata |
43 // list. | 86 // list. |
87 virtual std::unique_ptr<MetadataList> GetMetadataList() = 0; | |
88 | |
89 // Returns a list of resolved URLs and associated page metadata. If network | |
90 // requests are disabled or if discovery is not active, the list will be | |
91 // empty. The method can be called at any time to receive the current metadata | |
92 // list. | |
93 // DEPRECATED | |
94 // TODO(cco3): Remove this when we are no longer dependent on it. | |
44 virtual std::unique_ptr<base::ListValue> GetMetadata() = 0; | 95 virtual std::unique_ptr<base::ListValue> GetMetadata() = 0; |
45 | 96 |
46 // Returns boolean |true| if network requests are disabled and there are one | 97 // 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. | 98 // 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. | 99 // 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 | 100 // If discovery is inactive or network requests are enabled, it will always |
50 // return false. | 101 // return false. |
51 virtual bool HasUnresolvedDiscoveries() = 0; | 102 virtual bool HasUnresolvedDiscoveries() = 0; |
52 | 103 |
53 // Register for changes to Physical Web URLs and associated page metadata. | 104 // Register for changes to Physical Web URLs and associated page metadata. |
54 virtual void RegisterListener(PhysicalWebListener* physical_web_listener) = 0; | 105 virtual void RegisterListener(PhysicalWebListener* physical_web_listener) = 0; |
55 | 106 |
56 // Unregister for changes to Physical Web URLs and associated page metadata. | 107 // Unregister for changes to Physical Web URLs and associated page metadata. |
57 virtual void UnregisterListener( | 108 virtual void UnregisterListener( |
58 PhysicalWebListener* physical_web_listener) = 0; | 109 PhysicalWebListener* physical_web_listener) = 0; |
59 }; | 110 }; |
60 | 111 |
61 } // namespace physical_web | 112 } // namespace physical_web |
62 | 113 |
63 #endif // COMPONENTS_PHYSICAL_WEB_DATA_SOURCE_PHYSICAL_WEB_DATA_SOURCE_H_ | 114 #endif // COMPONENTS_PHYSICAL_WEB_DATA_SOURCE_PHYSICAL_WEB_DATA_SOURCE_H_ |
OLD | NEW |