OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/local_discovery/privetv3_setup_flow.h" | 5 #include "chrome/browser/local_discovery/privetv3_setup_flow.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "chrome/browser/local_discovery/gcd_registration_ticket_request.h" | 8 #include "chrome/browser/local_discovery/gcd_registration_ticket_request.h" |
9 | 9 |
10 namespace local_discovery { | 10 namespace local_discovery { |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
79 void PrivetV3SetupFlow::OnCodeConfirmed(bool success) { | 79 void PrivetV3SetupFlow::OnCodeConfirmed(bool success) { |
80 if (!success) | 80 if (!success) |
81 return OnSetupError(); | 81 return OnSetupError(); |
82 session_->ConfirmCode("1234", base::Bind(&PrivetV3SetupFlow::OnPairingDone, | 82 session_->ConfirmCode("1234", base::Bind(&PrivetV3SetupFlow::OnPairingDone, |
83 weak_ptr_factory_.GetWeakPtr())); | 83 weak_ptr_factory_.GetWeakPtr())); |
84 } | 84 } |
85 | 85 |
86 void PrivetV3SetupFlow::OnSessionInitialized( | 86 void PrivetV3SetupFlow::OnSessionInitialized( |
87 PrivetV3Session::Result result, | 87 PrivetV3Session::Result result, |
88 const std::vector<PrivetV3Session::PairingType>& types) { | 88 const std::vector<PrivetV3Session::PairingType>& types) { |
89 if (result != PrivetV3Session::Result::STATUS_SUCCESS) | 89 if (result != PrivetV3Session::Result::STATUS_SUCCESS || |
90 !std::count(types.begin(), types.end(), | |
91 PrivetV3Session::PairingType::PAIRING_TYPE_EMBEDDEDCODE)) { | |
Aleksey Shlyapnikov
2015/01/26 21:47:45
std::count will iterate over all elements, use std
| |
90 return OnSetupError(); | 92 return OnSetupError(); |
91 session_->StartPairing(PrivetV3Session::PairingType::PAIRING_TYPE_PINCODE, | 93 } |
92 base::Bind(&PrivetV3SetupFlow::OnPairingStarted, | 94 session_->StartPairing( |
93 weak_ptr_factory_.GetWeakPtr())); | 95 PrivetV3Session::PairingType::PAIRING_TYPE_EMBEDDEDCODE, |
96 base::Bind(&PrivetV3SetupFlow::OnPairingStarted, | |
97 weak_ptr_factory_.GetWeakPtr())); | |
94 } | 98 } |
95 | 99 |
96 void PrivetV3SetupFlow::OnPairingStarted(PrivetV3Session::Result result) { | 100 void PrivetV3SetupFlow::OnPairingStarted(PrivetV3Session::Result result) { |
97 if (result != PrivetV3Session::Result::STATUS_SUCCESS) | 101 if (result != PrivetV3Session::Result::STATUS_SUCCESS) |
98 return OnSetupError(); | 102 return OnSetupError(); |
99 delegate_->ConfirmSecurityCode(base::Bind(&PrivetV3SetupFlow::OnCodeConfirmed, | 103 delegate_->ConfirmSecurityCode(base::Bind(&PrivetV3SetupFlow::OnCodeConfirmed, |
100 weak_ptr_factory_.GetWeakPtr())); | 104 weak_ptr_factory_.GetWeakPtr())); |
101 } | 105 } |
102 | 106 |
103 void PrivetV3SetupFlow::OnPairingDone(PrivetV3Session::Result result) { | 107 void PrivetV3SetupFlow::OnPairingDone(PrivetV3Session::Result result) { |
104 if (result != PrivetV3Session::Result::STATUS_SUCCESS) | 108 if (result != PrivetV3Session::Result::STATUS_SUCCESS) |
105 return OnSetupError(); | 109 return OnSetupError(); |
106 base::DictionaryValue message; | 110 base::DictionaryValue message; |
107 message.SetString(kTicketJsonKeyName, ticket_id_); | 111 message.SetString(kTicketJsonKeyName, ticket_id_); |
108 message.SetString(kUserJsonKeyName, "me"); | 112 message.SetString(kUserJsonKeyName, "me"); |
109 session_->SendMessage("/privet/v3/setup/start", message, | 113 session_->SendMessage("/privet/v3/setup/start", message, |
110 base::Bind(&PrivetV3SetupFlow::OnSetupMessageSent, | 114 base::Bind(&PrivetV3SetupFlow::OnSetupMessageSent, |
111 weak_ptr_factory_.GetWeakPtr())); | 115 weak_ptr_factory_.GetWeakPtr())); |
112 } | 116 } |
113 | 117 |
114 void PrivetV3SetupFlow::OnSetupMessageSent( | 118 void PrivetV3SetupFlow::OnSetupMessageSent( |
115 PrivetV3Session::Result result, | 119 PrivetV3Session::Result result, |
116 const base::DictionaryValue& response) { | 120 const base::DictionaryValue& response) { |
117 if (result != PrivetV3Session::Result::STATUS_SUCCESS) | 121 if (result != PrivetV3Session::Result::STATUS_SUCCESS) |
118 return OnSetupError(); | 122 return OnSetupError(); |
119 delegate_->OnSetupDone(); | 123 delegate_->OnSetupDone(); |
120 } | 124 } |
121 | 125 |
122 } // namespace local_discovery | 126 } // namespace local_discovery |
OLD | NEW |