Chromium Code Reviews| 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 |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..15e3af6d98730ba09d302aeba9fac9da54fbde4f |
| --- /dev/null |
| +++ b/chrome/browser/extensions/api/networking_private/networking_private_credentials_getter_win.cc |
| @@ -0,0 +1,146 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/extensions/api/networking_private/networking_private_credentials_getter.h" |
| + |
| +#include "base/bind.h" |
| +#include "base/memory/scoped_handle.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" |
| + |
| +using content::BrowserThread; |
| +using content::UtilityProcessHost; |
| +using extensions::NetworkingPrivateCredentialsGetter; |
| + |
| +namespace { |
| + |
| +class CredentialsGetterHostClient : public content::UtilityProcessHostClient { |
| + public: |
| + explicit 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::string& key_data, |
| + const std::string& error); |
| + |
| + // 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) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
|
tbarzic
2014/02/25 20:40:49
Please, consider calling the callback on the threa
mef
2014/02/25 22:36:26
I've tried that, but base::MessageLoopProxy::curre
tbarzic
2014/02/25 23:07:25
Hm, in that case, I'm ok with this.
|
| + callback_.Run("", "Process Crashed"); |
| +} |
| + |
| +void CredentialsGetterHostClient::OnProcessLaunchFailed() { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| + callback_.Run("", "Process Launch Failed"); |
| +} |
| + |
| +void CredentialsGetterHostClient::OnGotEncryptedCredentials( |
| + const std::string& key_data, |
| + const std::string& error) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| + callback_.Run(key_data, error); |
| +} |
| + |
| +void CredentialsGetterHostClient::StartProcessOnIOThread( |
| + const std::string& network_guid, |
| + const std::string& public_key, |
| + const extensions::NetworkingPrivateServiceClient::CryptoVerify:: |
| + VerifyAndEncryptCredentialsCallback& callback) |
| +{ |
|
tbarzic
2014/02/25 20:40:49
nit: { fits to the previous line
mef
2014/02/25 22:36:26
Done.
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| + UtilityProcessHost* host = UtilityProcessHost::Create( |
| + this, base::MessageLoopProxy::current()); |
| + callback_ = callback; |
| + host->ElevatePrivileges(); |
| + host->Send(new ChromeUtilityHostMsg_GetAndEncryptWiFiCredentials(network_guid, |
| + public_key)); |
| +} |
| + |
| +} // namespace |
| + |
| +namespace extensions { |
| + |
| +class NetworkingPrivateCredentialsGetterWin |
| + : public NetworkingPrivateCredentialsGetter { |
| + public: |
| + explicit NetworkingPrivateCredentialsGetterWin(); |
|
tbarzic
2014/02/25 20:40:49
you can remove explicit
mef
2014/02/25 22:36:26
Done.
|
| + |
| + virtual void Start( |
| + const std::string& network_guid, |
| + const std::string& public_key, |
| + const extensions::NetworkingPrivateServiceClient::CryptoVerify:: |
| + VerifyAndEncryptCredentialsCallback& callback) OVERRIDE; |
| + |
| + private: |
| + virtual ~NetworkingPrivateCredentialsGetterWin(); |
| + |
| + DISALLOW_COPY_AND_ASSIGN(NetworkingPrivateCredentialsGetterWin); |
| +}; |
| + |
| +NetworkingPrivateCredentialsGetterWin::NetworkingPrivateCredentialsGetterWin() { |
| +} |
| + |
| +void NetworkingPrivateCredentialsGetterWin::Start( |
| + const std::string& network_guid, |
| + const std::string& public_key, |
| + const extensions::NetworkingPrivateServiceClient::CryptoVerify:: |
| + VerifyAndEncryptCredentialsCallback& callback) { |
| + BrowserThread::PostTask( |
| + BrowserThread::IO, |
| + FROM_HERE, |
| + base::Bind(&CredentialsGetterHostClient::StartProcessOnIOThread, |
| + new CredentialsGetterHostClient(), |
| + network_guid, |
| + public_key, |
| + callback)); |
| +} |
| + |
| +NetworkingPrivateCredentialsGetterWin:: |
| + ~NetworkingPrivateCredentialsGetterWin() {} |
| + |
| +NetworkingPrivateCredentialsGetter* NetworkingPrivateCredentialsGetter:: |
| + Create() { |
| + return new NetworkingPrivateCredentialsGetterWin(); |
| +} |
| + |
| +} // namespace extensions |
| + |