Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 CHROMEOS_COMPONENTS_TETHER_HOST_SCAN_CACHE_H_ | 5 #ifndef CHROMEOS_COMPONENTS_TETHER_HOST_SCAN_CACHE_H_ |
| 6 #define CHROMEOS_COMPONENTS_TETHER_HOST_SCAN_CACHE_H_ | 6 #define CHROMEOS_COMPONENTS_TETHER_HOST_SCAN_CACHE_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <unordered_map> | 9 #include <unordered_map> |
| 10 | 10 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 50 // Updates the cache to include this scan result. If no scan result for | 50 // Updates the cache to include this scan result. If no scan result for |
| 51 // |tether_network_guid| exists in the cache, a scan result will be added; | 51 // |tether_network_guid| exists in the cache, a scan result will be added; |
| 52 // if a scan result is already present, it is updated with the new data | 52 // if a scan result is already present, it is updated with the new data |
| 53 // provided as parameters to this function. Once scan results have been | 53 // provided as parameters to this function. Once scan results have been |
| 54 // updated, a timer starts counting down |kNumMinutesBeforeCacheEntryExpires| | 54 // updated, a timer starts counting down |kNumMinutesBeforeCacheEntryExpires| |
| 55 // minutes. Once the timer fires, the scan result is automatically removed | 55 // minutes. Once the timer fires, the scan result is automatically removed |
| 56 // from the cache unless it corresponds to the active host. | 56 // from the cache unless it corresponds to the active host. |
| 57 // Note: |signal_strength| should be in the range [0, 100]. This is different | 57 // Note: |signal_strength| should be in the range [0, 100]. This is different |
| 58 // from the |connection_strength| field received in ConnectTetheringResponse | 58 // from the |connection_strength| field received in ConnectTetheringResponse |
| 59 // and KeepAliveTickleResponse messages (the range is [0, 4] in those cases). | 59 // and KeepAliveTickleResponse messages (the range is [0, 4] in those cases). |
| 60 // |battery_percentage| should also be in the range [0, 100]. | |
| 61 // |setup_required| indicates that the host device requires first-time setup, | |
| 62 // i.e. user interaction to allow tethering. | |
|
Kyle Horimoto
2017/05/31 23:01:19
supernit: "i.e.," (comma after)
Same below.
Ryan Hansberry
2017/06/01 01:07:51
Done.
| |
| 60 virtual void SetHostScanResult(const std::string& tether_network_guid, | 63 virtual void SetHostScanResult(const std::string& tether_network_guid, |
| 61 const std::string& device_name, | 64 const std::string& device_name, |
| 62 const std::string& carrier, | 65 const std::string& carrier, |
| 63 int battery_percentage, | 66 int battery_percentage, |
| 64 int signal_strength); | 67 int signal_strength, |
| 68 bool setup_required); | |
| 65 | 69 |
| 66 // Removes the scan result with GUID |tether_network_guid| from the cache. If | 70 // Removes the scan result with GUID |tether_network_guid| from the cache. If |
| 67 // no cache result with that GUID was present in the cache, this function is | 71 // no cache result with that GUID was present in the cache, this function is |
| 68 // a no-op. Returns whether a scan result was actually removed. | 72 // a no-op. Returns whether a scan result was actually removed. |
| 69 virtual bool RemoveHostScanResult(const std::string& tether_network_guid); | 73 virtual bool RemoveHostScanResult(const std::string& tether_network_guid); |
| 70 | 74 |
| 71 // Removes all scan results from the cache unless they correspond to the | 75 // Removes all scan results from the cache unless they correspond to the |
| 72 // active host; the active host must always remain in the cache while | 76 // active host; the active host must always remain in the cache while |
| 73 // connecting/connected to ensure the UI is up to date. | 77 // connecting/connected to ensure the UI is up to date. |
| 74 virtual void ClearCacheExceptForActiveHost(); | 78 virtual void ClearCacheExceptForActiveHost(); |
| 75 | 79 |
| 80 // Returns true if the host device requires first-time setup, i.e. user | |
| 81 // interaction to allow tethering. | |
| 82 virtual bool DoesHostRequireSetup(const std::string& tether_network_guid); | |
| 83 | |
| 76 // TetherHostResponseRecorder::Observer: | 84 // TetherHostResponseRecorder::Observer: |
| 77 void OnPreviouslyConnectedHostIdsChanged() override; | 85 void OnPreviouslyConnectedHostIdsChanged() override; |
| 78 | 86 |
| 79 class TimerFactory { | 87 class TimerFactory { |
| 80 public: | 88 public: |
| 81 virtual std::unique_ptr<base::Timer> CreateOneShotTimer() = 0; | 89 virtual std::unique_ptr<base::Timer> CreateOneShotTimer() = 0; |
| 82 }; | 90 }; |
| 83 | 91 |
| 84 private: | 92 private: |
| 85 friend class HostScanCacheTest; | 93 friend class HostScanCacheTest; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 96 ActiveHost* active_host_; | 104 ActiveHost* active_host_; |
| 97 TetherHostResponseRecorder* tether_host_response_recorder_; | 105 TetherHostResponseRecorder* tether_host_response_recorder_; |
| 98 DeviceIdTetherNetworkGuidMap* device_id_tether_network_guid_map_; | 106 DeviceIdTetherNetworkGuidMap* device_id_tether_network_guid_map_; |
| 99 | 107 |
| 100 // Maps from the Tether network GUID to a Timer object. While a scan result is | 108 // Maps from the Tether network GUID to a Timer object. While a scan result is |
| 101 // active in the cache, the corresponding Timer object starts running; if the | 109 // active in the cache, the corresponding Timer object starts running; if the |
| 102 // timer fires, the result is removed (unless it corresponds to the active | 110 // timer fires, the result is removed (unless it corresponds to the active |
| 103 // host). | 111 // host). |
| 104 std::unordered_map<std::string, std::unique_ptr<base::Timer>> | 112 std::unordered_map<std::string, std::unique_ptr<base::Timer>> |
| 105 tether_guid_to_timer_map_; | 113 tether_guid_to_timer_map_; |
| 114 std::unordered_set<std::string> setup_required_tether_guids_; | |
| 106 base::WeakPtrFactory<HostScanCache> weak_ptr_factory_; | 115 base::WeakPtrFactory<HostScanCache> weak_ptr_factory_; |
| 107 | 116 |
| 108 DISALLOW_COPY_AND_ASSIGN(HostScanCache); | 117 DISALLOW_COPY_AND_ASSIGN(HostScanCache); |
| 109 }; | 118 }; |
| 110 | 119 |
| 111 } // namespace tether | 120 } // namespace tether |
| 112 | 121 |
| 113 } // namespace chromeos | 122 } // namespace chromeos |
| 114 | 123 |
| 115 #endif // CHROMEOS_COMPONENTS_TETHER_HOST_SCAN_CACHE_H_ | 124 #endif // CHROMEOS_COMPONENTS_TETHER_HOST_SCAN_CACHE_H_ |
| OLD | NEW |