| 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..5b92db7e370d81f87ee87a9feb38838ce78b9495
|
| --- /dev/null
|
| +++ b/chrome/browser/extensions/api/networking_private/networking_private_credentials_getter_win.cc
|
| @@ -0,0 +1,125 @@
|
| +// 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;
|
| +
|
| +namespace extensions {
|
| +
|
| +class NetworkingPrivateCredentialsGetterWin
|
| + : public content::UtilityProcessHostClient,
|
| + public NetworkingPrivateCredentialsGetter {
|
| + public:
|
| + explicit NetworkingPrivateCredentialsGetterWin(
|
| + const GetCredentialsCallback& callback);
|
| +
|
| + virtual void Start(const std::string& network_guid,
|
| + const std::string& public_key) OVERRIDE;
|
| +
|
| + virtual void ReportResult(const std::string& key_data,
|
| + const std::string& error) OVERRIDE;
|
| + private:
|
| + friend class ProcessHostClient;
|
| +
|
| + virtual ~NetworkingPrivateCredentialsGetterWin();
|
| +
|
| + // Starts the utility process that gets wifi passphrase from system.
|
| + void StartProcessOnIOThread(const std::string& network_guid,
|
| + const std::string& public_key);
|
| +
|
| + // UtilityProcessHostClient
|
| + virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
|
| + virtual void OnProcessCrashed(int exit_code) OVERRIDE;
|
| +
|
| + // IPC message handlers.
|
| + void OnGotEncryptedCredentials(const std::string& key_data,
|
| + const std::string& error);
|
| +
|
| +
|
| + // The callback.
|
| + GetCredentialsCallback callback_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(NetworkingPrivateCredentialsGetterWin);
|
| +};
|
| +
|
| +NetworkingPrivateCredentialsGetterWin::NetworkingPrivateCredentialsGetterWin(
|
| + const GetCredentialsCallback& callback) : callback_(callback) {
|
| +}
|
| +
|
| +void NetworkingPrivateCredentialsGetterWin::Start(
|
| + const std::string& network_guid,
|
| + const std::string& public_key) {
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| + BrowserThread::PostTask(
|
| + BrowserThread::IO,
|
| + FROM_HERE,
|
| + base::Bind(&NetworkingPrivateCredentialsGetterWin::StartProcessOnIOThread,
|
| + this,
|
| + network_guid,
|
| + public_key));
|
| +}
|
| +
|
| +NetworkingPrivateCredentialsGetterWin::~NetworkingPrivateCredentialsGetterWin()
|
| +{ }
|
| +
|
| +bool NetworkingPrivateCredentialsGetterWin::OnMessageReceived(
|
| + const IPC::Message& message) {
|
| + bool handled = true;
|
| + IPC_BEGIN_MESSAGE_MAP(NetworkingPrivateCredentialsGetterWin, message)
|
| + IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_GotEncryptedWiFiCredentials,
|
| + OnGotEncryptedCredentials)
|
| + IPC_MESSAGE_UNHANDLED(handled = false)
|
| + IPC_END_MESSAGE_MAP()
|
| + return handled;
|
| +}
|
| +
|
| +void NetworkingPrivateCredentialsGetterWin::OnProcessCrashed(int exit_code) {
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
|
| + ReportResult("", "Process Crashed");
|
| +}
|
| +
|
| +void NetworkingPrivateCredentialsGetterWin::StartProcessOnIOThread(
|
| + const std::string& network_guid,
|
| + const std::string& public_key) {
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
|
| + UtilityProcessHost* host = UtilityProcessHost::Create(
|
| + this,
|
| + base::MessageLoopProxy::current().get());
|
| + host->Send(new ChromeUtilityHostMsg_GetAndEncryptWiFiCredentials(
|
| + network_guid, public_key));
|
| +}
|
| +
|
| +void NetworkingPrivateCredentialsGetterWin::OnGotEncryptedCredentials(
|
| + const std::string& key_data,
|
| + const std::string& error) {
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
|
| + ReportResult(key_data, error);
|
| +}
|
| +
|
| +void NetworkingPrivateCredentialsGetterWin::ReportResult(
|
| + const std::string& key_data,
|
| + const std::string& error) {
|
| + if (!callback_.is_null()) {
|
| + BrowserThread::PostTask(BrowserThread::UI,
|
| + FROM_HERE,
|
| + base::Bind(callback_, key_data, error));
|
| + }
|
| +}
|
| +
|
| +NetworkingPrivateCredentialsGetter* NetworkingPrivateCredentialsGetter::Create(
|
| + const GetCredentialsCallback& callback) {
|
| + return new NetworkingPrivateCredentialsGetterWin(callback);
|
| +}
|
| +
|
| +} // namespace extensions
|
|
|