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

Side by Side Diff: content/browser/broadcast_channel/broadcast_channel_provider.cc

Issue 2171843002: Use array<uint8> rather than string to pass BroadcastChannel messages. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/broadcast_channel/broadcast_channel_provider.h" 5 #include "content/browser/broadcast_channel/broadcast_channel_provider.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "mojo/public/cpp/bindings/associated_binding.h" 9 #include "mojo/public/cpp/bindings/associated_binding.h"
10 #include "mojo/public/cpp/bindings/interface_ptr_set.h" 10 #include "mojo/public/cpp/bindings/interface_ptr_set.h"
11 #include "mojo/public/cpp/bindings/strong_binding.h" 11 #include "mojo/public/cpp/bindings/strong_binding.h"
12 12
13 namespace content { 13 namespace content {
14 14
15 // There is a one-to-one mapping of BroadcastChannel instances in the renderer 15 // There is a one-to-one mapping of BroadcastChannel instances in the renderer
16 // and Connection instances in the browser. The Connection is owned by a 16 // and Connection instances in the browser. The Connection is owned by a
17 // BroadcastChannelProvider. 17 // BroadcastChannelProvider.
18 class BroadcastChannelProvider::Connection 18 class BroadcastChannelProvider::Connection
19 : public blink::mojom::BroadcastChannelClient { 19 : public blink::mojom::BroadcastChannelClient {
20 public: 20 public:
21 Connection(const url::Origin& origin, 21 Connection(const url::Origin& origin,
22 const mojo::String& name, 22 const mojo::String& name,
23 blink::mojom::BroadcastChannelClientAssociatedPtrInfo client, 23 blink::mojom::BroadcastChannelClientAssociatedPtrInfo client,
24 blink::mojom::BroadcastChannelClientAssociatedRequest connection, 24 blink::mojom::BroadcastChannelClientAssociatedRequest connection,
25 BroadcastChannelProvider* service); 25 BroadcastChannelProvider* service);
26 26
27 void OnMessage(const mojo::String& message) override; 27 void OnMessage(mojo::Array<uint8_t> message) override;
28 void MessageToClient(const mojo::String& message) const { 28 void MessageToClient(mojo::Array<uint8_t> message) const {
29 client_->OnMessage(message); 29 client_->OnMessage(std::move(message));
30 } 30 }
31 const url::Origin& origin() const { return origin_; } 31 const url::Origin& origin() const { return origin_; }
32 const std::string& name() const { return name_; } 32 const std::string& name() const { return name_; }
33 33
34 void set_connection_error_handler(const base::Closure& error_handler) { 34 void set_connection_error_handler(const base::Closure& error_handler) {
35 binding_.set_connection_error_handler(error_handler); 35 binding_.set_connection_error_handler(error_handler);
36 client_.set_connection_error_handler(error_handler); 36 client_.set_connection_error_handler(error_handler);
37 } 37 }
38 38
39 private: 39 private:
(...skipping 12 matching lines...) Expand all
52 blink::mojom::BroadcastChannelClientAssociatedRequest connection, 52 blink::mojom::BroadcastChannelClientAssociatedRequest connection,
53 BroadcastChannelProvider* service) 53 BroadcastChannelProvider* service)
54 : binding_(this, std::move(connection)), 54 : binding_(this, std::move(connection)),
55 service_(service), 55 service_(service),
56 origin_(origin), 56 origin_(origin),
57 name_(name) { 57 name_(name) {
58 client_.Bind(std::move(client)); 58 client_.Bind(std::move(client));
59 } 59 }
60 60
61 void BroadcastChannelProvider::Connection::OnMessage( 61 void BroadcastChannelProvider::Connection::OnMessage(
62 const mojo::String& message) { 62 mojo::Array<uint8_t> message) {
63 service_->ReceivedMessageOnConnection(this, message); 63 service_->ReceivedMessageOnConnection(this, std::move(message));
64 } 64 }
65 65
66 BroadcastChannelProvider::BroadcastChannelProvider() {} 66 BroadcastChannelProvider::BroadcastChannelProvider() {}
67 67
68 void BroadcastChannelProvider::Connect( 68 void BroadcastChannelProvider::Connect(
69 mojo::InterfaceRequest<blink::mojom::BroadcastChannelProvider> request) { 69 mojo::InterfaceRequest<blink::mojom::BroadcastChannelProvider> request) {
70 bindings_.AddBinding(this, std::move(request)); 70 bindings_.AddBinding(this, std::move(request));
71 } 71 }
72 72
73 void BroadcastChannelProvider::ConnectToChannel( 73 void BroadcastChannelProvider::ConnectToChannel(
(...skipping 21 matching lines...) Expand all
95 connections.erase(it); 95 connections.erase(it);
96 break; 96 break;
97 } 97 }
98 } 98 }
99 if (connections.empty()) 99 if (connections.empty())
100 connections_.erase(origin); 100 connections_.erase(origin);
101 } 101 }
102 102
103 void BroadcastChannelProvider::ReceivedMessageOnConnection( 103 void BroadcastChannelProvider::ReceivedMessageOnConnection(
104 Connection* c, 104 Connection* c,
105 const mojo::String& message) { 105 mojo::Array<uint8_t> message) {
106 auto& connections = connections_[c->origin()]; 106 auto& connections = connections_[c->origin()];
107 for (auto it = connections.lower_bound(c->name()), 107 for (auto it = connections.lower_bound(c->name()),
108 end = connections.upper_bound(c->name()); 108 end = connections.upper_bound(c->name());
109 it != end; ++it) { 109 it != end; ++it) {
110 if (it->second.get() != c) 110 if (it->second.get() != c)
111 it->second->MessageToClient(message); 111 it->second->MessageToClient(message.Clone());
112 } 112 }
113 } 113 }
114 114
115 } // namespace content 115 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698