| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/proximity_auth/webui/reachable_phone_flow.h" | 5 #include "components/proximity_auth/webui/reachable_phone_flow.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| 11 #include "base/threading/thread_task_runner_handle.h" | 11 #include "base/threading/thread_task_runner_handle.h" |
| 12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
| 13 #include "components/proximity_auth/cryptauth/cryptauth_client.h" | 13 #include "components/cryptauth/cryptauth_client.h" |
| 14 #include "components/proximity_auth/cryptauth/proto/cryptauth_api.pb.h" | 14 #include "components/proximity_auth/cryptauth/proto/cryptauth_api.pb.h" |
| 15 #include "components/proximity_auth/logging/logging.h" | 15 #include "components/proximity_auth/logging/logging.h" |
| 16 | 16 |
| 17 namespace proximity_auth { | 17 namespace proximity_auth { |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 // The time, in milliseconds, to wait for phones to respond to the CryptAuth | 21 // The time, in milliseconds, to wait for phones to respond to the CryptAuth |
| 22 // ping before querying for reachable devices. | 22 // ping before querying for reachable devices. |
| 23 const int kWaitTimeMillis = 7000; | 23 const int kWaitTimeMillis = 7000; |
| 24 | 24 |
| 25 } // namespace | 25 } // namespace |
| 26 | 26 |
| 27 ReachablePhoneFlow::ReachablePhoneFlow(CryptAuthClientFactory* client_factory) | 27 ReachablePhoneFlow::ReachablePhoneFlow( |
| 28 cryptauth::CryptAuthClientFactory* client_factory) |
| 28 : client_factory_(client_factory), weak_ptr_factory_(this) {} | 29 : client_factory_(client_factory), weak_ptr_factory_(this) {} |
| 29 | 30 |
| 30 ReachablePhoneFlow::~ReachablePhoneFlow() {} | 31 ReachablePhoneFlow::~ReachablePhoneFlow() {} |
| 31 | 32 |
| 32 void ReachablePhoneFlow::Run(const ReachablePhonesCallback& callback) { | 33 void ReachablePhoneFlow::Run(const ReachablePhonesCallback& callback) { |
| 33 if (!callback_.is_null()) { | 34 if (!callback_.is_null()) { |
| 34 PA_LOG(ERROR) << "Flow already started."; | 35 PA_LOG(ERROR) << "Flow already started."; |
| 35 callback.Run(std::vector<cryptauth::ExternalDeviceInfo>()); | 36 callback.Run(std::vector<cryptauth::ExternalDeviceInfo>()); |
| 36 return; | 37 return; |
| 37 } | 38 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 response.eligible_devices().end(), reachable_phones.begin()); | 84 response.eligible_devices().end(), reachable_phones.begin()); |
| 84 callback_.Run(reachable_phones); | 85 callback_.Run(reachable_phones); |
| 85 } | 86 } |
| 86 | 87 |
| 87 void ReachablePhoneFlow::OnApiCallError(const std::string& error) { | 88 void ReachablePhoneFlow::OnApiCallError(const std::string& error) { |
| 88 PA_LOG(ERROR) << "Error making api call: " << error; | 89 PA_LOG(ERROR) << "Error making api call: " << error; |
| 89 callback_.Run(std::vector<cryptauth::ExternalDeviceInfo>()); | 90 callback_.Run(std::vector<cryptauth::ExternalDeviceInfo>()); |
| 90 } | 91 } |
| 91 | 92 |
| 92 } // namespace proximity_auth | 93 } // namespace proximity_auth |
| OLD | NEW |