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

Side by Side Diff: chromeos/components/tether/keep_alive_scheduler.cc

Issue 2918863002: [CrOS Tether] Update the KeepAliveTickle code to receive DeviceStatus updates. (Closed)
Patch Set: Rebased. Created 3 years, 6 months 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 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 #include "chromeos/components/tether/keep_alive_scheduler.h" 5 #include "chromeos/components/tether/keep_alive_scheduler.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "chromeos/components/tether/device_id_tether_network_guid_map.h"
9 #include "chromeos/components/tether/host_scan_cache.h"
8 10
9 namespace chromeos { 11 namespace chromeos {
10 12
11 namespace tether { 13 namespace tether {
12 14
13 // static 15 // static
14 const uint32_t KeepAliveScheduler::kKeepAliveIntervalMinutes = 4; 16 const uint32_t KeepAliveScheduler::kKeepAliveIntervalMinutes = 4;
15 17
16 KeepAliveScheduler::KeepAliveScheduler(ActiveHost* active_host, 18 KeepAliveScheduler::KeepAliveScheduler(
17 BleConnectionManager* connection_manager) 19 ActiveHost* active_host,
20 BleConnectionManager* connection_manager,
21 HostScanCache* host_scan_cache,
22 DeviceIdTetherNetworkGuidMap* device_id_tether_network_guid_map)
18 : KeepAliveScheduler(active_host, 23 : KeepAliveScheduler(active_host,
19 connection_manager, 24 connection_manager,
25 host_scan_cache,
26 device_id_tether_network_guid_map,
20 base::MakeUnique<base::RepeatingTimer>()) {} 27 base::MakeUnique<base::RepeatingTimer>()) {}
21 28
22 KeepAliveScheduler::KeepAliveScheduler(ActiveHost* active_host, 29 KeepAliveScheduler::KeepAliveScheduler(
23 BleConnectionManager* connection_manager, 30 ActiveHost* active_host,
24 std::unique_ptr<base::Timer> timer) 31 BleConnectionManager* connection_manager,
32 HostScanCache* host_scan_cache,
33 DeviceIdTetherNetworkGuidMap* device_id_tether_network_guid_map,
34 std::unique_ptr<base::Timer> timer)
25 : active_host_(active_host), 35 : active_host_(active_host),
26 connection_manager_(connection_manager), 36 connection_manager_(connection_manager),
37 host_scan_cache_(host_scan_cache),
38 device_id_tether_network_guid_map_(device_id_tether_network_guid_map),
27 timer_(std::move(timer)), 39 timer_(std::move(timer)),
28 weak_ptr_factory_(this) { 40 weak_ptr_factory_(this) {
29 active_host_->AddObserver(this); 41 active_host_->AddObserver(this);
30 } 42 }
31 43
32 KeepAliveScheduler::~KeepAliveScheduler() { 44 KeepAliveScheduler::~KeepAliveScheduler() {
33 active_host_->RemoveObserver(this); 45 active_host_->RemoveObserver(this);
34 } 46 }
35 47
36 void KeepAliveScheduler::OnActiveHostChanged( 48 void KeepAliveScheduler::OnActiveHostChanged(
(...skipping 12 matching lines...) Expand all
49 DCHECK(change_info.new_active_host); 61 DCHECK(change_info.new_active_host);
50 active_host_device_ = change_info.new_active_host; 62 active_host_device_ = change_info.new_active_host;
51 timer_->Start(FROM_HERE, 63 timer_->Start(FROM_HERE,
52 base::TimeDelta::FromMinutes(kKeepAliveIntervalMinutes), 64 base::TimeDelta::FromMinutes(kKeepAliveIntervalMinutes),
53 base::Bind(&KeepAliveScheduler::SendKeepAliveTickle, 65 base::Bind(&KeepAliveScheduler::SendKeepAliveTickle,
54 weak_ptr_factory_.GetWeakPtr())); 66 weak_ptr_factory_.GetWeakPtr()));
55 SendKeepAliveTickle(); 67 SendKeepAliveTickle();
56 } 68 }
57 } 69 }
58 70
59 void KeepAliveScheduler::OnOperationFinished() { 71 void KeepAliveScheduler::OnOperationFinished(
72 const cryptauth::RemoteDevice& remote_device,
73 std::unique_ptr<DeviceStatus> device_status) {
74 // Make a copy before destroying the operation below.
75 const cryptauth::RemoteDevice device_copy = remote_device;
76
60 keep_alive_operation_->RemoveObserver(this); 77 keep_alive_operation_->RemoveObserver(this);
61 keep_alive_operation_.reset(); 78 keep_alive_operation_.reset();
79
80 if (!device_status) {
81 // If the operation did not complete successfully, there is no new
82 // information with which to update the cache.
83 return;
84 }
85
86 std::string carrier;
87 int32_t battery_percentage;
88 int32_t signal_strength;
89 NormalizeDeviceStatus(*device_status, &carrier, &battery_percentage,
90 &signal_strength);
91
92 // Update the cache. Note that "false" is passed for the |setup_required|
93 // parameter because it is assumed that setup is no longer required for an
94 // active connection attempt.
95 host_scan_cache_->SetHostScanResult(
96 device_id_tether_network_guid_map_->GetTetherNetworkGuidForDeviceId(
97 device_copy.GetDeviceId()),
98 device_copy.name, carrier, battery_percentage, signal_strength,
99 false /* setup_required */);
62 } 100 }
63 101
64 void KeepAliveScheduler::SendKeepAliveTickle() { 102 void KeepAliveScheduler::SendKeepAliveTickle() {
65 DCHECK(active_host_device_); 103 DCHECK(active_host_device_);
66 104
67 keep_alive_operation_ = KeepAliveOperation::Factory::NewInstance( 105 keep_alive_operation_ = KeepAliveOperation::Factory::NewInstance(
68 *active_host_device_, connection_manager_); 106 *active_host_device_, connection_manager_);
69 keep_alive_operation_->AddObserver(this); 107 keep_alive_operation_->AddObserver(this);
70 keep_alive_operation_->Initialize(); 108 keep_alive_operation_->Initialize();
71 } 109 }
72 110
73 } // namespace tether 111 } // namespace tether
74 112
75 } // namespace chromeos 113 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698