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
3 // found in the LICENSE file.
5 #ifndef REMOTING_HOST_SETUP_ME2ME_NATIVE_MESSAGING_HOST_H_
6 #define REMOTING_HOST_SETUP_ME2ME_NATIVE_MESSAGING_HOST_H_
8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/memory/weak_ptr.h"
11 #include "base/threading/thread_checker.h"
12 #include "remoting/host/native_messaging/native_messaging_channel.h"
13 #include "remoting/host/setup/daemon_controller.h"
14 #include "remoting/host/setup/oauth_client.h"
17 class DictionaryValue
;
22 class GaiaOAuthClient
;
28 class PairingRegistry
;
29 } // namespace protocol
31 // Implementation of the me2me native messaging host.
32 class Me2MeNativeMessagingHost
{
34 typedef NativeMessagingChannel::SendMessageCallback SendMessageCallback
;
36 Me2MeNativeMessagingHost(
37 scoped_ptr
<NativeMessagingChannel
> channel
,
38 scoped_refptr
<DaemonController
> daemon_controller
,
39 scoped_refptr
<protocol::PairingRegistry
> pairing_registry
,
40 scoped_ptr
<OAuthClient
> oauth_client
);
41 virtual ~Me2MeNativeMessagingHost();
43 void Start(const base::Closure
& quit_closure
);
46 void ProcessMessage(scoped_ptr
<base::DictionaryValue
> message
);
48 // These "Process.." methods handle specific request types. The |response|
49 // dictionary is pre-filled by ProcessMessage() with the parts of the
50 // response already known ("id" and "type" fields).
52 const base::DictionaryValue
& message
,
53 scoped_ptr
<base::DictionaryValue
> response
);
54 void ProcessClearPairedClients(
55 const base::DictionaryValue
& message
,
56 scoped_ptr
<base::DictionaryValue
> response
);
57 void ProcessDeletePairedClient(
58 const base::DictionaryValue
& message
,
59 scoped_ptr
<base::DictionaryValue
> response
);
60 void ProcessGetHostName(
61 const base::DictionaryValue
& message
,
62 scoped_ptr
<base::DictionaryValue
> response
);
63 void ProcessGetPinHash(
64 const base::DictionaryValue
& message
,
65 scoped_ptr
<base::DictionaryValue
> response
);
66 void ProcessGenerateKeyPair(
67 const base::DictionaryValue
& message
,
68 scoped_ptr
<base::DictionaryValue
> response
);
69 void ProcessUpdateDaemonConfig(
70 const base::DictionaryValue
& message
,
71 scoped_ptr
<base::DictionaryValue
> response
);
72 void ProcessGetDaemonConfig(
73 const base::DictionaryValue
& message
,
74 scoped_ptr
<base::DictionaryValue
> response
);
75 void ProcessGetPairedClients(
76 const base::DictionaryValue
& message
,
77 scoped_ptr
<base::DictionaryValue
> response
);
78 void ProcessGetUsageStatsConsent(
79 const base::DictionaryValue
& message
,
80 scoped_ptr
<base::DictionaryValue
> response
);
81 void ProcessStartDaemon(
82 const base::DictionaryValue
& message
,
83 scoped_ptr
<base::DictionaryValue
> response
);
84 void ProcessStopDaemon(
85 const base::DictionaryValue
& message
,
86 scoped_ptr
<base::DictionaryValue
> response
);
87 void ProcessGetDaemonState(
88 const base::DictionaryValue
& message
,
89 scoped_ptr
<base::DictionaryValue
> response
);
90 void ProcessGetHostClientId(
91 const base::DictionaryValue
& message
,
92 scoped_ptr
<base::DictionaryValue
> response
);
93 void ProcessGetCredentialsFromAuthCode(
94 const base::DictionaryValue
& message
,
95 scoped_ptr
<base::DictionaryValue
> response
);
97 // These Send... methods get called on the DaemonController's internal thread,
98 // or on the calling thread if called by the PairingRegistry.
99 // These methods fill in the |response| dictionary from the other parameters,
100 // and pass it to SendResponse().
101 void SendConfigResponse(scoped_ptr
<base::DictionaryValue
> response
,
102 scoped_ptr
<base::DictionaryValue
> config
);
103 void SendPairedClientsResponse(scoped_ptr
<base::DictionaryValue
> response
,
104 scoped_ptr
<base::ListValue
> pairings
);
105 void SendUsageStatsConsentResponse(
106 scoped_ptr
<base::DictionaryValue
> response
,
107 const DaemonController::UsageStatsConsent
& consent
);
108 void SendAsyncResult(scoped_ptr
<base::DictionaryValue
> response
,
109 DaemonController::AsyncResult result
);
110 void SendBooleanResult(scoped_ptr
<base::DictionaryValue
> response
,
112 void SendCredentialsResponse(scoped_ptr
<base::DictionaryValue
> response
,
113 const std::string
& user_email
,
114 const std::string
& refresh_token
);
118 scoped_ptr
<NativeMessagingChannel
> channel_
;
119 scoped_refptr
<DaemonController
> daemon_controller_
;
121 // Used to load and update the paired clients for this host.
122 scoped_refptr
<protocol::PairingRegistry
> pairing_registry_
;
124 // Used to exchange the service account authorization code for credentials.
125 scoped_ptr
<OAuthClient
> oauth_client_
;
127 base::ThreadChecker thread_checker_
;
129 base::WeakPtr
<Me2MeNativeMessagingHost
> weak_ptr_
;
130 base::WeakPtrFactory
<Me2MeNativeMessagingHost
> weak_factory_
;
132 DISALLOW_COPY_AND_ASSIGN(Me2MeNativeMessagingHost
);
135 // Creates a Me2MeNativeMessagingHost instance, attaches it to stdin/stdout and
136 // runs the message loop until Me2MeNativeMessagingHost signals shutdown.
137 int Me2MeNativeMessagingHostMain();
139 } // namespace remoting
141 #endif // REMOTING_HOST_SETUP_ME2ME_NATIVE_MESSAGING_HOST_H_