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" |
(...skipping 21 matching lines...) Expand all Loading... | |
32 const base::Closure& quit_closure); | 32 const base::Closure& quit_closure); |
33 ~NativeMessagingHost(); | 33 ~NativeMessagingHost(); |
34 | 34 |
35 // Starts reading and processing messages. | 35 // Starts reading and processing messages. |
36 void Start(); | 36 void Start(); |
37 | 37 |
38 // Posts |quit_closure| to |caller_task_runner|. This gets called whenever an | 38 // Posts |quit_closure| to |caller_task_runner|. This gets called whenever an |
39 // error is encountered during reading and processing messages. | 39 // error is encountered during reading and processing messages. |
40 void Shutdown(); | 40 void Shutdown(); |
41 | 41 |
42 // Allow unittests to use a mock DaemonController instance. | |
43 void SetDaemonControllerForTest( | |
Sergey Ulanov
2013/05/18 01:59:31
can daemon_controller be passed to the constructor
Lambros
2013/05/22 21:42:18
Done.
| |
44 scoped_ptr<DaemonController> daemon_controller); | |
45 | |
42 private: | 46 private: |
43 // Processes a message received from the client app. | 47 // Processes a message received from the client app. |
44 void ProcessMessage(scoped_ptr<base::Value> message); | 48 void ProcessMessage(scoped_ptr<base::Value> message); |
45 | 49 |
46 // These "Process.." methods handle specific request types. The |response| | 50 // These "Process.." methods handle specific request types. The |response| |
47 // dictionary is pre-filled by ProcessMessage() with the parts of the | 51 // dictionary is pre-filled by ProcessMessage() with the parts of the |
48 // response already known ("id" and "type" fields). | 52 // response already known ("id" and "type" fields). |
49 bool ProcessHello(const base::DictionaryValue& message, | 53 bool ProcessHello(const base::DictionaryValue& message, |
50 scoped_ptr<base::DictionaryValue> response); | 54 scoped_ptr<base::DictionaryValue> response); |
51 bool ProcessGetHostName(const base::DictionaryValue& message, | 55 bool ProcessGetHostName(const base::DictionaryValue& message, |
(...skipping 20 matching lines...) Expand all Loading... | |
72 // PostTask()s to the main thread if necessary. | 76 // PostTask()s to the main thread if necessary. |
73 void SendResponse(scoped_ptr<base::DictionaryValue> response); | 77 void SendResponse(scoped_ptr<base::DictionaryValue> response); |
74 | 78 |
75 // These Send... methods get called on the DaemonController's internal thread | 79 // These Send... methods get called on the DaemonController's internal thread |
76 // These methods fill in the |response| dictionary from the other parameters, | 80 // These methods fill in the |response| dictionary from the other parameters, |
77 // and pass it to SendResponse(). | 81 // and pass it to SendResponse(). |
78 void SendUpdateConfigResponse(scoped_ptr<base::DictionaryValue> response, | 82 void SendUpdateConfigResponse(scoped_ptr<base::DictionaryValue> response, |
79 DaemonController::AsyncResult result); | 83 DaemonController::AsyncResult result); |
80 void SendConfigResponse(scoped_ptr<base::DictionaryValue> response, | 84 void SendConfigResponse(scoped_ptr<base::DictionaryValue> response, |
81 scoped_ptr<base::DictionaryValue> config); | 85 scoped_ptr<base::DictionaryValue> config); |
82 void SendUsageStatsConsentResponse( | 86 void SendUsageStatsConsentResponse(scoped_ptr<base::DictionaryValue> response, |
83 scoped_ptr<base::DictionaryValue> response, | 87 bool supported, |
84 bool supported, | 88 bool allowed, |
85 bool allowed, | 89 bool set_by_policy); |
86 bool set_by_policy); | |
87 void SendAsyncResult(scoped_ptr<base::DictionaryValue> response, | 90 void SendAsyncResult(scoped_ptr<base::DictionaryValue> response, |
88 DaemonController::AsyncResult result); | 91 DaemonController::AsyncResult result); |
89 | 92 |
90 // Callbacks may be invoked by e.g. DaemonController during destruction, | 93 // 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 | 94 // which use |weak_ptr_|, so it's important that it be the last member to be |
92 // destroyed. | 95 // destroyed. |
93 base::WeakPtr<NativeMessagingHost> weak_ptr_; | 96 base::WeakPtr<NativeMessagingHost> weak_ptr_; |
94 | 97 |
95 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner_; | 98 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner_; |
96 base::Closure quit_closure_; | 99 base::Closure quit_closure_; |
97 | 100 |
98 NativeMessagingReader native_messaging_reader_; | 101 NativeMessagingReader native_messaging_reader_; |
99 NativeMessagingWriter native_messaging_writer_; | 102 NativeMessagingWriter native_messaging_writer_; |
100 | 103 |
101 // The DaemonController may post tasks to this object during destruction (but | 104 // 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 | 105 // not afterwards), so it needs to be destroyed before other members of this |
103 // class (except for |weak_factory_|). | 106 // class (except for |weak_factory_|). |
104 scoped_ptr<remoting::DaemonController> daemon_controller_; | 107 scoped_ptr<remoting::DaemonController> daemon_controller_; |
105 | 108 |
106 base::WeakPtrFactory<NativeMessagingHost> weak_factory_; | 109 base::WeakPtrFactory<NativeMessagingHost> weak_factory_; |
107 | 110 |
108 DISALLOW_COPY_AND_ASSIGN(NativeMessagingHost); | 111 DISALLOW_COPY_AND_ASSIGN(NativeMessagingHost); |
109 }; | 112 }; |
110 | 113 |
111 } // namespace remoting | 114 } // namespace remoting |
112 | 115 |
113 #endif // REMOTING_HOST_SETUP_NATIVE_MESSAGING_HOST_H_ | 116 #endif // REMOTING_HOST_SETUP_NATIVE_MESSAGING_HOST_H_ |
OLD | NEW |