| 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 #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" |
| 11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 12 #include "base/platform_file.h" | 12 #include "base/platform_file.h" |
| 13 #include "remoting/host/setup/daemon_controller.h" | 13 #include "remoting/host/setup/daemon_controller.h" |
| 14 #include "remoting/host/setup/native_messaging_reader.h" | 14 #include "remoting/host/setup/native_messaging_reader.h" |
| 15 #include "remoting/host/setup/native_messaging_writer.h" | 15 #include "remoting/host/setup/native_messaging_writer.h" |
| 16 | 16 |
| 17 namespace base { | 17 namespace base { |
| 18 class DictionaryValue; | 18 class DictionaryValue; |
| 19 class SingleThreadTaskRunner; | 19 class SingleThreadTaskRunner; |
| 20 class Value; | 20 class Value; |
| 21 } // namespace base | 21 } // namespace base |
| 22 | 22 |
| 23 namespace remoting { | 23 namespace remoting { |
| 24 | 24 |
| 25 // Implementation of the native messaging host process. | 25 // Implementation of the native messaging host process. |
| 26 class NativeMessagingHost { | 26 class NativeMessagingHost { |
| 27 public: | 27 public: |
| 28 NativeMessagingHost( | 28 NativeMessagingHost( |
| 29 scoped_ptr<DaemonController> daemon_controller, |
| 29 base::PlatformFile input, | 30 base::PlatformFile input, |
| 30 base::PlatformFile output, | 31 base::PlatformFile output, |
| 31 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner, | 32 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner, |
| 32 const base::Closure& quit_closure); | 33 const base::Closure& quit_closure); |
| 33 ~NativeMessagingHost(); | 34 ~NativeMessagingHost(); |
| 34 | 35 |
| 35 // Starts reading and processing messages. | 36 // Starts reading and processing messages. |
| 36 void Start(); | 37 void Start(); |
| 37 | 38 |
| 38 // Posts |quit_closure| to |caller_task_runner|. This gets called whenever an | 39 // Posts |quit_closure| to |caller_task_runner|. This gets called whenever an |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 // PostTask()s to the main thread if necessary. | 73 // PostTask()s to the main thread if necessary. |
| 73 void SendResponse(scoped_ptr<base::DictionaryValue> response); | 74 void SendResponse(scoped_ptr<base::DictionaryValue> response); |
| 74 | 75 |
| 75 // These Send... methods get called on the DaemonController's internal thread | 76 // These Send... methods get called on the DaemonController's internal thread |
| 76 // These methods fill in the |response| dictionary from the other parameters, | 77 // These methods fill in the |response| dictionary from the other parameters, |
| 77 // and pass it to SendResponse(). | 78 // and pass it to SendResponse(). |
| 78 void SendUpdateConfigResponse(scoped_ptr<base::DictionaryValue> response, | 79 void SendUpdateConfigResponse(scoped_ptr<base::DictionaryValue> response, |
| 79 DaemonController::AsyncResult result); | 80 DaemonController::AsyncResult result); |
| 80 void SendConfigResponse(scoped_ptr<base::DictionaryValue> response, | 81 void SendConfigResponse(scoped_ptr<base::DictionaryValue> response, |
| 81 scoped_ptr<base::DictionaryValue> config); | 82 scoped_ptr<base::DictionaryValue> config); |
| 82 void SendUsageStatsConsentResponse( | 83 void SendUsageStatsConsentResponse(scoped_ptr<base::DictionaryValue> response, |
| 83 scoped_ptr<base::DictionaryValue> response, | 84 bool supported, |
| 84 bool supported, | 85 bool allowed, |
| 85 bool allowed, | 86 bool set_by_policy); |
| 86 bool set_by_policy); | |
| 87 void SendAsyncResult(scoped_ptr<base::DictionaryValue> response, | 87 void SendAsyncResult(scoped_ptr<base::DictionaryValue> response, |
| 88 DaemonController::AsyncResult result); | 88 DaemonController::AsyncResult result); |
| 89 | 89 |
| 90 // Callbacks may be invoked by e.g. DaemonController during destruction, | 90 // Callbacks may be invoked by e.g. DaemonController during destruction, |
| 91 // which use |weak_ptr_|, so it's important that it be the last member to be | 91 // which use |weak_ptr_|, so it's important that it be the last member to be |
| 92 // destroyed. | 92 // destroyed. |
| 93 base::WeakPtr<NativeMessagingHost> weak_ptr_; | 93 base::WeakPtr<NativeMessagingHost> weak_ptr_; |
| 94 | 94 |
| 95 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner_; | 95 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner_; |
| 96 base::Closure quit_closure_; | 96 base::Closure quit_closure_; |
| 97 | 97 |
| 98 NativeMessagingReader native_messaging_reader_; | 98 NativeMessagingReader native_messaging_reader_; |
| 99 NativeMessagingWriter native_messaging_writer_; | 99 NativeMessagingWriter native_messaging_writer_; |
| 100 | 100 |
| 101 // The DaemonController may post tasks to this object during destruction (but | 101 // The DaemonController may post tasks to this object during destruction (but |
| 102 // not afterwards), so it needs to be destroyed before other members of this | 102 // not afterwards), so it needs to be destroyed before other members of this |
| 103 // class (except for |weak_factory_|). | 103 // class (except for |weak_factory_|). |
| 104 scoped_ptr<remoting::DaemonController> daemon_controller_; | 104 scoped_ptr<remoting::DaemonController> daemon_controller_; |
| 105 | 105 |
| 106 base::WeakPtrFactory<NativeMessagingHost> weak_factory_; | 106 base::WeakPtrFactory<NativeMessagingHost> weak_factory_; |
| 107 | 107 |
| 108 DISALLOW_COPY_AND_ASSIGN(NativeMessagingHost); | 108 DISALLOW_COPY_AND_ASSIGN(NativeMessagingHost); |
| 109 }; | 109 }; |
| 110 | 110 |
| 111 } // namespace remoting | 111 } // namespace remoting |
| 112 | 112 |
| 113 #endif // REMOTING_HOST_SETUP_NATIVE_MESSAGING_HOST_H_ | 113 #endif // REMOTING_HOST_SETUP_NATIVE_MESSAGING_HOST_H_ |
| OLD | NEW |