Add GCMChannelStatusSyncer to schedule requests and enable/disable GCM
[chromium-blink-merge.git] / chrome / browser / local_discovery / wifi / credential_getter_win.cc
blobfdd0052ec6b67c71b7bbd89529f8065caff8a416
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 {
13 namespace wifi {
15 CredentialGetterWin::CredentialGetterWin() {
18 CredentialGetterWin::~CredentialGetterWin() {
21 void CredentialGetterWin::StartGetCredentials(
22 const std::string& network_guid,
23 const CredentialsCallback& callback) {
24 callback_ = callback;
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));
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) {
41 bool handled = true;
42 IPC_BEGIN_MESSAGE_MAP(CredentialGetterWin, message)
43 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_GotWiFiCredentials, OnGotCredentials)
44 IPC_MESSAGE_UNHANDLED(handled = false)
45 IPC_END_MESSAGE_MAP()
46 return handled;
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,
58 bool success) {
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));
68 } // namespace wifi
69 } // namespace local_discovery