cygprofile: increase timeouts to allow showing web contents
[chromium-blink-merge.git] / content / child / navigator_connect / service_port_dispatcher_impl.cc
blob977f2b926aadb63c66b3db9f742d6f2f7df64385
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.
5 #include "content/child/navigator_connect/service_port_dispatcher_impl.h"
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/modules/serviceworker/WebServiceWorkerContextProxy.h"
12 namespace content {
14 namespace {
16 class WebConnectCallbacksImpl
17 : public blink::WebServicePortConnectEventCallbacks {
18 public:
19 WebConnectCallbacksImpl(
20 const ServicePortDispatcher::ConnectCallback& callback)
21 : callback_(callback) {}
23 ~WebConnectCallbacksImpl() override {}
25 void onSuccess(blink::WebServicePort* port) override {
26 callback_.Run(SERVICE_PORT_CONNECT_RESULT_ACCEPT,
27 mojo::String::From<base::string16>(port->name),
28 mojo::String::From<base::string16>(port->data));
31 void onError() override {
32 callback_.Run(SERVICE_PORT_CONNECT_RESULT_REJECT, mojo::String(""),
33 mojo::String(""));
36 private:
37 ServicePortDispatcher::ConnectCallback callback_;
40 } // namespace
42 void ServicePortDispatcherImpl::Create(
43 base::WeakPtr<blink::WebServiceWorkerContextProxy> proxy,
44 mojo::InterfaceRequest<ServicePortDispatcher> request) {
45 new ServicePortDispatcherImpl(proxy, request.Pass());
48 ServicePortDispatcherImpl::~ServicePortDispatcherImpl() {
49 WorkerThread::RemoveObserver(this);
52 ServicePortDispatcherImpl::ServicePortDispatcherImpl(
53 base::WeakPtr<blink::WebServiceWorkerContextProxy> proxy,
54 mojo::InterfaceRequest<ServicePortDispatcher> request)
55 : binding_(this, request.Pass()), proxy_(proxy) {
56 WorkerThread::AddObserver(this);
59 void ServicePortDispatcherImpl::WillStopCurrentWorkerThread() {
60 delete this;
63 void ServicePortDispatcherImpl::Connect(const mojo::String& target_url,
64 const mojo::String& origin,
65 int32_t port_id,
66 const ConnectCallback& callback) {
67 if (!proxy_) {
68 callback.Run(SERVICE_PORT_CONNECT_RESULT_REJECT, mojo::String(""),
69 mojo::String(""));
70 return;
72 TRACE_EVENT0("ServiceWorker", "ServicePortDispatcherImpl::Connect");
73 proxy_->dispatchServicePortConnectEvent(new WebConnectCallbacksImpl(callback),
74 target_url.To<GURL>(),
75 origin.To<base::string16>(), port_id);
78 } // namespace content