Code cleanup in QNAM

The private class already store a QNetworkConfigurationManager
 and networkSessionRequired so it's not need to compute them again
nor to instantiate temporary classes.

Change-Id: I1bbd9439afa70c950ed6ec3e4fc63ddae4a5b259
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
This commit is contained in:
Filipe Azevedo 2017-11-22 11:49:56 +01:00
parent 0f3c9782e6
commit 048c380629

View File

@ -985,8 +985,7 @@ QNetworkConfiguration QNetworkAccessManager::configuration() const
if (session) { if (session) {
return session->configuration(); return session->configuration();
} else { } else {
QNetworkConfigurationManager manager; return d->networkConfigurationManager.defaultConfiguration();
return manager.defaultConfiguration();
} }
} }
@ -1010,12 +1009,11 @@ QNetworkConfiguration QNetworkAccessManager::activeConfiguration() const
Q_D(const QNetworkAccessManager); Q_D(const QNetworkAccessManager);
QSharedPointer<QNetworkSession> networkSession(d->getNetworkSession()); QSharedPointer<QNetworkSession> networkSession(d->getNetworkSession());
QNetworkConfigurationManager manager;
if (networkSession) { if (networkSession) {
return manager.configurationFromIdentifier( return d->networkConfigurationManager.configurationFromIdentifier(
networkSession->sessionProperty(QLatin1String("ActiveConfiguration")).toString()); networkSession->sessionProperty(QLatin1String("ActiveConfiguration")).toString());
} else { } else {
return manager.defaultConfiguration(); return d->networkConfigurationManager.defaultConfiguration();
} }
} }
@ -1342,17 +1340,16 @@ QNetworkReply *QNetworkAccessManager::createRequest(QNetworkAccessManager::Opera
} }
if (!d->networkSessionStrongRef && (d->initializeSession || !d->networkConfiguration.identifier().isEmpty())) { if (!d->networkSessionStrongRef && (d->initializeSession || !d->networkConfiguration.identifier().isEmpty())) {
QNetworkConfigurationManager manager;
if (!d->networkConfiguration.identifier().isEmpty()) { if (!d->networkConfiguration.identifier().isEmpty()) {
if ((d->networkConfiguration.state() & QNetworkConfiguration::Defined) if ((d->networkConfiguration.state() & QNetworkConfiguration::Defined)
&& d->networkConfiguration != manager.defaultConfiguration()) && d->networkConfiguration != d->networkConfigurationManager.defaultConfiguration())
d->createSession(manager.defaultConfiguration()); d->createSession(d->networkConfigurationManager.defaultConfiguration());
else else
d->createSession(d->networkConfiguration); d->createSession(d->networkConfiguration);
} else { } else {
if (manager.capabilities() & QNetworkConfigurationManager::NetworkSessionRequired) if (d->networkSessionRequired)
d->createSession(manager.defaultConfiguration()); d->createSession(d->networkConfigurationManager.defaultConfiguration());
else else
d->initializeSession = false; d->initializeSession = false;
} }
@ -1884,8 +1881,8 @@ void QNetworkAccessManagerPrivate::_q_onlineStateChanged(bool isOnline)
online = (networkConfiguration.state() & QNetworkConfiguration::Active); online = (networkConfiguration.state() & QNetworkConfiguration::Active);
} else { } else {
if (online != isOnline) { if (online != isOnline) {
_q_networkSessionClosed(); _q_networkSessionClosed();
createSession(q->configuration()); createSession(q->configuration());
online = isOnline; online = isOnline;
} }
} }
@ -1909,13 +1906,13 @@ void QNetworkAccessManagerPrivate::_q_configurationChanged(const QNetworkConfigu
const QString id = configuration.identifier(); const QString id = configuration.identifier();
if (configuration.state().testFlag(QNetworkConfiguration::Active)) { if (configuration.state().testFlag(QNetworkConfiguration::Active)) {
if (!onlineConfigurations.contains(id)) { if (!onlineConfigurations.contains(id)) {
QSharedPointer<QNetworkSession> session(getNetworkSession()); QSharedPointer<QNetworkSession> session(getNetworkSession());
if (session) { if (session) {
if (online && session->configuration().identifier() if (online && session->configuration().identifier()
!= networkConfigurationManager.defaultConfiguration().identifier()) { != networkConfigurationManager.defaultConfiguration().identifier()) {
onlineConfigurations.insert(id); onlineConfigurations.insert(id);
// CHECK: If it's having Active flag - why would it be disconnected ???
//this one disconnected but another one is online, //this one disconnected but another one is online,
// close and create new session // close and create new session
_q_networkSessionClosed(); _q_networkSessionClosed();
@ -1926,6 +1923,7 @@ void QNetworkAccessManagerPrivate::_q_configurationChanged(const QNetworkConfigu
} else if (onlineConfigurations.contains(id)) { } else if (onlineConfigurations.contains(id)) {
//this one is disconnecting //this one is disconnecting
// CHECK: If it disconnected while we create a session over a down configuration ???
onlineConfigurations.remove(id); onlineConfigurations.remove(id);
if (!onlineConfigurations.isEmpty()) { if (!onlineConfigurations.isEmpty()) {
_q_networkSessionClosed(); _q_networkSessionClosed();