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/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 WiFiPassphraseGetter::WiFiPassphraseGetter(const PassphraseCallback& callback, | |
21 int32 callback_id, | |
22 const std::string& network_guid, | |
23 const std::string& public_key) | |
24 : callback_(callback), | |
25 callback_id_(callback_id), | |
26 network_guid_(network_guid), | |
27 public_key_(public_key) { | |
28 } | |
29 | |
30 void WiFiPassphraseGetter::Start() { | |
31 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
32 BrowserThread::PostTask( | |
33 BrowserThread::IO, | |
34 FROM_HERE, | |
35 base::Bind(&WiFiPassphraseGetter::StartProcessOnIOThread, | |
36 this, | |
37 callback_id_, | |
38 network_guid_, | |
39 public_key_)); | |
40 } | |
41 | |
42 WiFiPassphraseGetter::~WiFiPassphraseGetter() { | |
43 } | |
44 | |
45 bool WiFiPassphraseGetter::OnMessageReceived(const IPC::Message& message) { | |
46 bool handled = true; | |
47 IPC_BEGIN_MESSAGE_MAP(WiFiPassphraseGetter, message) | |
48 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_GotEncryptedWiFiPassphrase, | |
49 OnGotEncryptedWiFiPassphrase) | |
50 IPC_MESSAGE_UNHANDLED(handled = false) | |
51 IPC_END_MESSAGE_MAP() | |
52 return handled; | |
53 } | |
54 | |
55 void WiFiPassphraseGetter::OnProcessCrashed(int exit_code) { | |
56 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
57 BrowserThread::PostTask( | |
58 BrowserThread::UI, | |
59 FROM_HERE, | |
60 base::Bind( | |
61 &WiFiPassphraseGetter::ReportEncryptedPassphraseOnUIThread, | |
62 this, | |
63 "", | |
64 "Process Crashed")); | |
65 } | |
66 | |
67 void WiFiPassphraseGetter::StartProcessOnIOThread( | |
68 int32 callback_id, | |
69 const std::string& network_guid, | |
70 const std::string& public_key) { | |
71 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
72 UtilityProcessHost* host = UtilityProcessHost::Create( | |
73 this, | |
74 base::MessageLoopProxy::current().get()); | |
75 host->Send(new ChromeUtilityHostMsg_GetAndEncryptWiFiPassphrase( | |
76 callback_id_, network_guid_, public_key_)); | |
77 } | |
78 | |
79 void WiFiPassphraseGetter::OnGotEncryptedWiFiPassphrase( | |
80 int32 callback_id, | |
81 const std::string& passphrase, | |
82 const std::string& error) { | |
83 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
84 BrowserThread::PostTask( | |
85 BrowserThread::UI, | |
tbarzic
2014/02/07 19:25:00
instead of changing thread here, you can pass the
mef
2014/02/07 19:53:31
Hmm, I suppose I can store current message loop pr
tbarzic
2014/02/07 22:43:02
I think you can just pass it to StartProcessOnIOTh
mef
2014/02/11 23:20:04
Done. Start is called on the worker thread, but co
| |
86 FROM_HERE, | |
87 base::Bind( | |
88 &WiFiPassphraseGetter::ReportEncryptedPassphraseOnUIThread, | |
89 this, | |
90 passphrase, | |
91 error)); | |
92 } | |
93 | |
94 void WiFiPassphraseGetter::ReportEncryptedPassphraseOnUIThread( | |
95 const std::string& passphrase, | |
96 const std::string& error) { | |
97 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
98 if (!callback_.is_null()) | |
99 callback_.Run(passphrase, error); | |
100 } | |
101 | |
102 } // namespace extensions | |
OLD | NEW |