Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(633)

Side by Side Diff: components/physical_web/data_source/physical_web_data_source.h

Issue 2561493002: Pass Physical Web metadata through a struct (Closed)
Patch Set: Fix missed compile errors Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
nyquist 2016/12/13 18:13:25 Nit: Should there be a newline before the //base i
cco3 2016/12/16 19:17:53 Done.
12 #include "url/gurl.h"
mattreynolds 2016/12/12 19:41:29 Also add "//url" to the data_source deps in compon
nyquist 2016/12/13 18:13:25 Since this is an exposed header with a new include
cco3 2016/12/16 19:17:53 Done.
cco3 2016/12/16 19:17:53 Done.
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;
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: when the website has not specified a description, the PWS
53 // generates one based on the initial text of the site, but this is not
54 // guaranteed behavior.
55 std::string description;
56 // An identifier that associates multiple resolved URLs. These URLs will
57 // most typically be associated because their metadata is near-identical
58 // (same icon, title, description, URL minus the fragment). e.g.,
59 // https://mymuseum/exhibits#e1
60 // https://mymuseum/exhibits#e2
61 // If two URLs have the same group id, only one should be shown (typically,
62 // the one with the smallest distance estimate).
63 // OPTIONAL: treat the item as its own unique group if this is empty.
64 std::string group_id;
65 // The estimated distance between the user and the Physical Web device (e.g.,
66 // beacon) in meters.
67 // OPTIONAL: This will be a value <= 0 if no distance estimate has been
68 // calculated. The distance may not be calculated if we aren't able to
69 // receive an estimate from the underlying scanning service in time, or if
70 // (in the future) we begin sourcing Physical Web URLs from a non-BLE
71 // transport (e.g. mDNS).
72 double distance_estimate;
73 // The timestamp corresponding to when this URL was last scanned.
74 // REQUIRED
75 base::Time scan_timestamp;
76 };
77
78 using MetadataList = std::vector<Metadata>;
79
28 // Helper class for accessing Physical Web metadata and controlling the scanner. 80 // Helper class for accessing Physical Web metadata and controlling the scanner.
29 class PhysicalWebDataSource { 81 class PhysicalWebDataSource {
30 public: 82 public:
31 virtual ~PhysicalWebDataSource() {} 83 virtual ~PhysicalWebDataSource() {}
32 84
33 // Starts scanning for Physical Web URLs. If |network_request_enabled| is 85 // Starts scanning for Physical Web URLs. If |network_request_enabled| is
34 // true, discovered URLs will be sent to a resolution service. 86 // true, discovered URLs will be sent to a resolution service.
35 virtual void StartDiscovery(bool network_request_enabled) = 0; 87 virtual void StartDiscovery(bool network_request_enabled) = 0;
36 88
37 // Stops scanning for Physical Web URLs and clears cached URL content. 89 // Stops scanning for Physical Web URLs and clears cached URL content.
38 virtual void StopDiscovery() = 0; 90 virtual void StopDiscovery() = 0;
39 91
40 // Returns a list of resolved URLs and associated page metadata. If network 92 // 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 93 // 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 94 // empty. The method can be called at any time to receive the current metadata
43 // list. 95 // list.
96 virtual std::unique_ptr<MetadataList> GetMetadataList() = 0;
97
98 // Returns a list of resolved URLs and associated page metadata. If network
99 // requests are disabled or if discovery is not active, the list will be
100 // empty. The method can be called at any time to receive the current metadata
101 // list.
102 // DEPRECATED
103 // TODO(cco3): Remove this when we are no longer dependent on it.
44 virtual std::unique_ptr<base::ListValue> GetMetadata() = 0; 104 virtual std::unique_ptr<base::ListValue> GetMetadata() = 0;
45 105
46 // Returns boolean |true| if network requests are disabled and there are one 106 // 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. 107 // 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. 108 // 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 109 // If discovery is inactive or network requests are enabled, it will always
50 // return false. 110 // return false.
51 virtual bool HasUnresolvedDiscoveries() = 0; 111 virtual bool HasUnresolvedDiscoveries() = 0;
52 112
53 // Register for changes to Physical Web URLs and associated page metadata. 113 // Register for changes to Physical Web URLs and associated page metadata.
54 virtual void RegisterListener(PhysicalWebListener* physical_web_listener) = 0; 114 virtual void RegisterListener(PhysicalWebListener* physical_web_listener) = 0;
55 115
56 // Unregister for changes to Physical Web URLs and associated page metadata. 116 // Unregister for changes to Physical Web URLs and associated page metadata.
57 virtual void UnregisterListener( 117 virtual void UnregisterListener(
58 PhysicalWebListener* physical_web_listener) = 0; 118 PhysicalWebListener* physical_web_listener) = 0;
59 }; 119 };
60 120
61 } // namespace physical_web 121 } // namespace physical_web
62 122
63 #endif // COMPONENTS_PHYSICAL_WEB_DATA_SOURCE_PHYSICAL_WEB_DATA_SOURCE_H_ 123 #endif // COMPONENTS_PHYSICAL_WEB_DATA_SOURCE_PHYSICAL_WEB_DATA_SOURCE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698