OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/local_discovery/wifi/credential_getter_win.h" |
| 6 #include "chrome/common/chrome_utility_messages.h" |
| 7 #include "content/public/browser/browser_thread.h" |
| 8 #include "content/public/browser/utility_process_host.h" |
| 9 |
| 10 namespace local_discovery { |
| 11 |
| 12 namespace wifi { |
| 13 |
| 14 CredentialGetterWin::CredentialGetterWin() { |
| 15 } |
| 16 |
| 17 CredentialGetterWin::~CredentialGetterWin() { |
| 18 } |
| 19 |
| 20 void CredentialGetterWin::StartGetCredentials( |
| 21 const std::string& network_guid, |
| 22 const CredentialsCallback& callback) { |
| 23 callback_ = callback; |
| 24 if (!callback_runner_) |
| 25 callback_runner_ = base::MessageLoopProxy::current(); |
| 26 content::BrowserThread::PostTask( |
| 27 content::BrowserThread::IO, |
| 28 FROM_HERE, |
| 29 base::Bind(&CredentialGetterWin::StartOnIOThread, this, network_guid)); |
| 30 } |
| 31 |
| 32 void CredentialGetterWin::SetCallbackRunner( |
| 33 const scoped_refptr<base::TaskRunner>& callback_runner) { |
| 34 callback_runner_ = callback_runner; |
| 35 } |
| 36 |
| 37 void CredentialGetterWin::StartOnIOThread(const std::string& network_guid) { |
| 38 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| 39 content::UtilityProcessHost* host = content::UtilityProcessHost::Create( |
| 40 this, base::MessageLoopProxy::current()); |
| 41 host->ElevatePrivileges(); |
| 42 host->Send(new ChromeUtilityHostMsg_GetWiFiCredentials(network_guid)); |
| 43 } |
| 44 |
| 45 bool CredentialGetterWin::OnMessageReceived(const IPC::Message& message) { |
| 46 bool handled = true; |
| 47 IPC_BEGIN_MESSAGE_MAP(CredentialGetterWin, message) |
| 48 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_GotWiFiCredentials, OnGotCredentials) |
| 49 IPC_MESSAGE_UNHANDLED(handled = false) |
| 50 IPC_END_MESSAGE_MAP() |
| 51 return handled; |
| 52 } |
| 53 |
| 54 void CredentialGetterWin::OnProcessCrashed(int exit_code) { |
| 55 PostCallback(false /* success */, "" /* no key data */); |
| 56 } |
| 57 |
| 58 void CredentialGetterWin::OnProcessLaunchFailed() { |
| 59 PostCallback(false /* success */, "" /* no key data */); |
| 60 } |
| 61 |
| 62 void CredentialGetterWin::OnGotCredentials(const std::string& key_data, |
| 63 bool success) { |
| 64 PostCallback(success, key_data); |
| 65 } |
| 66 |
| 67 void CredentialGetterWin::PostCallback(bool success, |
| 68 const std::string& key_data) { |
| 69 callback_runner_->PostTask(FROM_HERE, |
| 70 base::Bind(callback_, success, key_data)); |
| 71 } |
| 72 |
| 73 } // namespace wifi |
| 74 } // namespace local_discovery |
OLD | NEW |