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

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

Issue 2158913006: Move BroadcastChannel browser code from components/ to content/browser. (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 "components/webmessaging/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 webmessaging { 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 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 mojom::BroadcastChannelClientAssociatedPtrInfo client, 23 blink::mojom::BroadcastChannelClientAssociatedPtrInfo client,
24 mojom::BroadcastChannelClientAssociatedRequest connection, 24 blink::mojom::BroadcastChannelClientAssociatedRequest connection,
25 webmessaging::BroadcastChannelProvider* service); 25 BroadcastChannelProvider* service);
26 26
27 void OnMessage(const mojo::String& message) override; 27 void OnMessage(const mojo::String& message) override;
28 void MessageToClient(const mojo::String& message) const { 28 void MessageToClient(const mojo::String& message) const {
29 client_->OnMessage(message); 29 client_->OnMessage(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:
40 mojo::AssociatedBinding<mojom::BroadcastChannelClient> binding_; 40 mojo::AssociatedBinding<blink::mojom::BroadcastChannelClient> binding_;
41 mojom::BroadcastChannelClientAssociatedPtr client_; 41 blink::mojom::BroadcastChannelClientAssociatedPtr client_;
42 42
43 webmessaging::BroadcastChannelProvider* service_; 43 BroadcastChannelProvider* service_;
44 url::Origin origin_; 44 url::Origin origin_;
45 std::string name_; 45 std::string name_;
46 }; 46 };
47 47
48 BroadcastChannelProvider::Connection::Connection( 48 BroadcastChannelProvider::Connection::Connection(
49 const url::Origin& origin, 49 const url::Origin& origin,
50 const mojo::String& name, 50 const mojo::String& name,
51 mojom::BroadcastChannelClientAssociatedPtrInfo client, 51 blink::mojom::BroadcastChannelClientAssociatedPtrInfo client,
52 mojom::BroadcastChannelClientAssociatedRequest connection, 52 blink::mojom::BroadcastChannelClientAssociatedRequest connection,
53 webmessaging::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 const mojo::String& message) {
63 service_->ReceivedMessageOnConnection(this, message); 63 service_->ReceivedMessageOnConnection(this, message);
64 } 64 }
65 65
66 BroadcastChannelProvider::BroadcastChannelProvider() {} 66 BroadcastChannelProvider::BroadcastChannelProvider() {}
67 67
68 void BroadcastChannelProvider::Connect( 68 void BroadcastChannelProvider::Connect(
69 mojo::InterfaceRequest<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(
74 const url::Origin& origin, 74 const url::Origin& origin,
75 const mojo::String& name, 75 const mojo::String& name,
76 mojom::BroadcastChannelClientAssociatedPtrInfo client, 76 blink::mojom::BroadcastChannelClientAssociatedPtrInfo client,
77 mojom::BroadcastChannelClientAssociatedRequest connection) { 77 blink::mojom::BroadcastChannelClientAssociatedRequest connection) {
78 std::unique_ptr<Connection> c(new Connection(origin, name, std::move(client), 78 std::unique_ptr<Connection> c(new Connection(origin, name, std::move(client),
79 std::move(connection), this)); 79 std::move(connection), this));
80 c->set_connection_error_handler( 80 c->set_connection_error_handler(
81 base::Bind(&BroadcastChannelProvider::UnregisterConnection, 81 base::Bind(&BroadcastChannelProvider::UnregisterConnection,
82 base::Unretained(this), c.get())); 82 base::Unretained(this), c.get()));
83 connections_[origin].insert(std::make_pair(name, std::move(c))); 83 connections_[origin].insert(std::make_pair(name, std::move(c)));
84 } 84 }
85 85
86 BroadcastChannelProvider::~BroadcastChannelProvider() {} 86 BroadcastChannelProvider::~BroadcastChannelProvider() {}
87 87
(...skipping 17 matching lines...) Expand all
105 const mojo::String& message) { 105 const mojo::String& 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);
112 } 112 }
113 } 113 }
114 114
115 } // namespace webmessaging 115 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698