Chromium Code Reviews| 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 "blimp/net/engine_authentication_handler.h" | 5 #include "blimp/net/engine_authentication_handler.h" |
| 6 | 6 |
| 7 #include "base/callback_helpers.h" | 7 #include "base/callback_helpers.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/timer/timer.h" | 9 #include "base/timer/timer.h" |
| 10 #include "blimp/common/proto/blimp_message.pb.h" | 10 #include "blimp/common/proto/blimp_message.pb.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 57 base::OneShotTimer timeout_timer_; | 57 base::OneShotTimer timeout_timer_; |
| 58 | 58 |
| 59 DISALLOW_COPY_AND_ASSIGN(Authenticator); | 59 DISALLOW_COPY_AND_ASSIGN(Authenticator); |
| 60 }; | 60 }; |
| 61 | 61 |
| 62 Authenticator::Authenticator( | 62 Authenticator::Authenticator( |
| 63 scoped_ptr<BlimpConnection> connection, | 63 scoped_ptr<BlimpConnection> connection, |
| 64 base::WeakPtr<ConnectionHandler> connection_handler) | 64 base::WeakPtr<ConnectionHandler> connection_handler) |
| 65 : connection_(std::move(connection)), | 65 : connection_(std::move(connection)), |
| 66 connection_handler_(connection_handler) { | 66 connection_handler_(connection_handler) { |
| 67 DVLOG(1) << "Authenticator object created."; | |
| 67 connection_->SetConnectionErrorObserver(this); | 68 connection_->SetConnectionErrorObserver(this); |
| 68 connection_->SetIncomingMessageProcessor(this); | 69 connection_->SetIncomingMessageProcessor(this); |
| 69 timeout_timer_.Start( | 70 timeout_timer_.Start( |
| 70 FROM_HERE, base::TimeDelta::FromSeconds(kAuthTimeoutDurationInSeconds), | 71 FROM_HERE, base::TimeDelta::FromSeconds(kAuthTimeoutDurationInSeconds), |
| 71 this, &Authenticator::OnAuthenticationTimeout); | 72 this, &Authenticator::OnAuthenticationTimeout); |
| 72 } | 73 } |
| 73 | 74 |
| 74 Authenticator::~Authenticator() {} | 75 Authenticator::~Authenticator() {} |
| 75 | 76 |
| 76 void Authenticator::OnConnectionAuthenticated(bool authenticated) { | 77 void Authenticator::OnConnectionAuthenticated(bool authenticated) { |
| 77 connection_->SetIncomingMessageProcessor(nullptr); | 78 DVLOG(1) << "OnConnectionAuthenticated result=" << authenticated; |
| 78 connection_->SetConnectionErrorObserver(nullptr); | |
| 79 | |
| 80 if (authenticated && connection_handler_) { | 79 if (authenticated && connection_handler_) { |
| 80 // We expect |connection_handler_| to provide |connection_| with its own | |
| 81 // ConnectionErrorObserver and IncomingMessageProcessor objects, | |
|
haibinlu
2015/12/29 00:51:46
I prefer to set nullptr as before, rather than rel
Kevin M
2015/12/30 23:08:49
Removed ErrorObserver from here.
I'm not sure I u
| |
| 82 // so there is no need to unset them beforehand. | |
| 81 connection_handler_->HandleConnection(std::move(connection_)); | 83 connection_handler_->HandleConnection(std::move(connection_)); |
| 82 } | 84 } |
| 83 | |
| 84 delete this; | 85 delete this; |
| 85 } | 86 } |
| 86 | 87 |
| 87 void Authenticator::OnAuthenticationTimeout() { | 88 void Authenticator::OnAuthenticationTimeout() { |
| 88 DVLOG(1) << "Connection authentication timeout"; | 89 DVLOG(1) << "Connection authentication timeout"; |
| 89 OnConnectionAuthenticated(false); | 90 OnConnectionAuthenticated(false); |
| 90 } | 91 } |
| 91 | 92 |
| 92 void Authenticator::OnConnectionError(int error) { | 93 void Authenticator::OnConnectionError(int error) { |
| 93 DVLOG(1) << "Connection error before authenticated " | 94 DVLOG(1) << "Connection error before authenticated " |
| 94 << net::ErrorToString(error); | 95 << net::ErrorToString(error); |
| 95 OnConnectionAuthenticated(false); | 96 OnConnectionAuthenticated(false); |
| 96 } | 97 } |
| 97 | 98 |
| 98 void Authenticator::ProcessMessage(scoped_ptr<BlimpMessage> message, | 99 void Authenticator::ProcessMessage(scoped_ptr<BlimpMessage> message, |
| 99 const net::CompletionCallback& callback) { | 100 const net::CompletionCallback& callback) { |
| 100 if (message->type() == BlimpMessage::PROTOCOL_CONTROL) { | 101 if (message->type() == BlimpMessage::PROTOCOL_CONTROL) { |
| 101 // TODO(haibinlu): check client token. | 102 DVLOG(1) << "Authentication challenge received: " |
|
haibinlu
2015/12/29 00:51:46
keep TODO since you are not verifying the client t
Kevin M
2015/12/30 23:08:49
Done.
| |
| 103 << message->protocol_control().start_connection().client_token(); | |
| 102 OnConnectionAuthenticated(true); | 104 OnConnectionAuthenticated(true); |
| 103 } else { | 105 } else { |
| 104 DVLOG(1) << "The first message is not START_CONNECTION"; | 106 DVLOG(1) << "The first message is not START_CONNECTION; got type " |
| 107 << message->type() << " instead."; | |
| 105 OnConnectionAuthenticated(false); | 108 OnConnectionAuthenticated(false); |
| 106 } | 109 } |
| 107 | 110 |
| 108 callback.Run(net::OK); | 111 callback.Run(net::OK); |
| 109 } | 112 } |
| 110 | 113 |
| 111 } // namespace | 114 } // namespace |
| 112 | 115 |
| 113 EngineAuthenticationHandler::EngineAuthenticationHandler( | 116 EngineAuthenticationHandler::EngineAuthenticationHandler( |
| 114 ConnectionHandler* connection_handler) | 117 ConnectionHandler* connection_handler) |
| 115 : connection_handler_weak_factory_(connection_handler) {} | 118 : connection_handler_weak_factory_(connection_handler) {} |
| 116 | 119 |
| 117 EngineAuthenticationHandler::~EngineAuthenticationHandler() {} | 120 EngineAuthenticationHandler::~EngineAuthenticationHandler() {} |
| 118 | 121 |
| 119 void EngineAuthenticationHandler::HandleConnection( | 122 void EngineAuthenticationHandler::HandleConnection( |
| 120 scoped_ptr<BlimpConnection> connection) { | 123 scoped_ptr<BlimpConnection> connection) { |
| 121 // Authenticator manages its own lifetime. | 124 // Authenticator manages its own lifetime. |
| 122 new Authenticator(std::move(connection), | 125 new Authenticator(std::move(connection), |
| 123 connection_handler_weak_factory_.GetWeakPtr()); | 126 connection_handler_weak_factory_.GetWeakPtr()); |
| 124 } | 127 } |
| 125 | 128 |
| 126 } // namespace blimp | 129 } // namespace blimp |
| OLD | NEW |