Index: chrome/browser/extensions/api/networking_private/wifi_passphrase_getter_win.cc |
diff --git a/chrome/browser/extensions/api/networking_private/wifi_passphrase_getter_win.cc b/chrome/browser/extensions/api/networking_private/wifi_passphrase_getter_win.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..1e4fac1d4d73e78d67a5225769e6bdaf605958f6 |
--- /dev/null |
+++ b/chrome/browser/extensions/api/networking_private/wifi_passphrase_getter_win.cc |
@@ -0,0 +1,159 @@ |
+// 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/wifi_passphrase_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 WiFiPassphraseGetterWin : public content::UtilityProcessHostClient, |
+ public WiFiPassphraseGetter { |
+ public: |
+ typedef base::Callback<void(const std::string& passphrase, |
+ const std::string& error)> PassphraseCallback; |
+ |
+ WiFiPassphraseGetterWin(const PassphraseCallback& callback, |
+ int32 callback_id, |
+ const std::string& network_guid, |
+ const std::string& public_key); |
+ |
+ void Start(); |
+ |
+ private: |
+ friend class ProcessHostClient; |
+ |
+ virtual ~WiFiPassphraseGetterWin(); |
+ |
+ // Starts the utility process that gets wifi passphrase from |
+ void StartProcessOnIOThread(int32 callback_id, |
+ 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 OnGotEncryptedWiFiPassphrase(int32 callback_id, |
+ const std::string& passphrase, |
+ const std::string& error); |
+ |
+ void ReportEncryptedPassphraseOnUIThread(const std::string& passphrase, |
+ const std::string& error); |
+ |
+ // The callback. |
+ PassphraseCallback callback_; |
+ |
+ int32 callback_id_; |
+ std::string network_guid_; |
+ std::string public_key_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(WiFiPassphraseGetterWin); |
+}; |
+ |
+ |
+WiFiPassphraseGetterWin::WiFiPassphraseGetterWin(const PassphraseCallback& callback, |
+ int32 callback_id, |
+ const std::string& network_guid, |
+ const std::string& public_key) |
+ : callback_(callback), |
+ callback_id_(callback_id), |
+ network_guid_(network_guid), |
+ public_key_(public_key) { |
+} |
+ |
+void WiFiPassphraseGetterWin::Start() { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
+ BrowserThread::PostTask( |
+ BrowserThread::IO, |
+ FROM_HERE, |
+ base::Bind(&WiFiPassphraseGetterWin::StartProcessOnIOThread, |
+ this, |
+ callback_id_, |
+ network_guid_, |
+ public_key_)); |
+} |
+ |
+WiFiPassphraseGetterWin::~WiFiPassphraseGetterWin() { |
+} |
+ |
+bool WiFiPassphraseGetterWin::OnMessageReceived(const IPC::Message& message) { |
+ bool handled = true; |
+ IPC_BEGIN_MESSAGE_MAP(WiFiPassphraseGetterWin, message) |
+ IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_GotEncryptedWiFiPassphrase, |
+ OnGotEncryptedWiFiPassphrase) |
+ IPC_MESSAGE_UNHANDLED(handled = false) |
+ IPC_END_MESSAGE_MAP() |
+ return handled; |
+} |
+ |
+void WiFiPassphraseGetterWin::OnProcessCrashed(int exit_code) { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
+ BrowserThread::PostTask( |
+ BrowserThread::UI, |
+ FROM_HERE, |
+ base::Bind( |
+ &WiFiPassphraseGetterWin::ReportEncryptedPassphraseOnUIThread, |
+ this, |
+ "", |
+ "Process Crashed")); |
+} |
+ |
+void WiFiPassphraseGetterWin::StartProcessOnIOThread( |
+ int32 callback_id, |
+ 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_GetAndEncryptWiFiPassphrase( |
+ callback_id_, network_guid_, public_key_)); |
+} |
+ |
+void WiFiPassphraseGetterWin::OnGotEncryptedWiFiPassphrase( |
+ int32 callback_id, |
+ const std::string& passphrase, |
+ const std::string& error) { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
+ BrowserThread::PostTask( |
+ BrowserThread::UI, |
+ FROM_HERE, |
+ base::Bind( |
+ &WiFiPassphraseGetterWin::ReportEncryptedPassphraseOnUIThread, |
+ this, |
+ passphrase, |
+ error)); |
+} |
+ |
+void WiFiPassphraseGetterWin::ReportEncryptedPassphraseOnUIThread( |
+ const std::string& passphrase, |
+ const std::string& error) { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
+ if (!callback_.is_null()) |
+ callback_.Run(passphrase, error); |
+} |
+ |
+WiFiPassphraseGetter* WiFiPassphraseGetter::Create( |
+ const PassphraseCallback& callback, |
+ int32 callback_id, |
+ const std::string& network_guid, |
+ const std::string& public_key) { |
+ return new WiFiPassphraseGetterWin(callback, |
+ callback_id, |
+ network_guid, |
+ public_key); |
+} |
+ |
+} // namespace extensions |