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

Side by Side Diff: blimp/net/engine_authentication_handler.cc

Issue 1551583003: Implementation and fixes for Blimp client/engine E2E communication. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@dtrainor-linux-cl1528243002
Patch Set: Haibin feedback Created 4 years, 11 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 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
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 connection_->SetConnectionErrorObserver(this); 67 DVLOG(1) << "Authenticator object created.";
68
69 // Observe for errors that might occur during the authentication phase.
70 connection_->AddConnectionErrorObserver(this);
68 connection_->SetIncomingMessageProcessor(this); 71 connection_->SetIncomingMessageProcessor(this);
69 timeout_timer_.Start( 72 timeout_timer_.Start(
70 FROM_HERE, base::TimeDelta::FromSeconds(kAuthTimeoutDurationInSeconds), 73 FROM_HERE, base::TimeDelta::FromSeconds(kAuthTimeoutDurationInSeconds),
71 this, &Authenticator::OnAuthenticationTimeout); 74 this, &Authenticator::OnAuthenticationTimeout);
72 } 75 }
73 76
74 Authenticator::~Authenticator() {} 77 Authenticator::~Authenticator() {}
75 78
76 void Authenticator::OnConnectionAuthenticated(bool authenticated) { 79 void Authenticator::OnConnectionAuthenticated(bool authenticated) {
77 connection_->SetIncomingMessageProcessor(nullptr); 80 DVLOG(1) << "OnConnectionAuthenticated result=" << authenticated;
78 connection_->SetConnectionErrorObserver(nullptr);
79 81
80 if (authenticated && connection_handler_) { 82 if (authenticated && connection_handler_) {
83 // Authentication is successful. Stop observing connection errors.
84 connection_->RemoveConnectionErrorObserver(this);
81 connection_handler_->HandleConnection(std::move(connection_)); 85 connection_handler_->HandleConnection(std::move(connection_));
82 } 86 }
83 87
84 delete this; 88 delete this;
85 } 89 }
86 90
87 void Authenticator::OnAuthenticationTimeout() { 91 void Authenticator::OnAuthenticationTimeout() {
88 DVLOG(1) << "Connection authentication timeout"; 92 DVLOG(1) << "Connection authentication timeout";
89 OnConnectionAuthenticated(false); 93 OnConnectionAuthenticated(false);
90 } 94 }
91 95
92 void Authenticator::OnConnectionError(int error) { 96 void Authenticator::OnConnectionError(int error) {
93 DVLOG(1) << "Connection error before authenticated " 97 DVLOG(1) << "Connection error before authenticated "
94 << net::ErrorToString(error); 98 << net::ErrorToString(error);
95 OnConnectionAuthenticated(false); 99 OnConnectionAuthenticated(false);
96 } 100 }
97 101
98 void Authenticator::ProcessMessage(scoped_ptr<BlimpMessage> message, 102 void Authenticator::ProcessMessage(scoped_ptr<BlimpMessage> message,
99 const net::CompletionCallback& callback) { 103 const net::CompletionCallback& callback) {
100 if (message->type() == BlimpMessage::PROTOCOL_CONTROL) { 104 if (message->type() == BlimpMessage::PROTOCOL_CONTROL) {
101 // TODO(haibinlu): check client token. 105 DVLOG(1) << "Authentication challenge received: "
106 << message->protocol_control().start_connection().client_token();
102 OnConnectionAuthenticated(true); 107 OnConnectionAuthenticated(true);
103 } else { 108 } else {
104 DVLOG(1) << "The first message is not START_CONNECTION"; 109 DVLOG(1) << "Expected START_CONNECTION message, got " << message
110 << " instead.";
105 OnConnectionAuthenticated(false); 111 OnConnectionAuthenticated(false);
106 } 112 }
107 113
108 callback.Run(net::OK); 114 callback.Run(net::OK);
109 } 115 }
110 116
111 } // namespace 117 } // namespace
112 118
113 EngineAuthenticationHandler::EngineAuthenticationHandler( 119 EngineAuthenticationHandler::EngineAuthenticationHandler(
114 ConnectionHandler* connection_handler) 120 ConnectionHandler* connection_handler)
115 : connection_handler_weak_factory_(connection_handler) {} 121 : connection_handler_weak_factory_(connection_handler) {}
116 122
117 EngineAuthenticationHandler::~EngineAuthenticationHandler() {} 123 EngineAuthenticationHandler::~EngineAuthenticationHandler() {}
118 124
119 void EngineAuthenticationHandler::HandleConnection( 125 void EngineAuthenticationHandler::HandleConnection(
120 scoped_ptr<BlimpConnection> connection) { 126 scoped_ptr<BlimpConnection> connection) {
121 // Authenticator manages its own lifetime. 127 // Authenticator manages its own lifetime.
122 new Authenticator(std::move(connection), 128 new Authenticator(std::move(connection),
123 connection_handler_weak_factory_.GetWeakPtr()); 129 connection_handler_weak_factory_.GetWeakPtr());
124 } 130 }
125 131
126 } // namespace blimp 132 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698