Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(208)

Side by Side Diff: chrome/browser/chromeos/arc/extensions/arc_support_message_host.h

Issue 2436903003: Extract ArcSupportMessageHost. (Closed)
Patch Set: Rebase Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 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.
4
5 #ifndef CHROME_BROWSER_CHROMEOS_ARC_EXTENSIONS_ARC_SUPPORT_MESSAGE_HOST_H_
6 #define CHROME_BROWSER_CHROMEOS_ARC_EXTENSIONS_ARC_SUPPORT_MESSAGE_HOST_H_
7
8 #include <memory>
9
10 #include "base/macros.h"
11 #include "base/values.h"
12 #include "extensions/browser/api/messaging/native_message_host.h"
13
14 namespace arc {
15
16 // Implements message routing to communicate with arc_support Chrome App.
17 // Provides JSON (base::Value) APIs for the communication.
18 class ArcSupportMessageHost : public extensions::NativeMessageHost {
19 public:
20 class Observer {
21 public:
22 // Called when an message is sent from arc_support Chrome App.
23 virtual void OnMessage(const base::DictionaryValue& message) = 0;
24
25 protected:
26 virtual ~Observer() = default;
27 };
28
29 static const char kHostName[];
30 static const char* const kHostOrigin[];
31
32 // Called when the arc_support connects the "port". Returns the
33 // instance of ArcSupportMessageHost.
34 static std::unique_ptr<NativeMessageHost> Create();
35
36 ~ArcSupportMessageHost() override;
37
38 // Sends a message to arc_support. If the client is not yet ready, the
39 // message will be just ignored.
40 void SendMessage(const base::Value& message);
41
42 // Registers (or unregisters if nullptr) the observer. Currently this class
43 // assumes that it has only one observer.
44 void SetObserver(Observer* observer);
45
46 private:
47 // Keep private. The instance will be created via Create().
48 ArcSupportMessageHost();
49
50 // extensions::NativeMessageHost overrides:
51 void Start(Client* client) override;
52 void OnMessage(const std::string& request_string) override;
53 scoped_refptr<base::SingleThreadTaskRunner> task_runner() const override;
54
55 Observer* observer_ = nullptr;
56 Client* client_ = nullptr;
57
58 DISALLOW_COPY_AND_ASSIGN(ArcSupportMessageHost);
59 };
60
61 } // namespace arc
62
63 #endif // CHROME_BROWSER_CHROMEOS_ARC_EXTENSIONS_ARC_SUPPORT_MESSAGE_HOST_H_
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/arc/arc_support_host.cc ('k') | chrome/browser/chromeos/arc/extensions/arc_support_message_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698