Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(125)

Side by Side Diff: chrome/browser/extensions/api/networking_private/wifi_passphrase_getter_win.cc

Issue 102993002: Implement Networking Private API VerifyAndEncryptCredentials method (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Implement GetWiFiPasswordFromSystem on Mac. Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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/extensions/api/networking_private/wifi_passphrase_gette r.h"
6
7 #include "base/bind.h"
8 #include "base/memory/scoped_handle.h"
9 #include "base/message_loop/message_loop.h"
10 #include "base/threading/sequenced_worker_pool.h"
11 #include "chrome/common/chrome_utility_messages.h"
12 #include "content/public/browser/browser_thread.h"
13 #include "content/public/browser/utility_process_host.h"
14
15 using content::BrowserThread;
16 using content::UtilityProcessHost;
17
18 namespace extensions {
19
20 class WiFiPassphraseGetterWin : public content::UtilityProcessHostClient,
21 public WiFiPassphraseGetter {
22 public:
23 typedef base::Callback<void(const std::string& passphrase,
24 const std::string& error)> PassphraseCallback;
25
26 WiFiPassphraseGetterWin(const PassphraseCallback& callback,
27 int32 callback_id,
28 const std::string& network_guid,
29 const std::string& public_key);
30
31 void Start();
32
33 private:
34 friend class ProcessHostClient;
35
36 virtual ~WiFiPassphraseGetterWin();
37
38 // Starts the utility process that gets wifi passphrase from
39 void StartProcessOnIOThread(int32 callback_id,
40 const std::string& network_guid,
41 const std::string& public_key);
42
43 // UtilityProcessHostClient
44 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
45 virtual void OnProcessCrashed(int exit_code) OVERRIDE;
46
47 // IPC message handlers.
48 void OnGotEncryptedWiFiPassphrase(int32 callback_id,
49 const std::string& passphrase,
50 const std::string& error);
51
52 void ReportEncryptedPassphraseOnUIThread(const std::string& passphrase,
53 const std::string& error);
54
55 // The callback.
56 PassphraseCallback callback_;
57
58 int32 callback_id_;
59 std::string network_guid_;
60 std::string public_key_;
61
62 DISALLOW_COPY_AND_ASSIGN(WiFiPassphraseGetterWin);
63 };
64
65
66 WiFiPassphraseGetterWin::WiFiPassphraseGetterWin(const PassphraseCallback& callb ack,
67 int32 callback_id,
68 const std::string& network_guid,
69 const std::string& public_key)
70 : callback_(callback),
71 callback_id_(callback_id),
72 network_guid_(network_guid),
73 public_key_(public_key) {
74 }
75
76 void WiFiPassphraseGetterWin::Start() {
77 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
78 BrowserThread::PostTask(
79 BrowserThread::IO,
80 FROM_HERE,
81 base::Bind(&WiFiPassphraseGetterWin::StartProcessOnIOThread,
82 this,
83 callback_id_,
84 network_guid_,
85 public_key_));
86 }
87
88 WiFiPassphraseGetterWin::~WiFiPassphraseGetterWin() {
89 }
90
91 bool WiFiPassphraseGetterWin::OnMessageReceived(const IPC::Message& message) {
92 bool handled = true;
93 IPC_BEGIN_MESSAGE_MAP(WiFiPassphraseGetterWin, message)
94 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_GotEncryptedWiFiPassphrase,
95 OnGotEncryptedWiFiPassphrase)
96 IPC_MESSAGE_UNHANDLED(handled = false)
97 IPC_END_MESSAGE_MAP()
98 return handled;
99 }
100
101 void WiFiPassphraseGetterWin::OnProcessCrashed(int exit_code) {
102 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
103 BrowserThread::PostTask(
104 BrowserThread::UI,
105 FROM_HERE,
106 base::Bind(
107 &WiFiPassphraseGetterWin::ReportEncryptedPassphraseOnUIThread,
108 this,
109 "",
110 "Process Crashed"));
111 }
112
113 void WiFiPassphraseGetterWin::StartProcessOnIOThread(
114 int32 callback_id,
115 const std::string& network_guid,
116 const std::string& public_key) {
117 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
118 UtilityProcessHost* host = UtilityProcessHost::Create(
119 this,
120 base::MessageLoopProxy::current().get());
121 host->Send(new ChromeUtilityHostMsg_GetAndEncryptWiFiPassphrase(
122 callback_id_, network_guid_, public_key_));
123 }
124
125 void WiFiPassphraseGetterWin::OnGotEncryptedWiFiPassphrase(
126 int32 callback_id,
127 const std::string& passphrase,
128 const std::string& error) {
129 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
130 BrowserThread::PostTask(
131 BrowserThread::UI,
132 FROM_HERE,
133 base::Bind(
134 &WiFiPassphraseGetterWin::ReportEncryptedPassphraseOnUIThread,
135 this,
136 passphrase,
137 error));
138 }
139
140 void WiFiPassphraseGetterWin::ReportEncryptedPassphraseOnUIThread(
141 const std::string& passphrase,
142 const std::string& error) {
143 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
144 if (!callback_.is_null())
145 callback_.Run(passphrase, error);
146 }
147
148 WiFiPassphraseGetter* WiFiPassphraseGetter::Create(
149 const PassphraseCallback& callback,
150 int32 callback_id,
151 const std::string& network_guid,
152 const std::string& public_key) {
153 return new WiFiPassphraseGetterWin(callback,
154 callback_id,
155 network_guid,
156 public_key);
157 }
158
159 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698