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

Unified Diff: net/quic/quic_stream_factory.cc

Issue 1614573002: Minor refactor of MaybeMigrateOrCloseSessions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@home
Patch Set: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/quic/quic_stream_factory.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/quic/quic_stream_factory.cc
diff --git a/net/quic/quic_stream_factory.cc b/net/quic/quic_stream_factory.cc
index 858f1cb93f0744e9960bd084dcd0393f8b1b04b4..ca8691ed38e3ecb3f0e3caa2ef5db487bcf19fdf 100644
--- a/net/quic/quic_stream_factory.cc
+++ b/net/quic/quic_stream_factory.cc
@@ -1183,11 +1183,8 @@ void QuicStreamFactory::OnNetworkSoonToDisconnect(
MaybeMigrateOrCloseSessions(network, /*force_close=*/false);
}
-void QuicStreamFactory::MaybeMigrateOrCloseSessions(
- NetworkChangeNotifier::NetworkHandle network,
- bool force_close) {
- DCHECK_NE(NetworkChangeNotifier::kInvalidNetworkHandle, network);
-
+NetworkChangeNotifier::NetworkHandle QuicStreamFactory::FindAlternateNetwork(
+ NetworkChangeNotifier::NetworkHandle network) {
// Find a new network that sessions bound to |network| can be migrated to.
NetworkChangeNotifier::NetworkList network_list;
NetworkChangeNotifier::GetConnectedNetworks(&network_list);
@@ -1199,6 +1196,15 @@ void QuicStreamFactory::MaybeMigrateOrCloseSessions(
break;
}
}
+ return new_network;
+}
Ryan Hamilton 2016/01/21 15:16:02 This can now be simpler: NetworkChangeNotifier::N
Jana 2016/01/21 18:25:50 Ah, right, of course. Done.
+
+void QuicStreamFactory::MaybeMigrateOrCloseSessions(
+ NetworkChangeNotifier::NetworkHandle network,
+ bool force_close) {
+ DCHECK_NE(NetworkChangeNotifier::kInvalidNetworkHandle, network);
+ NetworkChangeNotifier::NetworkHandle new_network =
+ FindAlternateNetwork(network);
QuicStreamFactory::SessionIdMap::iterator it = all_sessions_.begin();
while (it != all_sessions_.end()) {
@@ -1228,38 +1234,41 @@ void QuicStreamFactory::MaybeMigrateOrCloseSessions(
}
continue;
}
+ MigrateSessionToNetwork(session, new_network);
+ }
+}
- // Use OS-specified port for socket (DEFAULT_BIND) instead of
- // using the PortSuggester since the connection is being migrated
- // and not being newly created.
- scoped_ptr<DatagramClientSocket> socket(
- client_socket_factory_->CreateDatagramClientSocket(
- DatagramSocket::DEFAULT_BIND, RandIntCallback(),
- session->net_log().net_log(), session->net_log().source()));
-
- QuicConnection* connection = session->connection();
- if (ConfigureSocket(socket.get(), connection->peer_address(),
- new_network) != OK) {
- session->CloseSessionOnError(ERR_NETWORK_CHANGED, QUIC_INTERNAL_ERROR);
- HistogramMigrationStatus(MIGRATION_STATUS_INTERNAL_ERROR);
- continue;
- }
-
- scoped_ptr<QuicPacketReader> new_reader(new QuicPacketReader(
- socket.get(), clock_.get(), session, yield_after_packets_,
- yield_after_duration_, session->net_log()));
- scoped_ptr<QuicPacketWriter> new_writer(
- new QuicDefaultPacketWriter(socket.get()));
-
- if (!session->MigrateToSocket(std::move(socket), std::move(new_reader),
- std::move(new_writer))) {
- session->CloseSessionOnError(ERR_NETWORK_CHANGED,
- QUIC_CONNECTION_MIGRATION_TOO_MANY_CHANGES);
- HistogramMigrationStatus(MIGRATION_STATUS_TOO_MANY_CHANGES);
- } else {
- HistogramMigrationStatus(MIGRATION_STATUS_SUCCESS);
- }
+void QuicStreamFactory::MigrateSessionToNetwork(
+ QuicChromiumClientSession* session,
+ NetworkChangeNotifier::NetworkHandle new_network) {
+ // Use OS-specified port for socket (DEFAULT_BIND) instead of
+ // using the PortSuggester since the connection is being migrated
+ // and not being newly created.
+ scoped_ptr<DatagramClientSocket> socket(
+ client_socket_factory_->CreateDatagramClientSocket(
+ DatagramSocket::DEFAULT_BIND, RandIntCallback(),
+ session->net_log().net_log(), session->net_log().source()));
+ QuicConnection* connection = session->connection();
+ if (ConfigureSocket(socket.get(), connection->peer_address(), new_network) !=
+ OK) {
+ session->CloseSessionOnError(ERR_NETWORK_CHANGED, QUIC_INTERNAL_ERROR);
+ HistogramMigrationStatus(MIGRATION_STATUS_INTERNAL_ERROR);
+ return;
+ }
+ scoped_ptr<QuicPacketReader> new_reader(new QuicPacketReader(
+ socket.get(), clock_.get(), session, yield_after_packets_,
+ yield_after_duration_, session->net_log()));
+ scoped_ptr<QuicPacketWriter> new_writer(
+ new QuicDefaultPacketWriter(socket.get()));
+
+ if (!session->MigrateToSocket(std::move(socket), std::move(new_reader),
+ std::move(new_writer))) {
+ session->CloseSessionOnError(ERR_NETWORK_CHANGED,
+ QUIC_CONNECTION_MIGRATION_TOO_MANY_CHANGES);
+ HistogramMigrationStatus(MIGRATION_STATUS_TOO_MANY_CHANGES);
+ return;
}
+ HistogramMigrationStatus(MIGRATION_STATUS_SUCCESS);
}
void QuicStreamFactory::OnSSLConfigChanged() {
« no previous file with comments | « net/quic/quic_stream_factory.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698