Index: chrome/browser/extensions/api/networking_private/networking_private_credentials_getter_win.cc |
diff --git a/chrome/browser/extensions/api/networking_private/networking_private_credentials_getter_win.cc b/chrome/browser/extensions/api/networking_private/networking_private_credentials_getter_win.cc |
index 77653d88c019ce554a92cfd588a9d51cf2464018..c04b9a86cd56f832c3e6976ba8e319fb66ccaa92 100644 |
--- a/chrome/browser/extensions/api/networking_private/networking_private_credentials_getter_win.cc |
+++ b/chrome/browser/extensions/api/networking_private/networking_private_credentials_getter_win.cc |
@@ -7,102 +7,43 @@ |
#include "base/base64.h" |
#include "base/bind.h" |
#include "base/message_loop/message_loop.h" |
-#include "base/threading/sequenced_worker_pool.h" |
-#include "chrome/common/chrome_utility_messages.h" |
-#include "content/public/browser/browser_thread.h" |
-#include "content/public/browser/utility_process_host.h" |
+#include "chrome/browser/extensions/api/networking_private/networking_private_service_client.h" |
+#include "chrome/browser/local_discovery/wifi/credential_getter_win.h" |
+#include "chrome/common/extensions/api/networking_private/networking_private_crypto.h" |
-using content::BrowserThread; |
-using content::UtilityProcessHost; |
using extensions::NetworkingPrivateCredentialsGetter; |
stevenjb
2014/06/23 17:12:20
Unnecessary? (Code is in extensions namespace)
Noam Samuel
2014/06/23 17:55:44
Done.
|
+using local_discovery::wifi::CredentialGetterWin; |
+using extensions::NetworkingPrivateServiceClient; |
stevenjb
2014/06/23 17:12:20
Ditto
Noam Samuel
2014/06/23 17:55:44
Done.
|
-namespace { |
- |
-class CredentialsGetterHostClient : public content::UtilityProcessHostClient { |
- public: |
- CredentialsGetterHostClient(); |
- |
- virtual ~CredentialsGetterHostClient(); |
- |
- // UtilityProcessHostClient |
- virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
- virtual void OnProcessCrashed(int exit_code) OVERRIDE; |
- virtual void OnProcessLaunchFailed() OVERRIDE; |
- |
- // IPC message handlers. |
- void OnGotEncryptedCredentials(const std::vector<uint8>& key_data, |
- bool success); |
- |
- // Starts the utility process that gets wifi passphrase from system. |
- void StartProcessOnIOThread( |
- const std::string& network_guid, |
- const std::string& public_key, |
- const extensions::NetworkingPrivateServiceClient::CryptoVerify:: |
- VerifyAndEncryptCredentialsCallback& callback); |
- |
- private: |
- // Callback for reporting the result. |
- extensions::NetworkingPrivateServiceClient::CryptoVerify:: |
- VerifyAndEncryptCredentialsCallback callback_; |
- |
- DISALLOW_COPY_AND_ASSIGN(CredentialsGetterHostClient); |
-}; |
- |
-CredentialsGetterHostClient::CredentialsGetterHostClient() {} |
- |
-CredentialsGetterHostClient::~CredentialsGetterHostClient() {} |
- |
-bool CredentialsGetterHostClient::OnMessageReceived( |
- const IPC::Message& message) { |
- bool handled = true; |
- IPC_BEGIN_MESSAGE_MAP(CredentialsGetterHostClient, message) |
- IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_GotEncryptedWiFiCredentials, |
- OnGotEncryptedCredentials) |
- IPC_MESSAGE_UNHANDLED(handled = false) |
- IPC_END_MESSAGE_MAP() |
- return handled; |
-} |
- |
-void CredentialsGetterHostClient::OnProcessCrashed(int exit_code) { |
- callback_.Run("", "Process Crashed"); |
-} |
+namespace extensions { |
-void CredentialsGetterHostClient::OnProcessLaunchFailed() { |
- callback_.Run("", "Process Launch Failed"); |
-} |
+namespace { |
-void CredentialsGetterHostClient::OnGotEncryptedCredentials( |
- const std::vector<uint8>& key_data, |
- bool success) { |
- if (success) { |
- std::string base64_encoded_key_data; |
- base::Base64Encode(std::string(key_data.begin(), key_data.end()), |
- &base64_encoded_key_data); |
- callback_.Run(base64_encoded_key_data, ""); |
- } else { |
- callback_.Run("", "Get Credentials Failed"); |
+void OnGotCredentials(const NetworkingPrivateServiceClient::CryptoVerify:: |
+ VerifyAndEncryptCredentialsCallback& callback, |
+ const std::string& public_key, |
+ bool success, |
+ const std::string& key_data) { |
+ if (!success) { |
+ callback.Run("", "Could not retrieve credentials"); |
} |
-} |
-void CredentialsGetterHostClient::StartProcessOnIOThread( |
- const std::string& network_guid, |
- const std::string& public_key, |
- const extensions::NetworkingPrivateServiceClient::CryptoVerify:: |
- VerifyAndEncryptCredentialsCallback& callback) { |
- DCHECK_CURRENTLY_ON(BrowserThread::IO); |
+ NetworkingPrivateCrypto crypto; |
std::vector<uint8> public_key_data(public_key.begin(), public_key.end()); |
- UtilityProcessHost* host = |
- UtilityProcessHost::Create(this, base::MessageLoopProxy::current()); |
- callback_ = callback; |
- host->ElevatePrivileges(); |
- host->Send(new ChromeUtilityHostMsg_GetAndEncryptWiFiCredentials( |
- network_guid, public_key_data)); |
+ std::vector<uint8> ciphertext; |
+ if (!crypto.EncryptByteString(public_key_data, key_data, &ciphertext)) { |
+ callback.Run("", "Encryption failed"); |
+ return; |
+ } |
+ |
+ std::string base64_encoded_ciphertext; |
+ base::Base64Encode(std::string(ciphertext.begin(), ciphertext.end()), |
+ &base64_encoded_ciphertext); |
+ callback.Run(base64_encoded_ciphertext, ""); |
stevenjb
2014/06/23 17:12:20
nit: the above might be a little more clear if 'er
Noam Samuel
2014/06/23 17:55:44
Done.
|
} |
} // namespace |
-namespace extensions { |
- |
class NetworkingPrivateCredentialsGetterWin |
: public NetworkingPrivateCredentialsGetter { |
public: |
@@ -111,31 +52,33 @@ class NetworkingPrivateCredentialsGetterWin |
virtual void Start( |
const std::string& network_guid, |
const std::string& public_key, |
- const extensions::NetworkingPrivateServiceClient::CryptoVerify:: |
+ const NetworkingPrivateServiceClient::CryptoVerify:: |
VerifyAndEncryptCredentialsCallback& callback) OVERRIDE; |
private: |
virtual ~NetworkingPrivateCredentialsGetterWin(); |
+ scoped_refptr<CredentialGetterWin> credentials_getter_; |
+ |
+ base::WeakPtrFactory<NetworkingPrivateCredentialsGetterWin> weak_factory_; |
stevenjb
2014/06/23 17:12:20
Unused?
Noam Samuel
2014/06/23 17:55:44
Done.
|
DISALLOW_COPY_AND_ASSIGN(NetworkingPrivateCredentialsGetterWin); |
}; |
-NetworkingPrivateCredentialsGetterWin::NetworkingPrivateCredentialsGetterWin() { |
+NetworkingPrivateCredentialsGetterWin::NetworkingPrivateCredentialsGetterWin() |
+ : weak_factory_(this) { |
} |
void NetworkingPrivateCredentialsGetterWin::Start( |
const std::string& network_guid, |
const std::string& public_key, |
- const extensions::NetworkingPrivateServiceClient::CryptoVerify:: |
+ const NetworkingPrivateServiceClient::CryptoVerify:: |
VerifyAndEncryptCredentialsCallback& callback) { |
- BrowserThread::PostTask( |
- BrowserThread::IO, |
- FROM_HERE, |
- base::Bind(&CredentialsGetterHostClient::StartProcessOnIOThread, |
- new CredentialsGetterHostClient(), |
- network_guid, |
- public_key, |
- callback)); |
+ credentials_getter_ = new CredentialGetterWin(); |
+ credentials_getter_->SetCallbackRunner( |
+ content::BrowserThread::GetMessageLoopProxyForThread( |
+ content::BrowserThread::IO)); |
+ credentials_getter_->StartGetCredentials( |
+ network_guid, base::Bind(&OnGotCredentials, callback, public_key)); |
} |
NetworkingPrivateCredentialsGetterWin:: |