File: it2me_cli_host.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (92 lines) | stat: -rw-r--r-- 2,895 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef REMOTING_TEST_IT2ME_CLI_HOST_H_
#define REMOTING_TEST_IT2ME_CLI_HOST_H_

#include <memory>
#include <string>

#include "base/memory/scoped_refptr.h"
#include "base/memory/weak_ptr.h"
#include "base/values.h"
#include "extensions/browser/api/messaging/native_message_host.h"
#include "remoting/base/oauth_token_getter.h"

namespace remoting {

namespace test {
class TestOAuthTokenGetter;
class TestTokenStorage;
}  // namespace test

class AutoThreadTaskRunner;

class It2MeCliHost final : public extensions::NativeMessageHost::Client {
 public:
  static bool ShouldPrintHelp();
  static void PrintHelp();

  It2MeCliHost();

  It2MeCliHost(const It2MeCliHost&) = delete;
  It2MeCliHost& operator=(const It2MeCliHost&) = delete;

  ~It2MeCliHost() override;

  void Start();

 private:
  // extensions::NativeMessageHost::Client:
  // Invoked when native host sends a message
  void PostMessageFromNativeHost(const std::string& message) override;
  void CloseChannel(const std::string& error_message) override;

  // Sends message to host in separate task.
  void SendMessageToHost(const std::string& type, base::Value::Dict params);
  // Actually sends message to host.
  void DoSendMessage(const std::string& json);
  void OnProtocolBroken(const std::string& message);

  void StartCRDHostAndGetCode(OAuthTokenGetter::Status status,
                              const std::string& user_email,
                              const std::string& access_token,
                              const std::string& scopes);

  // Shuts down host in a separate task.
  void ShutdownHost();
  // Actually shuts down a host.
  void DoShutdownHost();

  // Handlers for messages from host
  void OnHelloResponse();
  void OnDisconnectResponse();

  void OnStateError(const std::string& error_state,
                    const base::Value::Dict& message);
  void OnStateRemoteConnected(const base::Value::Dict& message);
  void OnStateRemoteDisconnected();
  void OnStateReceivedAccessCode(const base::Value::Dict& message);

  std::unique_ptr<test::TestTokenStorage> storage_;
  std::unique_ptr<test::TestOAuthTokenGetter> token_getter_;
  scoped_refptr<AutoThreadTaskRunner> ui_task_runner_;
  std::unique_ptr<extensions::NativeMessageHost> host_;

  // Filled structure with parameters for "connect" message.
  base::Value::Dict connect_params_;

  // Determines actions when receiving messages from CRD host,
  // if command is still running (no error / access code), then
  // callbacks have to be called.
  bool command_awaiting_crd_access_code_;
  // True if remote session was established.
  bool remote_connected_;

  base::WeakPtrFactory<It2MeCliHost> weak_factory_{this};
};

}  // namespace remoting

#endif  // REMOTING_TEST_IT2ME_CLI_HOST_H_