Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / chrome / browser / local_discovery / wifi / credential_getter_win.cc
blob2730fca37192f105adaabe9341bc02039d4b602e
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 "base/thread_task_runner_handle.h"
8 #include "chrome/common/extensions/chrome_utility_extensions_messages.h"
9 #include "chrome/grit/generated_resources.h"
10 #include "content/public/browser/browser_thread.h"
11 #include "content/public/browser/utility_process_host.h"
12 #include "ui/base/l10n/l10n_util.h"
14 namespace local_discovery {
16 namespace wifi {
18 CredentialGetterWin::CredentialGetterWin() {
21 void CredentialGetterWin::StartGetCredentials(
22 const std::string& network_guid,
23 const CredentialsCallback& callback) {
24 callback_ = callback;
25 callback_runner_ = base::ThreadTaskRunnerHandle::Get();
26 content::BrowserThread::PostTask(
27 content::BrowserThread::IO,
28 FROM_HERE,
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::ThreadTaskRunnerHandle::Get());
36 host->SetName(l10n_util::GetStringUTF16(
37 IDS_UTILITY_PROCESS_WIFI_CREDENTIALS_GETTER_NAME));
38 host->ElevatePrivileges();
39 host->Send(new ChromeUtilityHostMsg_GetWiFiCredentials(network_guid));
42 CredentialGetterWin::~CredentialGetterWin() {
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;
54 void CredentialGetterWin::OnProcessCrashed(int exit_code) {
55 PostCallback(false, "");
58 void CredentialGetterWin::OnProcessLaunchFailed() {
59 PostCallback(false, "");
62 void CredentialGetterWin::OnGotCredentials(const std::string& key_data,
63 bool success) {
64 PostCallback(success, key_data);
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));
73 } // namespace wifi
74 } // namespace local_discovery