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

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

Issue 2436903003: Extract ArcSupportMessageHost. (Closed)
Patch Set: Fix tests Created 4 years, 2 months 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_UI_ARC_SUPPORT_MESSAGE_HOST_H_
6 #define CHROME_BROWSER_CHROMEOS_ARC_UI_ARC_SUPPORT_MESSAGE_HOST_H_
7
8 #include "base/macros.h"
9 #include "base/values.h"
10 #include "extensions/browser/api/messaging/native_message_host.h"
11
12 namespace arc {
13
14 // Implements message routing to communicate with arc_support Chrome App.
15 // Provides JSON (base::Value) APIs for the communication.
16 class ArcSupportMessageHost : public extensions::NativeMessageHost {
17 public:
18 class Observer {
19 public:
20 // Called when an message is sent from arc_support Chrome App.
21 virtual void OnMessage(const base::DictionaryValue& message) = 0;
22
23 protected:
24 virtual ~Observer() = default;
25 };
26
27 static const char kHostName[];
28 static const char* const kHostOrigin[];
29
30 // Called when the arc_support connects the "port". Returns the
31 // instance of ArcSupportMessageHost.
32 static std::unique_ptr<NativeMessageHost> Create();
33
34 ~ArcSupportMessageHost() override;
35
36 // Sends a message to arc_support. If the client is not yet ready, the
37 // message will be just ignored.
38 void SendMessage(const base::Value& message);
39
40 // Register (or unregister if nullptr) the observer. Currently this class
khmel 2016/10/21 03:34:49 nit: Register(s) unregister(s)
hidehiko 2016/10/21 07:40:28 Good catch. Done in a new file.
41 // assumes that it has only one observer.
42 void SetObserver(Observer* observer);
43
44 private:
45 // Keep private. The instance will be created via Create().
46 ArcSupportMessageHost();
47
48 // Overrides NativeMessageHost:
khmel 2016/10/21 03:34:49 nit: not sure, but // extensions::NativeMessageHo
hidehiko 2016/10/21 07:40:27 Hmm. There seem various patterns... // $classname:
Luis Héctor Chávez 2016/10/21 07:50:48 I'd consult the chromium-dev mailing list if this
hidehiko 2016/10/21 10:06:13 As long as this is not standardized, I'd like to m
49 void Start(Client* client) override;
50 void OnMessage(const std::string& request_string) override;
51 scoped_refptr<base::SingleThreadTaskRunner> task_runner() const override;
52
53 Observer* observer_ = nullptr;
54 Client* client_ = nullptr;
55
56 DISALLOW_COPY_AND_ASSIGN(ArcSupportMessageHost);
57 };
58
59 } // namespace arc
60
61 #endif // CHROME_BROWSER_CHROMEOS_ARC_UI_ARC_SUPPORT_MESSAGE_HOST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698