Network config: Only set AutoConnect to false

Setting 'AutoConnect' to true during configuration causes Shill to
attempt to connect immediately after configuration which breaks
the notification logic. By default Shill will set AutoConenct to
true on the first successful connect if not explicitly set to false.

This also adds yet more / better logging.

TBR=stevenjb@chromium.org

(cherry picked from commit 1a5003a497c23879f023b588483738146075a639)

Bug: 809902
Cq-Include-Trybots: master.tryserver.chromium.linux:closure_compilation
Change-Id: Ibace61a761b7adf7b5c87e8db93d54d3b3942a48
Reviewed-on: https://chromium-review.googlesource.com/940338
Commit-Queue: Steven Bennetts <stevenjb@chromium.org>
Reviewed-by: Alexander Alekseev <alemate@chromium.org>
Reviewed-by: Toni Barzic <tbarzic@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#539896}
Reviewed-on: https://chromium-review.googlesource.com/941505
Reviewed-by: Steven Bennetts <stevenjb@chromium.org>
Cr-Commit-Position: refs/branch-heads/3325@{#628}
Cr-Branched-From: bc084a8b5afa3744a74927344e304c02ae54189f-refs/heads/master@{#530369}
diff --git a/chrome/browser/ui/ash/network/network_state_notifier.cc b/chrome/browser/ui/ash/network/network_state_notifier.cc
index 9f88ebe..99e1a5c1 100644
--- a/chrome/browser/ui/ash/network/network_state_notifier.cc
+++ b/chrome/browser/ui/ash/network/network_state_notifier.cc
@@ -174,8 +174,12 @@
   const NetworkState* network =
       NetworkHandler::Get()->network_state_handler()->GetNetworkState(
           service_path);
-  if (ShouldConnectFailedNotificationBeShown(error_name, network))
-    ShowNetworkConnectErrorForGuid(error_name, network ? network->guid() : "");
+  if (!ShouldConnectFailedNotificationBeShown(error_name, network)) {
+    NET_LOG(EVENT) << "Skipping notification for: " << service_path
+                   << " Error: " << error_name;
+    return;
+  }
+  ShowNetworkConnectErrorForGuid(error_name, network ? network->guid() : "");
 }
 
 void NetworkStateNotifier::DisconnectRequested(
@@ -353,6 +357,7 @@
   shill_properties.GetStringWithoutPathExpansion(shill::kStateProperty, &state);
   if (NetworkState::StateIsConnected(state) ||
       NetworkState::StateIsConnecting(state)) {
+    NET_LOG(EVENT) << "Skipping connect error notification. State: " << state;
     // Network is no longer in an error state. This can happen if an
     // unexpected idle state transition occurs, see http://crbug.com/333955.
     return;
diff --git a/chromeos/network/network_connection_handler_impl.cc b/chromeos/network/network_connection_handler_impl.cc
index ce23ce6..af86518 100644
--- a/chromeos/network/network_connection_handler_impl.cc
+++ b/chromeos/network/network_connection_handler_impl.cc
@@ -236,7 +236,7 @@
   // Clear any existing queued connect request.
   queued_connect_.reset();
   if (HasConnectingNetwork(service_path)) {
-    NET_LOG_USER("Connect Request While Pending", service_path);
+    NET_LOG(USER) << "Connect Request while pending: " << service_path;
     InvokeConnectErrorCallback(service_path, error_callback, kErrorConnecting);
     return;
   }
@@ -251,6 +251,7 @@
   if (network) {
     // For existing networks, perform some immediate consistency checks.
     if (network->IsConnectedState()) {
+      NET_LOG(ERROR) << "Connect Request while connected: " << service_path;
       InvokeConnectErrorCallback(service_path, error_callback, kErrorConnected);
       return;
     }
@@ -740,10 +741,10 @@
   } else if (dbus_error_name == shill::kErrorResultInProgress) {
     error = kErrorConnecting;
   } else {
-    NET_LOG_ERROR("Connect Failure, Shill error: " + dbus_error_name,
-                  service_path);
     error = kErrorConnectFailed;
   }
+  NET_LOG(ERROR) << "Connect Failure: " << service_path << " Error: " << error
+                 << " Shill error: " << dbus_error_name;
   InvokeConnectErrorCallback(service_path, error_callback, error);
 }
 
diff --git a/ui/webui/resources/cr_components/chromeos/network/network_config.js b/ui/webui/resources/cr_components/chromeos/network/network_config.js
index 6b07c82..74cdc9b 100644
--- a/ui/webui/resources/cr_components/chromeos/network/network_config.js
+++ b/ui/webui/resources/cr_components/chromeos/network/network_config.js
@@ -368,14 +368,14 @@
 
     var propertiesToSet = this.getPropertiesToSet_();
     if (this.getSource_() == CrOnc.Source.NONE) {
-      // New non VPN network configurations default to 'AutoConnect' unless
-      // prohibited by policy.
-      var prohibitAutoConnect = this.globalPolicy &&
-          this.globalPolicy.AllowOnlyPolicyNetworksToConnect;
-      CrOnc.setTypeProperty(
-          propertiesToSet, 'AutoConnect',
-          this.type != CrOnc.Type.VPN && !prohibitAutoConnect);
-
+      // Set 'AutoConnect' to false for VPN or if prohibited by policy.
+      // Note: Do not set AutoConnect to true, the connection manager will do
+      // that on a successful connection (unless set to false here).
+      if (this.type == CrOnc.Type.VPN ||
+          (this.globalPolicy &&
+           this.globalPolicy.AllowOnlyPolicyNetworksToConnect)) {
+        CrOnc.setTypeProperty(propertiesToSet, 'AutoConnect', false);
+      }
       // Create the configuration, then connect to it in the callback.
       this.networkingPrivate.createNetwork(
           this.shareNetwork_, propertiesToSet,