OLD | NEW |
---|---|
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 #include "remoting/host/setup/native_messaging_host.h" | 5 #include "remoting/host/setup/native_messaging_host.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 18 matching lines...) Expand all Loading... | |
29 } else { | 29 } else { |
30 LOG(ERROR) << "'config' dictionary not found"; | 30 LOG(ERROR) << "'config' dictionary not found"; |
31 } | 31 } |
32 return result.Pass(); | 32 return result.Pass(); |
33 } | 33 } |
34 | 34 |
35 } // namespace | 35 } // namespace |
36 | 36 |
37 namespace remoting { | 37 namespace remoting { |
38 | 38 |
39 const char NativeMessagingHost::kStateNotImplemented[] = "NOT_IMPLEMENTED"; | |
Sergey Ulanov
2013/05/31 23:01:43
As I mentioned before you don't really need to def
Lambros
2013/06/03 21:28:44
Done.
| |
40 const char NativeMessagingHost::kStateNotInstalled[] = "NOT_INSTALLED"; | |
41 const char NativeMessagingHost::kStateInstalling[] = "INSTALLING"; | |
42 const char NativeMessagingHost::kStateStopped[] = "STOPPED"; | |
43 const char NativeMessagingHost::kStateStarting[] = "STARTING"; | |
44 const char NativeMessagingHost::kStateStarted[] = "STARTED"; | |
45 const char NativeMessagingHost::kStateStopping[] = "STOPPING"; | |
46 const char NativeMessagingHost::kStateUnknown[] = "UNKNOWN"; | |
47 | |
48 const char NativeMessagingHost::kResultOk[] = "OK"; | |
49 const char NativeMessagingHost::kResultFailed[] = "FAILED"; | |
50 const char NativeMessagingHost::kResultCancelled[] = "CANCELLED"; | |
51 const char NativeMessagingHost::kResultFailedDirectory[] = "FAILED_DIRECTORY"; | |
52 | |
39 NativeMessagingHost::NativeMessagingHost( | 53 NativeMessagingHost::NativeMessagingHost( |
40 scoped_ptr<DaemonController> daemon_controller, | 54 scoped_ptr<DaemonController> daemon_controller, |
41 base::PlatformFile input, | 55 base::PlatformFile input, |
42 base::PlatformFile output, | 56 base::PlatformFile output, |
43 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner, | 57 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner, |
44 const base::Closure& quit_closure) | 58 const base::Closure& quit_closure) |
45 : caller_task_runner_(caller_task_runner), | 59 : caller_task_runner_(caller_task_runner), |
46 quit_closure_(quit_closure), | 60 quit_closure_(quit_closure), |
47 native_messaging_reader_(input), | 61 native_messaging_reader_(input), |
48 native_messaging_writer_(output), | 62 native_messaging_writer_(output), |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
234 scoped_ptr<base::DictionaryValue> response) { | 248 scoped_ptr<base::DictionaryValue> response) { |
235 daemon_controller_->Stop( | 249 daemon_controller_->Stop( |
236 base::Bind(&NativeMessagingHost::SendAsyncResult, base::Unretained(this), | 250 base::Bind(&NativeMessagingHost::SendAsyncResult, base::Unretained(this), |
237 base::Passed(&response))); | 251 base::Passed(&response))); |
238 return true; | 252 return true; |
239 } | 253 } |
240 | 254 |
241 bool NativeMessagingHost::ProcessGetDaemonState( | 255 bool NativeMessagingHost::ProcessGetDaemonState( |
242 const base::DictionaryValue& message, | 256 const base::DictionaryValue& message, |
243 scoped_ptr<base::DictionaryValue> response) { | 257 scoped_ptr<base::DictionaryValue> response) { |
244 // TODO(lambroslambrou): Send the state as a string instead of an integer, | |
245 // and update the web-app accordingly. | |
246 DaemonController::State state = daemon_controller_->GetState(); | 258 DaemonController::State state = daemon_controller_->GetState(); |
247 response->SetInteger("state", state); | 259 switch (state) { |
260 case DaemonController::STATE_NOT_IMPLEMENTED: | |
261 response->SetString("state", kStateNotImplemented); | |
262 break; | |
263 case DaemonController::STATE_NOT_INSTALLED: | |
264 response->SetString("state", kStateNotInstalled); | |
265 break; | |
266 case DaemonController::STATE_INSTALLING: | |
267 response->SetString("state", kStateInstalling); | |
268 break; | |
269 case DaemonController::STATE_STOPPED: | |
270 response->SetString("state", kStateStopped); | |
271 break; | |
272 case DaemonController::STATE_STARTING: | |
273 response->SetString("state", kStateStarting); | |
274 break; | |
275 case DaemonController::STATE_STARTED: | |
276 response->SetString("state", kStateStarted); | |
277 break; | |
278 case DaemonController::STATE_STOPPING: | |
279 response->SetString("state", kStateStopping); | |
280 break; | |
281 case DaemonController::STATE_UNKNOWN: | |
282 response->SetString("state", kStateUnknown); | |
283 break; | |
284 } | |
248 SendResponse(response.Pass()); | 285 SendResponse(response.Pass()); |
249 return true; | 286 return true; |
250 } | 287 } |
251 | 288 |
252 void NativeMessagingHost::SendResponse( | 289 void NativeMessagingHost::SendResponse( |
253 scoped_ptr<base::DictionaryValue> response) { | 290 scoped_ptr<base::DictionaryValue> response) { |
254 if (!caller_task_runner_->BelongsToCurrentThread()) { | 291 if (!caller_task_runner_->BelongsToCurrentThread()) { |
255 caller_task_runner_->PostTask( | 292 caller_task_runner_->PostTask( |
256 FROM_HERE, base::Bind(&NativeMessagingHost::SendResponse, weak_ptr_, | 293 FROM_HERE, base::Bind(&NativeMessagingHost::SendResponse, weak_ptr_, |
257 base::Passed(&response))); | 294 base::Passed(&response))); |
(...skipping 18 matching lines...) Expand all Loading... | |
276 bool set_by_policy) { | 313 bool set_by_policy) { |
277 response->SetBoolean("supported", supported); | 314 response->SetBoolean("supported", supported); |
278 response->SetBoolean("allowed", allowed); | 315 response->SetBoolean("allowed", allowed); |
279 response->SetBoolean("set_by_policy", set_by_policy); | 316 response->SetBoolean("set_by_policy", set_by_policy); |
280 SendResponse(response.Pass()); | 317 SendResponse(response.Pass()); |
281 } | 318 } |
282 | 319 |
283 void NativeMessagingHost::SendAsyncResult( | 320 void NativeMessagingHost::SendAsyncResult( |
284 scoped_ptr<base::DictionaryValue> response, | 321 scoped_ptr<base::DictionaryValue> response, |
285 DaemonController::AsyncResult result) { | 322 DaemonController::AsyncResult result) { |
286 // TODO(lambroslambrou): Send the result as a string instead of an integer, | 323 switch (result) { |
287 // and update the web-app accordingly. See http://crbug.com/232135. | 324 case DaemonController::RESULT_OK: |
288 response->SetInteger("result", result); | 325 response->SetString("result", kResultOk); |
326 break; | |
327 case DaemonController::RESULT_FAILED: | |
328 response->SetString("result", kResultFailed); | |
329 break; | |
330 case DaemonController::RESULT_CANCELLED: | |
331 response->SetString("result", kResultCancelled); | |
332 break; | |
333 case DaemonController::RESULT_FAILED_DIRECTORY: | |
334 response->SetString("result", kResultFailedDirectory); | |
335 break; | |
336 } | |
289 SendResponse(response.Pass()); | 337 SendResponse(response.Pass()); |
290 } | 338 } |
291 | 339 |
292 } // namespace remoting | 340 } // namespace remoting |
OLD | NEW |