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

Side by Side Diff: remoting/host/host_user_interface.cc

Issue 10454040: Replace ScopedThreadProxy with MessageLoopProxy & WeakPtrs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "remoting/host/host_user_interface.h" 5 #include "remoting/host/host_user_interface.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "remoting/host/chromoting_host.h" 8 #include "remoting/host/chromoting_host.h"
9 #include "remoting/host/chromoting_host_context.h" 9 #include "remoting/host/chromoting_host_context.h"
10 #include "remoting/host/disconnect_window.h" 10 #include "remoting/host/disconnect_window.h"
11 #include "remoting/host/local_input_monitor.h" 11 #include "remoting/host/local_input_monitor.h"
12 12
13 namespace remoting { 13 namespace remoting {
14 14
15 HostUserInterface::HostUserInterface(ChromotingHostContext* context) 15 HostUserInterface::HostUserInterface(ChromotingHostContext* context)
16 : host_(NULL), 16 : host_(NULL),
17 context_(context), 17 context_(context),
18 is_monitoring_local_inputs_(false), 18 is_monitoring_local_inputs_(false),
19 ui_thread_proxy_(context->ui_message_loop()), 19 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)),
20 weak_ptr_(weak_factory_.GetWeakPtr()),
20 disable_disconnect_shortcut_on_mac_(false) { 21 disable_disconnect_shortcut_on_mac_(false) {
21 } 22 }
22 23
23 HostUserInterface::~HostUserInterface() { 24 HostUserInterface::~HostUserInterface() {
24 DCHECK(ui_message_loop()->BelongsToCurrentThread()); 25 DCHECK(ui_message_loop()->BelongsToCurrentThread());
25 26
26 MonitorLocalInputs(false); 27 MonitorLocalInputs(false);
27 ShowDisconnectWindow(false, std::string()); 28 ShowDisconnectWindow(false, std::string());
28
29 ui_thread_proxy_.Detach();
30 } 29 }
31 30
32 void HostUserInterface::Start(ChromotingHost* host, 31 void HostUserInterface::Start(ChromotingHost* host,
33 const base::Closure& disconnect_callback) { 32 const base::Closure& disconnect_callback) {
34 DCHECK(network_message_loop()->BelongsToCurrentThread()); 33 DCHECK(network_message_loop()->BelongsToCurrentThread());
35 DCHECK(host_ == NULL); 34 DCHECK(host_ == NULL);
36 DCHECK(disconnect_callback_.is_null()); 35 DCHECK(disconnect_callback_.is_null());
37 36
38 host_ = host; 37 host_ = host;
39 disconnect_callback_ = disconnect_callback; 38 disconnect_callback_ = disconnect_callback;
40 disconnect_window_ = DisconnectWindow::Create(); 39 disconnect_window_ = DisconnectWindow::Create();
41 local_input_monitor_ = LocalInputMonitor::Create(); 40 local_input_monitor_ = LocalInputMonitor::Create();
42 host_->AddStatusObserver(this); 41 host_->AddStatusObserver(this);
43 } 42 }
44 43
45 void HostUserInterface::DisableDisconnectShortcutOnMac() { 44 void HostUserInterface::DisableDisconnectShortcutOnMac() {
46 disable_disconnect_shortcut_on_mac_ = true; 45 disable_disconnect_shortcut_on_mac_ = true;
47 } 46 }
48 47
49 void HostUserInterface::OnClientAuthenticated(const std::string& jid) { 48 void HostUserInterface::OnClientAuthenticated(const std::string& jid) {
49 DCHECK(network_message_loop()->BelongsToCurrentThread());
50
50 authenticated_jid_ = jid; 51 authenticated_jid_ = jid;
51 52
52 std::string username = jid.substr(0, jid.find('/')); 53 std::string username = jid.substr(0, jid.find('/'));
53 ui_thread_proxy_.PostTask(FROM_HERE, base::Bind( 54 ui_message_loop()->PostTask(FROM_HERE, base::Bind(
54 &HostUserInterface::ProcessOnClientAuthenticated, 55 &HostUserInterface::ProcessOnClientAuthenticated,
55 base::Unretained(this), username)); 56 weak_ptr_, username));
56 } 57 }
57 58
58 void HostUserInterface::OnClientDisconnected(const std::string& jid) { 59 void HostUserInterface::OnClientDisconnected(const std::string& jid) {
60 DCHECK(network_message_loop()->BelongsToCurrentThread());
61
59 if (jid == authenticated_jid_) { 62 if (jid == authenticated_jid_) {
60 ui_thread_proxy_.PostTask(FROM_HERE, base::Bind( 63 ui_message_loop()->PostTask(FROM_HERE, base::Bind(
61 &HostUserInterface::ProcessOnClientDisconnected, 64 &HostUserInterface::ProcessOnClientDisconnected,
62 base::Unretained(this))); 65 weak_ptr_));
63 } 66 }
64 } 67 }
65 68
66 void HostUserInterface::OnAccessDenied(const std::string& jid) { 69 void HostUserInterface::OnAccessDenied(const std::string& jid) {
67 } 70 }
68 71
69 void HostUserInterface::OnShutdown() { 72 void HostUserInterface::OnShutdown() {
73 DCHECK(network_message_loop()->BelongsToCurrentThread());
74
70 // Host status observers must be removed on the network thread, so 75 // Host status observers must be removed on the network thread, so
71 // it must happen here instead of in the destructor. 76 // it must happen here instead of in the destructor.
72 host_->RemoveStatusObserver(this); 77 host_->RemoveStatusObserver(this);
73 host_ = NULL; 78 host_ = NULL;
79
80 // TODO(wez): This isn't safe, since the callback gets called on UI thread.
Sergey Ulanov 2012/05/29 18:58:30 I think we can just remove this line. The disconne
Wez 2012/05/30 00:18:39 Done. Not sure whether the intent was that Start(
74 disconnect_callback_ = base::Closure(); 81 disconnect_callback_ = base::Closure();
75 } 82 }
76 83
77 void HostUserInterface::OnDisconnectCallback() { 84 void HostUserInterface::OnDisconnectCallback() {
78 DCHECK(ui_message_loop()->BelongsToCurrentThread()); 85 DCHECK(ui_message_loop()->BelongsToCurrentThread());
79 DCHECK(!disconnect_callback_.is_null());
80 86
81 MonitorLocalInputs(false); 87 MonitorLocalInputs(false);
82 ShowDisconnectWindow(false, std::string()); 88 ShowDisconnectWindow(false, std::string());
83 disconnect_callback_.Run(); 89 DisconnectSession();
Sergey Ulanov 2012/05/29 18:58:30 Do we need DisconnectSession() method at all?
Wez 2012/05/30 00:18:39 It's used by It2MeHostUserInterface when the Disco
84 } 90 }
85 91
86 base::MessageLoopProxy* HostUserInterface::network_message_loop() const { 92 base::MessageLoopProxy* HostUserInterface::network_message_loop() const {
87 return context_->network_message_loop(); 93 return context_->network_message_loop();
88 } 94 }
89 base::MessageLoopProxy* HostUserInterface::ui_message_loop() const { 95 base::MessageLoopProxy* HostUserInterface::ui_message_loop() const {
90 return context_->ui_message_loop(); 96 return context_->ui_message_loop();
91 } 97 }
92 98
93 void HostUserInterface::DisconnectSession() const { 99 void HostUserInterface::DisconnectSession() const {
94 return disconnect_callback_.Run(); 100 DCHECK(ui_message_loop()->BelongsToCurrentThread());
101 DCHECK(!disconnect_callback_.is_null());
102
103 disconnect_callback_.Run();
95 } 104 }
96 105
97 void HostUserInterface::ProcessOnClientAuthenticated( 106 void HostUserInterface::ProcessOnClientAuthenticated(
98 const std::string& username) { 107 const std::string& username) {
99 DCHECK(ui_message_loop()->BelongsToCurrentThread()); 108 DCHECK(ui_message_loop()->BelongsToCurrentThread());
100 109
101 MonitorLocalInputs(true); 110 MonitorLocalInputs(true);
102 ShowDisconnectWindow(true, username); 111 ShowDisconnectWindow(true, username);
103 } 112 }
104 113
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 } 150 }
142 151
143 void HostUserInterface::ShowDisconnectWindow(bool show, 152 void HostUserInterface::ShowDisconnectWindow(bool show,
144 const std::string& username) { 153 const std::string& username) {
145 DCHECK(ui_message_loop()->BelongsToCurrentThread()); 154 DCHECK(ui_message_loop()->BelongsToCurrentThread());
146 155
147 if (show) { 156 if (show) {
148 disconnect_window_->Show( 157 disconnect_window_->Show(
149 host_, 158 host_,
150 base::Bind(&HostUserInterface::OnDisconnectCallback, 159 base::Bind(&HostUserInterface::OnDisconnectCallback,
151 base::Unretained(this)), 160 weak_ptr_),
152 username); 161 username);
153 } else { 162 } else {
154 disconnect_window_->Hide(); 163 disconnect_window_->Hide();
155 } 164 }
156 } 165 }
157 166
158 } // namespace remoting 167 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698