shill: detect password change on user profile load

When loading a user profile, the stored password should be checked
against the currently active password.  A credential change should
be detected and handled if the passwords are different.  Additionally
removed the Service::SaveToProfile call in Service::SetHasEverConnected
to avoid overwriting a previously loaded profile.  Removed ordering
dependence on loading parts of a profile by adding a boolean to
Service::OnEapCredentialsChanged to differentiate between loading
credentials from a profile and changing credentials. In WiFi services
that do not use EAP for authentication, ignore changes to EAP credentials.
This allows only passphrase changes to trigger a disconnect when the
service is loaded from a new profile.

BUG=chromium:414889, chromium:414562
TEST=unit tests with and manual verification on peppy:
Connect to a new PSK network while logged in.  Log out (system should
disconnect).  Connect to the same network again (while still logged out).
Log in, and ensure that the system does not disconnect and re-connect to
the network in the process.

Change-Id: I6eef098728951cfd0118e94278d76caf595d5b81
Reviewed-on: https://chromium-review.googlesource.com/218618
Reviewed-by: Rebecca Silberstein <silberst@chromium.org>
Tested-by: Rebecca Silberstein <silberst@chromium.org>
Commit-Queue: Rebecca Silberstein <silberst@chromium.org>
diff --git a/service.h b/service.h
index 927ab67..34f8df8 100644
--- a/service.h
+++ b/service.h
@@ -126,6 +126,11 @@
     kCryptoAes
   };
 
+  enum UpdateCredentialsReason{
+    kReasonCredentialsLoaded,
+    kReasonPropertyUpdate
+  };
+
   static const int kPriorityNone;
 
   // A constructor for the Service object
@@ -445,7 +450,7 @@
   // Notification that occurs when an EAP credential property has been
   // changed.  Some service subclasses can choose to respond to this
   // event.
-  virtual void OnEapCredentialsChanged() {}
+  virtual void OnEapCredentialsChanged(UpdateCredentialsReason reason) {}
 
   // Called by the manager once after a resume.
   virtual void OnAfterResume();
@@ -663,6 +668,7 @@
   FRIEND_TEST(WiFiServiceTest, SetPassphraseResetHasEverConnected);
   FRIEND_TEST(WiFiServiceTest, SuspectedCredentialFailure);
   FRIEND_TEST(WiFiServiceTest, SetPassphraseRemovesCachedCredentials);
+  FRIEND_TEST(WiFiServiceTest, LoadPassphraseClearCredentials);
   FRIEND_TEST(WiFiTimerTest, ReconnectTimer);
   FRIEND_TEST(WiFiMainTest, EAPEvent);  // For eap_.
   FRIEND_TEST(WiMaxServiceTest, ChangeCredResetHasEverConnected);