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/cryptauth/cryptauth_client.h" | 13 #include "components/cryptauth/cryptauth_client.h" |
14 #include "components/cryptauth/proto/cryptauth_api.pb.h" | 14 #include "components/cryptauth/proto/cryptauth_api.pb.h" |
15 #include "components/proximity_auth/logging/logging.h" | 15 #include "components/proximity_auth/logging/logging.h" |
| 16 #include "net/traffic_annotation/network_traffic_annotation.h" |
16 | 17 |
17 namespace proximity_auth { | 18 namespace proximity_auth { |
18 | 19 |
19 namespace { | 20 namespace { |
20 | 21 |
21 // The time, in milliseconds, to wait for phones to respond to the CryptAuth | 22 // The time, in milliseconds, to wait for phones to respond to the CryptAuth |
22 // ping before querying for reachable devices. | 23 // ping before querying for reachable devices. |
23 const int kWaitTimeMillis = 7000; | 24 const int kWaitTimeMillis = 7000; |
24 | 25 |
25 } // namespace | 26 } // namespace |
(...skipping 10 matching lines...) Expand all Loading... |
36 callback.Run(std::vector<cryptauth::ExternalDeviceInfo>()); | 37 callback.Run(std::vector<cryptauth::ExternalDeviceInfo>()); |
37 return; | 38 return; |
38 } | 39 } |
39 | 40 |
40 callback_ = callback; | 41 callback_ = callback; |
41 client_ = client_factory_->CreateInstance(); | 42 client_ = client_factory_->CreateInstance(); |
42 | 43 |
43 // Ping the user's devices to update themselves with CryptAuth. | 44 // Ping the user's devices to update themselves with CryptAuth. |
44 cryptauth::SendDeviceSyncTickleRequest tickle_request; | 45 cryptauth::SendDeviceSyncTickleRequest tickle_request; |
45 tickle_request.set_tickle_type(cryptauth::UPDATE_ENROLLMENT); | 46 tickle_request.set_tickle_type(cryptauth::UPDATE_ENROLLMENT); |
| 47 net::PartialNetworkTrafficAnnotationTag partial_traffic_annotation = |
| 48 net::DefinePartialNetworkTrafficAnnotation("cryptauth_device_sync_tickle", |
| 49 "oauth2_api_call_flow", R"( |
| 50 semantics { |
| 51 sender: "EasyUnlock Debug UI" |
| 52 description: |
| 53 "Triggers a sync on all other device (for the same user) registered " |
| 54 "on CryptAuth." |
| 55 trigger: "User manually opens the EasyUnlock debug UI." |
| 56 data: "OAuth 2.0 token and the device public key." |
| 57 destination: GOOGLE_OWNED_SERVICE |
| 58 } |
| 59 policy { |
| 60 setting: |
| 61 "This feature cannot be disabled in settings, but this request will " |
| 62 "only be sent if the user opens the EasyUnlock debug UI." |
| 63 chrome_policy { |
| 64 SigninAllowed { |
| 65 SigninAllowed: false |
| 66 } |
| 67 } |
| 68 })"); |
46 client_->SendDeviceSyncTickle( | 69 client_->SendDeviceSyncTickle( |
47 tickle_request, base::Bind(&ReachablePhoneFlow::OnSyncTickleSuccess, | 70 tickle_request, |
48 weak_ptr_factory_.GetWeakPtr()), | 71 base::Bind(&ReachablePhoneFlow::OnSyncTickleSuccess, |
| 72 weak_ptr_factory_.GetWeakPtr()), |
49 base::Bind(&ReachablePhoneFlow::OnApiCallError, | 73 base::Bind(&ReachablePhoneFlow::OnApiCallError, |
50 weak_ptr_factory_.GetWeakPtr())); | 74 weak_ptr_factory_.GetWeakPtr()), |
| 75 partial_traffic_annotation); |
51 } | 76 } |
52 | 77 |
53 void ReachablePhoneFlow::OnSyncTickleSuccess( | 78 void ReachablePhoneFlow::OnSyncTickleSuccess( |
54 const cryptauth::SendDeviceSyncTickleResponse& response) { | 79 const cryptauth::SendDeviceSyncTickleResponse& response) { |
55 PA_LOG(INFO) << "Waiting " << kWaitTimeMillis | 80 PA_LOG(INFO) << "Waiting " << kWaitTimeMillis |
56 << "ms for phones to callback to CryptAuth..."; | 81 << "ms for phones to callback to CryptAuth..."; |
57 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 82 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
58 FROM_HERE, base::Bind(&ReachablePhoneFlow::QueryReachablePhones, | 83 FROM_HERE, base::Bind(&ReachablePhoneFlow::QueryReachablePhones, |
59 weak_ptr_factory_.GetWeakPtr()), | 84 weak_ptr_factory_.GetWeakPtr()), |
60 base::TimeDelta::FromMilliseconds(kWaitTimeMillis)); | 85 base::TimeDelta::FromMilliseconds(kWaitTimeMillis)); |
(...skipping 23 matching lines...) Expand all Loading... |
84 response.eligible_devices().end(), reachable_phones.begin()); | 109 response.eligible_devices().end(), reachable_phones.begin()); |
85 callback_.Run(reachable_phones); | 110 callback_.Run(reachable_phones); |
86 } | 111 } |
87 | 112 |
88 void ReachablePhoneFlow::OnApiCallError(const std::string& error) { | 113 void ReachablePhoneFlow::OnApiCallError(const std::string& error) { |
89 PA_LOG(ERROR) << "Error making api call: " << error; | 114 PA_LOG(ERROR) << "Error making api call: " << error; |
90 callback_.Run(std::vector<cryptauth::ExternalDeviceInfo>()); | 115 callback_.Run(std::vector<cryptauth::ExternalDeviceInfo>()); |
91 } | 116 } |
92 | 117 |
93 } // namespace proximity_auth | 118 } // namespace proximity_auth |
OLD | NEW |