Chromium Code Reviews| 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 { | |
|
mattreynolds
2016/12/09 00:10:03
We should comment on which fields are optional. II
| |
| 35 Metadata(); | |
| 36 Metadata(const Metadata& other); | |
| 37 ~Metadata(); | |
| 38 // The URL broadcasted by the beacon and scanned by the client device. | |
| 39 GURL scanned_url; | |
| 40 // The URL that the scanned_url redirects to. | |
| 41 // This is the URL that users should be directed to. | |
| 42 GURL resolved_url; | |
| 43 // The favicon URL. | |
| 44 GURL icon_url; | |
| 45 // The title of the web page. | |
| 46 std::string title; | |
| 47 // The description of the web page. | |
| 48 std::string description; | |
| 49 // An identifier that associates multiple resolved URLs. If two URLs have | |
| 50 // the same group id, only one should be shown (typically, the one with the | |
| 51 // smallest distance estimate). | |
| 52 std::string group_id; | |
| 53 // The estimated distance between the user and the Physical Web device (e.g., | |
| 54 // beacon) in meters. | |
| 55 double distance_estimate; | |
| 56 // The timestamp corresponding to when this URL was last scanned. | |
| 57 base::Time scan_timestamp; | |
| 58 }; | |
| 59 | |
| 60 using MetadataList = std::vector<Metadata>; | |
| 61 | |
| 28 // Helper class for accessing Physical Web metadata and controlling the scanner. | 62 // Helper class for accessing Physical Web metadata and controlling the scanner. |
| 29 class PhysicalWebDataSource { | 63 class PhysicalWebDataSource { |
| 30 public: | 64 public: |
| 31 virtual ~PhysicalWebDataSource() {} | 65 virtual ~PhysicalWebDataSource() {} |
| 32 | 66 |
| 33 // Starts scanning for Physical Web URLs. If |network_request_enabled| is | 67 // Starts scanning for Physical Web URLs. If |network_request_enabled| is |
| 34 // true, discovered URLs will be sent to a resolution service. | 68 // true, discovered URLs will be sent to a resolution service. |
| 35 virtual void StartDiscovery(bool network_request_enabled) = 0; | 69 virtual void StartDiscovery(bool network_request_enabled) = 0; |
| 36 | 70 |
| 37 // Stops scanning for Physical Web URLs and clears cached URL content. | 71 // Stops scanning for Physical Web URLs and clears cached URL content. |
| 38 virtual void StopDiscovery() = 0; | 72 virtual void StopDiscovery() = 0; |
| 39 | 73 |
| 40 // Returns a list of resolved URLs and associated page metadata. If network | 74 // 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 | 75 // 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 | 76 // empty. The method can be called at any time to receive the current metadata |
| 43 // list. | 77 // list. |
| 78 virtual std::unique_ptr<MetadataList> GetMetadataList() = 0; | |
| 79 | |
| 80 // Returns a list of resolved URLs and associated page metadata. If network | |
| 81 // requests are disabled or if discovery is not active, the list will be | |
| 82 // empty. The method can be called at any time to receive the current metadata | |
| 83 // list. | |
| 84 // DEPRECATED | |
| 85 // TODO(cco3): Remove this when we are no longer dependent on it. | |
| 44 virtual std::unique_ptr<base::ListValue> GetMetadata() = 0; | 86 virtual std::unique_ptr<base::ListValue> GetMetadata() = 0; |
| 45 | 87 |
| 46 // Returns boolean |true| if network requests are disabled and there are one | 88 // 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. | 89 // 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. | 90 // 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 | 91 // If discovery is inactive or network requests are enabled, it will always |
| 50 // return false. | 92 // return false. |
| 51 virtual bool HasUnresolvedDiscoveries() = 0; | 93 virtual bool HasUnresolvedDiscoveries() = 0; |
| 52 | 94 |
| 53 // Register for changes to Physical Web URLs and associated page metadata. | 95 // Register for changes to Physical Web URLs and associated page metadata. |
| 54 virtual void RegisterListener(PhysicalWebListener* physical_web_listener) = 0; | 96 virtual void RegisterListener(PhysicalWebListener* physical_web_listener) = 0; |
| 55 | 97 |
| 56 // Unregister for changes to Physical Web URLs and associated page metadata. | 98 // Unregister for changes to Physical Web URLs and associated page metadata. |
| 57 virtual void UnregisterListener( | 99 virtual void UnregisterListener( |
| 58 PhysicalWebListener* physical_web_listener) = 0; | 100 PhysicalWebListener* physical_web_listener) = 0; |
| 59 }; | 101 }; |
| 60 | 102 |
| 61 } // namespace physical_web | 103 } // namespace physical_web |
| 62 | 104 |
| 63 #endif // COMPONENTS_PHYSICAL_WEB_DATA_SOURCE_PHYSICAL_WEB_DATA_SOURCE_H_ | 105 #endif // COMPONENTS_PHYSICAL_WEB_DATA_SOURCE_PHYSICAL_WEB_DATA_SOURCE_H_ |
| OLD | NEW |