| 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..0aa1edddba7dff8556bd72741d31ae13d2e5191b
|
| --- /dev/null
|
| +++ b/chrome/browser/extensions/api/networking_private/networking_private_credentials_getter_win.cc
|
| @@ -0,0 +1,141 @@
|
| +// 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:
|
| + 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) {
|
| + callback_.Run("", "Process Crashed");
|
| +}
|
| +
|
| +void CredentialsGetterHostClient::OnProcessLaunchFailed() {
|
| + callback_.Run("", "Process Launch Failed");
|
| +}
|
| +
|
| +void CredentialsGetterHostClient::OnGotEncryptedCredentials(
|
| + const std::string& key_data,
|
| + const std::string& error) {
|
| + callback_.Run(key_data, error);
|
| +}
|
| +
|
| +void CredentialsGetterHostClient::StartProcessOnIOThread(
|
| + const std::string& network_guid,
|
| + const std::string& public_key,
|
| + const extensions::NetworkingPrivateServiceClient::CryptoVerify::
|
| + VerifyAndEncryptCredentialsCallback& callback) {
|
| + 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:
|
| + NetworkingPrivateCredentialsGetterWin();
|
| +
|
| + 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
|
|
|