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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/arc/ui/arc_support_message_host.h
diff --git a/chrome/browser/chromeos/arc/ui/arc_support_message_host.h b/chrome/browser/chromeos/arc/ui/arc_support_message_host.h
new file mode 100644
index 0000000000000000000000000000000000000000..8145e19919a2a108da52cb4caad67df94febae93
--- /dev/null
+++ b/chrome/browser/chromeos/arc/ui/arc_support_message_host.h
@@ -0,0 +1,61 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_CHROMEOS_ARC_UI_ARC_SUPPORT_MESSAGE_HOST_H_
+#define CHROME_BROWSER_CHROMEOS_ARC_UI_ARC_SUPPORT_MESSAGE_HOST_H_
+
+#include "base/macros.h"
+#include "base/values.h"
+#include "extensions/browser/api/messaging/native_message_host.h"
+
+namespace arc {
+
+// Implements message routing to communicate with arc_support Chrome App.
+// Provides JSON (base::Value) APIs for the communication.
+class ArcSupportMessageHost : public extensions::NativeMessageHost {
+ public:
+ class Observer {
+ public:
+ // Called when an message is sent from arc_support Chrome App.
+ virtual void OnMessage(const base::DictionaryValue& message) = 0;
+
+ protected:
+ virtual ~Observer() = default;
+ };
+
+ static const char kHostName[];
+ static const char* const kHostOrigin[];
+
+ // Called when the arc_support connects the "port". Returns the
+ // instance of ArcSupportMessageHost.
+ static std::unique_ptr<NativeMessageHost> Create();
+
+ ~ArcSupportMessageHost() override;
+
+ // Sends a message to arc_support. If the client is not yet ready, the
+ // message will be just ignored.
+ void SendMessage(const base::Value& message);
+
+ // 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.
+ // assumes that it has only one observer.
+ void SetObserver(Observer* observer);
+
+ private:
+ // Keep private. The instance will be created via Create().
+ ArcSupportMessageHost();
+
+ // 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
+ void Start(Client* client) override;
+ void OnMessage(const std::string& request_string) override;
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner() const override;
+
+ Observer* observer_ = nullptr;
+ Client* client_ = nullptr;
+
+ DISALLOW_COPY_AND_ASSIGN(ArcSupportMessageHost);
+};
+
+} // namespace arc
+
+#endif // CHROME_BROWSER_CHROMEOS_ARC_UI_ARC_SUPPORT_MESSAGE_HOST_H_

Powered by Google App Engine
This is Rietveld 408576698