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

Side by Side Diff: content/child/navigator_connect/service_port_dispatcher_impl.cc

Issue 1210643002: Update navigator.services API to use the new services.onconnect event [2/3]. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@serviceport
Patch Set: decouple renderer side code more Created 5 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
(Empty)
1 // Copyright 2015 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 #include "content/child/navigator_connect/service_port_dispatcher_impl.h"
6
7 #include "base/trace_event/trace_event.h"
8 #include "mojo/common/common_type_converters.h"
9 #include "mojo/common/url_type_converters.h"
10 #include "third_party/WebKit/public/web/WebServiceWorkerContextProxy.h"
11
12 namespace content {
13
14 namespace {
15
16 class ConnectCallbacks : public blink::WebServicePortConnectEventCallbacks {
17 public:
18 ConnectCallbacks(const ServicePortDispatcher::ConnectCallback& callback)
19 : callback_(callback) {}
20
21 ~ConnectCallbacks() override {}
22
23 void onSuccess(blink::WebServicePort* port) override {
24 callback_.Run(SERVICE_PORT_CONNECT_RESULT_ACCEPT,
25 mojo::String::From<base::string16>(port->name),
26 mojo::String::From<base::string16>(port->data));
27 }
28
29 void onError() override {
30 callback_.Run(SERVICE_PORT_CONNECT_RESULT_REJECT, mojo::String(""),
31 mojo::String(""));
32 }
33
34 private:
35 ServicePortDispatcher::ConnectCallback callback_;
36 };
37
38 } // namespace
39
40 void ServicePortDispatcherImpl::Create(
41 base::WeakPtr<blink::WebServiceWorkerContextProxy> proxy,
42 mojo::InterfaceRequest<ServicePortDispatcher> request) {
43 new ServicePortDispatcherImpl(proxy, request.Pass());
44 }
45
46 ServicePortDispatcherImpl::~ServicePortDispatcherImpl() {
47 }
48
49 ServicePortDispatcherImpl::ServicePortDispatcherImpl(
50 base::WeakPtr<blink::WebServiceWorkerContextProxy> proxy,
51 mojo::InterfaceRequest<ServicePortDispatcher> request)
52 : binding_(this, request.Pass()), proxy_(proxy) {
53 }
54
55 void ServicePortDispatcherImpl::Connect(const mojo::String& target_url,
56 const mojo::String& origin,
57 int32_t port_id,
58 const ConnectCallback& callback) {
59 if (!proxy_) {
60 callback.Run(SERVICE_PORT_CONNECT_RESULT_REJECT, mojo::String(""),
61 mojo::String(""));
62 return;
63 }
64 TRACE_EVENT0("ServiceWorker", "ServicePortDispatcherImpl::Connect");
65 proxy_->dispatchServicePortConnectEvent(new ConnectCallbacks(callback),
66 target_url.To<GURL>(),
67 origin.To<base::string16>(), port_id);
68 }
69
70 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698