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

Side by Side Diff: remoting/host/setup/native_messaging_host.h

Issue 23606019: Refactor the daemon controller so that the callbacks are called on the caller thread. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix the license Created 7 years, 3 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/setup/host_starter.cc ('k') | remoting/host/setup/native_messaging_host.cc » ('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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #ifndef REMOTING_HOST_SETUP_NATIVE_MESSAGING_HOST_H_ 5 #ifndef REMOTING_HOST_SETUP_NATIVE_MESSAGING_HOST_H_
6 #define REMOTING_HOST_SETUP_NATIVE_MESSAGING_HOST_H_ 6 #define REMOTING_HOST_SETUP_NATIVE_MESSAGING_HOST_H_
7 7
8 #include "base/callback_forward.h" 8 #include "base/callback_forward.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 18 matching lines...) Expand all
29 namespace remoting { 29 namespace remoting {
30 30
31 namespace protocol { 31 namespace protocol {
32 class PairingRegistry; 32 class PairingRegistry;
33 } // namespace protocol 33 } // namespace protocol
34 34
35 // Implementation of the native messaging host process. 35 // Implementation of the native messaging host process.
36 class NativeMessagingHost { 36 class NativeMessagingHost {
37 public: 37 public:
38 NativeMessagingHost( 38 NativeMessagingHost(
39 scoped_ptr<DaemonController> daemon_controller, 39 scoped_refptr<DaemonController> daemon_controller,
40 scoped_refptr<protocol::PairingRegistry> pairing_registry, 40 scoped_refptr<protocol::PairingRegistry> pairing_registry,
41 scoped_ptr<OAuthClient> oauth_client, 41 scoped_ptr<OAuthClient> oauth_client,
42 base::PlatformFile input, 42 base::PlatformFile input,
43 base::PlatformFile output, 43 base::PlatformFile output,
44 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner, 44 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner,
45 const base::Closure& quit_closure); 45 const base::Closure& quit_closure);
46 ~NativeMessagingHost(); 46 ~NativeMessagingHost();
47 47
48 // Starts reading and processing messages. 48 // Starts reading and processing messages.
49 void Start(); 49 void Start();
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 void SendResponse(scoped_ptr<base::DictionaryValue> response); 97 void SendResponse(scoped_ptr<base::DictionaryValue> response);
98 98
99 // These Send... methods get called on the DaemonController's internal thread, 99 // These Send... methods get called on the DaemonController's internal thread,
100 // or on the calling thread if called by the PairingRegistry. 100 // or on the calling thread if called by the PairingRegistry.
101 // These methods fill in the |response| dictionary from the other parameters, 101 // These methods fill in the |response| dictionary from the other parameters,
102 // and pass it to SendResponse(). 102 // and pass it to SendResponse().
103 void SendConfigResponse(scoped_ptr<base::DictionaryValue> response, 103 void SendConfigResponse(scoped_ptr<base::DictionaryValue> response,
104 scoped_ptr<base::DictionaryValue> config); 104 scoped_ptr<base::DictionaryValue> config);
105 void SendPairedClientsResponse(scoped_ptr<base::DictionaryValue> response, 105 void SendPairedClientsResponse(scoped_ptr<base::DictionaryValue> response,
106 scoped_ptr<base::ListValue> pairings); 106 scoped_ptr<base::ListValue> pairings);
107 void SendUsageStatsConsentResponse(scoped_ptr<base::DictionaryValue> response, 107 void SendUsageStatsConsentResponse(
108 bool supported, 108 scoped_ptr<base::DictionaryValue> response,
109 bool allowed, 109 const DaemonController::UsageStatsConsent& consent);
110 bool set_by_policy);
111 void SendAsyncResult(scoped_ptr<base::DictionaryValue> response, 110 void SendAsyncResult(scoped_ptr<base::DictionaryValue> response,
112 DaemonController::AsyncResult result); 111 DaemonController::AsyncResult result);
113 void SendBooleanResult(scoped_ptr<base::DictionaryValue> response, 112 void SendBooleanResult(scoped_ptr<base::DictionaryValue> response,
114 bool result); 113 bool result);
115 void SendCredentialsResponse(scoped_ptr<base::DictionaryValue> response, 114 void SendCredentialsResponse(scoped_ptr<base::DictionaryValue> response,
116 const std::string& user_email, 115 const std::string& user_email,
117 const std::string& refresh_token); 116 const std::string& refresh_token);
118 117
119 // Callbacks may be invoked by e.g. DaemonController during destruction, 118 // Callbacks may be invoked by e.g. DaemonController during destruction,
120 // which use |weak_ptr_|, so it's important that it be the last member to be 119 // which use |weak_ptr_|, so it's important that it be the last member to be
121 // destroyed. 120 // destroyed.
122 base::WeakPtr<NativeMessagingHost> weak_ptr_; 121 base::WeakPtr<NativeMessagingHost> weak_ptr_;
123 122
124 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner_; 123 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner_;
125 base::Closure quit_closure_; 124 base::Closure quit_closure_;
126 125
127 NativeMessagingReader native_messaging_reader_; 126 NativeMessagingReader native_messaging_reader_;
128 NativeMessagingWriter native_messaging_writer_; 127 NativeMessagingWriter native_messaging_writer_;
129 128
130 // The DaemonController may post tasks to this object during destruction (but 129 // The DaemonController may post tasks to this object during destruction (but
131 // not afterwards), so it needs to be destroyed before other members of this 130 // not afterwards), so it needs to be destroyed before other members of this
132 // class (except for |weak_factory_|). 131 // class (except for |weak_factory_|).
133 scoped_ptr<remoting::DaemonController> daemon_controller_; 132 scoped_refptr<remoting::DaemonController> daemon_controller_;
134 133
135 // Used to load and update the paired clients for this host. 134 // Used to load and update the paired clients for this host.
136 scoped_refptr<protocol::PairingRegistry> pairing_registry_; 135 scoped_refptr<protocol::PairingRegistry> pairing_registry_;
137 136
138 // Used to exchange the service account authorization code for credentials. 137 // Used to exchange the service account authorization code for credentials.
139 scoped_ptr<OAuthClient> oauth_client_; 138 scoped_ptr<OAuthClient> oauth_client_;
140 139
141 // Keeps track of pending requests. Used to delay shutdown until all responses 140 // Keeps track of pending requests. Used to delay shutdown until all responses
142 // have been sent. 141 // have been sent.
143 int pending_requests_; 142 int pending_requests_;
144 143
145 // True if Shutdown() has been called. 144 // True if Shutdown() has been called.
146 bool shutdown_; 145 bool shutdown_;
147 146
148 base::WeakPtrFactory<NativeMessagingHost> weak_factory_; 147 base::WeakPtrFactory<NativeMessagingHost> weak_factory_;
149 148
150 DISALLOW_COPY_AND_ASSIGN(NativeMessagingHost); 149 DISALLOW_COPY_AND_ASSIGN(NativeMessagingHost);
151 }; 150 };
152 151
153 // Creates a NativeMessagingHost instance, attaches it to stdin/stdout and runs 152 // Creates a NativeMessagingHost instance, attaches it to stdin/stdout and runs
154 // the message loop until NativeMessagingHost signals shutdown. 153 // the message loop until NativeMessagingHost signals shutdown.
155 int NativeMessagingHostMain(); 154 int NativeMessagingHostMain();
156 155
157 } // namespace remoting 156 } // namespace remoting
158 157
159 #endif // REMOTING_HOST_SETUP_NATIVE_MESSAGING_HOST_H_ 158 #endif // REMOTING_HOST_SETUP_NATIVE_MESSAGING_HOST_H_
OLDNEW
« no previous file with comments | « remoting/host/setup/host_starter.cc ('k') | remoting/host/setup/native_messaging_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698