OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef REMOTING_HOST_HOST_USER_INTERFACE_H_ | |
6 #define REMOTING_HOST_HOST_USER_INTERFACE_H_ | |
7 | |
8 #include <string> | |
9 | |
10 #include "base/basictypes.h" | |
11 #include "base/callback.h" | |
12 #include "base/compiler_specific.h" | |
13 #include "base/memory/ref_counted.h" | |
14 #include "base/memory/scoped_ptr.h" | |
15 #include "base/memory/weak_ptr.h" | |
16 #include "remoting/host/host_status_observer.h" | |
17 #include "remoting/host/ui_strings.h" | |
18 | |
19 namespace base { | |
20 class SingleThreadTaskRunner; | |
21 } // namespace base | |
22 | |
23 namespace remoting { | |
24 | |
25 class ChromotingHost; | |
26 | |
27 class HostUserInterface : public HostStatusObserver { | |
28 public: | |
29 HostUserInterface( | |
30 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner, | |
31 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, | |
32 const UiStrings& ui_strings); | |
33 virtual ~HostUserInterface(); | |
34 | |
35 // Initialize the OS-specific UI objects. | |
36 // Init must be called from |ui_task_runner_|. | |
37 virtual void Init(); | |
38 | |
39 // Start the HostUserInterface for |host|. |disconnect_callback| will be | |
40 // called on |ui_task_runner| to notify the caller that the connection should | |
41 // be disconnected. |host| must remain valid until OnShutdown() is called. | |
42 // Start must be called from |network_task_runner_|. | |
43 virtual void Start(ChromotingHost* host, | |
44 const base::Closure& disconnect_callback); | |
45 | |
46 // HostStatusObserver implementation. These methods will be called from the | |
47 // network thread. | |
48 virtual void OnClientAuthenticated(const std::string& jid) OVERRIDE; | |
49 virtual void OnClientDisconnected(const std::string& jid) OVERRIDE; | |
50 virtual void OnAccessDenied(const std::string& jid) OVERRIDE; | |
51 virtual void OnShutdown() OVERRIDE; | |
52 | |
53 protected: | |
54 const std::string& get_authenticated_jid() const { | |
55 return authenticated_jid_; | |
56 } | |
57 ChromotingHost* get_host() const { return host_; } | |
58 | |
59 const UiStrings& ui_strings() const { return ui_strings_; } | |
60 | |
61 base::SingleThreadTaskRunner* network_task_runner() const; | |
62 base::SingleThreadTaskRunner* ui_task_runner() const; | |
63 | |
64 // Invokes the session disconnect callback passed to Start(). | |
65 void DisconnectSession() const; | |
66 | |
67 virtual void ProcessOnClientAuthenticated(const std::string& username); | |
68 virtual void ProcessOnClientDisconnected(); | |
69 | |
70 ChromotingHost* host_; | |
71 | |
72 // Used to ask the host to disconnect the session. | |
73 base::Closure disconnect_callback_; | |
74 | |
75 private: | |
76 // Invoked from the UI thread when the user clicks on the Disconnect button | |
77 // to disconnect the session. | |
78 void OnDisconnectCallback(); | |
79 | |
80 // The JID of the currently-authenticated user (or an empty string if no user | |
81 // is connected). | |
82 std::string authenticated_jid_; | |
83 | |
84 // Thread on which the ChromotingHost processes network events. | |
85 // Notifications from the host, and some calls into it, use this thread. | |
86 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; | |
87 | |
88 // Thread on which to run the user interface. | |
89 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; | |
90 | |
91 // TODO(alexeypa): move |ui_strings_| to DesktopEnvironmentFactory. | |
92 UiStrings ui_strings_; | |
93 | |
94 // WeakPtr used to avoid tasks accessing the client after it is deleted. | |
95 base::WeakPtrFactory<HostUserInterface> weak_factory_; | |
96 base::WeakPtr<HostUserInterface> weak_ptr_; | |
97 | |
98 DISALLOW_COPY_AND_ASSIGN(HostUserInterface); | |
99 }; | |
100 | |
101 } // namespace remoting | |
102 | |
103 #endif // REMOTING_HOST_HOST_USER_INTERFACE_H_ | |
OLD | NEW |