Index: chrome/browser/extensions/api/networking_private/wifi_passphrase_getter.cc |
diff --git a/chrome/browser/extensions/api/networking_private/wifi_passphrase_getter.cc b/chrome/browser/extensions/api/networking_private/wifi_passphrase_getter.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..006c6c907db0f3d8ccae9867bd652f2e99ba33b5 |
--- /dev/null |
+++ b/chrome/browser/extensions/api/networking_private/wifi_passphrase_getter.cc |
@@ -0,0 +1,102 @@ |
+// 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 { |
+ |
+WiFiPassphraseGetter::WiFiPassphraseGetter(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 WiFiPassphraseGetter::Start() { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
+ BrowserThread::PostTask( |
+ BrowserThread::IO, |
+ FROM_HERE, |
+ base::Bind(&WiFiPassphraseGetter::StartProcessOnIOThread, |
+ this, |
+ callback_id_, |
+ network_guid_, |
+ public_key_)); |
+} |
+ |
+WiFiPassphraseGetter::~WiFiPassphraseGetter() { |
+} |
+ |
+bool WiFiPassphraseGetter::OnMessageReceived(const IPC::Message& message) { |
+ bool handled = true; |
+ IPC_BEGIN_MESSAGE_MAP(WiFiPassphraseGetter, message) |
+ IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_GotEncryptedWiFiPassphrase, |
+ OnGotEncryptedWiFiPassphrase) |
+ IPC_MESSAGE_UNHANDLED(handled = false) |
+ IPC_END_MESSAGE_MAP() |
+ return handled; |
+} |
+ |
+void WiFiPassphraseGetter::OnProcessCrashed(int exit_code) { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
+ BrowserThread::PostTask( |
+ BrowserThread::UI, |
+ FROM_HERE, |
+ base::Bind( |
+ &WiFiPassphraseGetter::ReportEncryptedPassphraseOnUIThread, |
+ this, |
+ "", |
+ "Process Crashed")); |
+} |
+ |
+void WiFiPassphraseGetter::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 WiFiPassphraseGetter::OnGotEncryptedWiFiPassphrase( |
+ int32 callback_id, |
+ const std::string& passphrase, |
+ const std::string& error) { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
+ BrowserThread::PostTask( |
+ BrowserThread::UI, |
tbarzic
2014/02/07 19:25:00
instead of changing thread here, you can pass the
mef
2014/02/07 19:53:31
Hmm, I suppose I can store current message loop pr
tbarzic
2014/02/07 22:43:02
I think you can just pass it to StartProcessOnIOTh
mef
2014/02/11 23:20:04
Done. Start is called on the worker thread, but co
|
+ FROM_HERE, |
+ base::Bind( |
+ &WiFiPassphraseGetter::ReportEncryptedPassphraseOnUIThread, |
+ this, |
+ passphrase, |
+ error)); |
+} |
+ |
+void WiFiPassphraseGetter::ReportEncryptedPassphraseOnUIThread( |
+ const std::string& passphrase, |
+ const std::string& error) { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
+ if (!callback_.is_null()) |
+ callback_.Run(passphrase, error); |
+} |
+ |
+} // namespace extensions |