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.
5 #include "chrome/browser/local_discovery/wifi/credential_getter_win.h"
7 #include "chrome/common/extensions/chrome_utility_extensions_messages.h"
8 #include "content/public/browser/browser_thread.h"
9 #include "content/public/browser/utility_process_host.h"
11 namespace local_discovery
{
15 CredentialGetterWin::CredentialGetterWin() {
18 CredentialGetterWin::~CredentialGetterWin() {
21 void CredentialGetterWin::StartGetCredentials(
22 const std::string
& network_guid
,
23 const CredentialsCallback
& callback
) {
25 callback_runner_
= base::MessageLoopProxy::current();
26 content::BrowserThread::PostTask(
27 content::BrowserThread::IO
,
29 base::Bind(&CredentialGetterWin::StartOnIOThread
, this, network_guid
));
32 void CredentialGetterWin::StartOnIOThread(const std::string
& network_guid
) {
33 DCHECK_CURRENTLY_ON(content::BrowserThread::IO
);
34 content::UtilityProcessHost
* host
= content::UtilityProcessHost::Create(
35 this, base::MessageLoopProxy::current());
36 host
->ElevatePrivileges();
37 host
->Send(new ChromeUtilityHostMsg_GetWiFiCredentials(network_guid
));
40 bool CredentialGetterWin::OnMessageReceived(const IPC::Message
& message
) {
42 IPC_BEGIN_MESSAGE_MAP(CredentialGetterWin
, message
)
43 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_GotWiFiCredentials
, OnGotCredentials
)
44 IPC_MESSAGE_UNHANDLED(handled
= false)
49 void CredentialGetterWin::OnProcessCrashed(int exit_code
) {
50 PostCallback(false, "");
53 void CredentialGetterWin::OnProcessLaunchFailed() {
54 PostCallback(false, "");
57 void CredentialGetterWin::OnGotCredentials(const std::string
& key_data
,
59 PostCallback(success
, key_data
);
62 void CredentialGetterWin::PostCallback(bool success
,
63 const std::string
& key_data
) {
64 callback_runner_
->PostTask(FROM_HERE
,
65 base::Bind(callback_
, success
, key_data
));
69 } // namespace local_discovery