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

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

Issue 10440107: Replace ScopedThreadProxy with MessageLoopProxy & WeakPtrs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use correct TaskRunner reference, and copy instance reference in lock. 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
« no previous file with comments | « remoting/host/host_user_interface.h ('k') | remoting/host/it2me_host_user_interface.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 } 21 }
21 22
22 HostUserInterface::~HostUserInterface() { 23 HostUserInterface::~HostUserInterface() {
23 DCHECK(ui_message_loop()->BelongsToCurrentThread()); 24 DCHECK(ui_message_loop()->BelongsToCurrentThread());
24 25
25 MonitorLocalInputs(false); 26 MonitorLocalInputs(false);
26 ShowDisconnectWindow(false, std::string()); 27 ShowDisconnectWindow(false, std::string());
27
28 ui_thread_proxy_.Detach();
29 } 28 }
30 29
31 void HostUserInterface::Start(ChromotingHost* host, 30 void HostUserInterface::Start(ChromotingHost* host,
32 const base::Closure& disconnect_callback) { 31 const base::Closure& disconnect_callback) {
33 DCHECK(network_message_loop()->BelongsToCurrentThread()); 32 DCHECK(network_message_loop()->BelongsToCurrentThread());
34 DCHECK(host_ == NULL); 33 DCHECK(host_ == NULL);
35 DCHECK(disconnect_callback_.is_null()); 34 DCHECK(disconnect_callback_.is_null());
36 35
37 host_ = host; 36 host_ = host;
38 disconnect_callback_ = disconnect_callback; 37 disconnect_callback_ = disconnect_callback;
39 disconnect_window_ = DisconnectWindow::Create(); 38 disconnect_window_ = DisconnectWindow::Create();
40 local_input_monitor_ = LocalInputMonitor::Create(); 39 local_input_monitor_ = LocalInputMonitor::Create();
41 host_->AddStatusObserver(this); 40 host_->AddStatusObserver(this);
42 } 41 }
43 42
44 void HostUserInterface::OnClientAuthenticated(const std::string& jid) { 43 void HostUserInterface::OnClientAuthenticated(const std::string& jid) {
44 DCHECK(network_message_loop()->BelongsToCurrentThread());
45
45 authenticated_jid_ = jid; 46 authenticated_jid_ = jid;
46 47
47 std::string username = jid.substr(0, jid.find('/')); 48 std::string username = jid.substr(0, jid.find('/'));
48 ui_thread_proxy_.PostTask(FROM_HERE, base::Bind( 49 ui_message_loop()->PostTask(FROM_HERE, base::Bind(
49 &HostUserInterface::ProcessOnClientAuthenticated, 50 &HostUserInterface::ProcessOnClientAuthenticated,
50 base::Unretained(this), username)); 51 weak_ptr_, username));
51 } 52 }
52 53
53 void HostUserInterface::OnClientDisconnected(const std::string& jid) { 54 void HostUserInterface::OnClientDisconnected(const std::string& jid) {
55 DCHECK(network_message_loop()->BelongsToCurrentThread());
56
54 if (jid == authenticated_jid_) { 57 if (jid == authenticated_jid_) {
55 ui_thread_proxy_.PostTask(FROM_HERE, base::Bind( 58 ui_message_loop()->PostTask(FROM_HERE, base::Bind(
56 &HostUserInterface::ProcessOnClientDisconnected, 59 &HostUserInterface::ProcessOnClientDisconnected,
57 base::Unretained(this))); 60 weak_ptr_));
58 } 61 }
59 } 62 }
60 63
61 void HostUserInterface::OnAccessDenied(const std::string& jid) { 64 void HostUserInterface::OnAccessDenied(const std::string& jid) {
62 } 65 }
63 66
64 void HostUserInterface::OnShutdown() { 67 void HostUserInterface::OnShutdown() {
68 DCHECK(network_message_loop()->BelongsToCurrentThread());
69
65 // Host status observers must be removed on the network thread, so 70 // Host status observers must be removed on the network thread, so
66 // it must happen here instead of in the destructor. 71 // it must happen here instead of in the destructor.
67 host_->RemoveStatusObserver(this); 72 host_->RemoveStatusObserver(this);
68 host_ = NULL; 73 host_ = NULL;
69 disconnect_callback_ = base::Closure();
70 } 74 }
71 75
72 void HostUserInterface::OnDisconnectCallback() { 76 void HostUserInterface::OnDisconnectCallback() {
73 DCHECK(ui_message_loop()->BelongsToCurrentThread()); 77 DCHECK(ui_message_loop()->BelongsToCurrentThread());
74 DCHECK(!disconnect_callback_.is_null());
75 78
76 MonitorLocalInputs(false); 79 MonitorLocalInputs(false);
77 ShowDisconnectWindow(false, std::string()); 80 ShowDisconnectWindow(false, std::string());
78 disconnect_callback_.Run(); 81 DisconnectSession();
79 } 82 }
80 83
81 base::MessageLoopProxy* HostUserInterface::network_message_loop() const { 84 base::MessageLoopProxy* HostUserInterface::network_message_loop() const {
82 return context_->network_message_loop(); 85 return context_->network_message_loop();
83 } 86 }
84 base::MessageLoopProxy* HostUserInterface::ui_message_loop() const { 87 base::MessageLoopProxy* HostUserInterface::ui_message_loop() const {
85 return context_->ui_message_loop(); 88 return context_->ui_message_loop();
86 } 89 }
87 90
88 void HostUserInterface::DisconnectSession() const { 91 void HostUserInterface::DisconnectSession() const {
89 return disconnect_callback_.Run(); 92 DCHECK(ui_message_loop()->BelongsToCurrentThread());
93 DCHECK(!disconnect_callback_.is_null());
94
95 disconnect_callback_.Run();
90 } 96 }
91 97
92 void HostUserInterface::ProcessOnClientAuthenticated( 98 void HostUserInterface::ProcessOnClientAuthenticated(
93 const std::string& username) { 99 const std::string& username) {
94 DCHECK(ui_message_loop()->BelongsToCurrentThread()); 100 DCHECK(ui_message_loop()->BelongsToCurrentThread());
95 101
96 MonitorLocalInputs(true); 102 MonitorLocalInputs(true);
97 ShowDisconnectWindow(true, username); 103 ShowDisconnectWindow(true, username);
98 } 104 }
99 105
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 } 139 }
134 140
135 void HostUserInterface::ShowDisconnectWindow(bool show, 141 void HostUserInterface::ShowDisconnectWindow(bool show,
136 const std::string& username) { 142 const std::string& username) {
137 DCHECK(ui_message_loop()->BelongsToCurrentThread()); 143 DCHECK(ui_message_loop()->BelongsToCurrentThread());
138 144
139 if (show) { 145 if (show) {
140 disconnect_window_->Show( 146 disconnect_window_->Show(
141 host_, 147 host_,
142 base::Bind(&HostUserInterface::OnDisconnectCallback, 148 base::Bind(&HostUserInterface::OnDisconnectCallback,
143 base::Unretained(this)), 149 weak_ptr_),
144 username); 150 username);
145 } else { 151 } else {
146 disconnect_window_->Hide(); 152 disconnect_window_->Hide();
147 } 153 }
148 } 154 }
149 155
150 } // namespace remoting 156 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/host_user_interface.h ('k') | remoting/host/it2me_host_user_interface.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698