platform_service_provider_mac.cc 1.8 KB
Newer Older
C
Chinmay Garde 已提交
1 2 3 4 5 6 7 8
// Copyright 2015 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.

#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/lazy_instance.h"
#include "base/location.h"
E
Eric Seidel 已提交
9
#include "base/single_thread_task_runner.h"
C
Chinmay Garde 已提交
10
#include "mojo/public/cpp/application/service_provider_impl.h"
E
Eric Seidel 已提交
11
#include "sky/engine/wtf/Assertions.h"
C
Chinmay Garde 已提交
12
#include "sky/services/ns_net/network_service_impl.h"
E
Eric Seidel 已提交
13
#include "sky/shell/service_provider.h"
E
Eric Seidel 已提交
14
#if !TARGET_OS_IPHONE
E
Eric Seidel 已提交
15
#include "sky/shell/testing/test_runner.h"
E
Eric Seidel 已提交
16
#endif
C
Chinmay Garde 已提交
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

namespace sky {
namespace shell {

// FIXME(csg): Put this in an application owned context
base::LazyInstance<scoped_ptr<mojo::ServiceProviderImpl>> g_service_provider =
    LAZY_INSTANCE_INITIALIZER;
base::LazyInstance<scoped_ptr<mojo::NetworkServiceFactory>>
    g_network_service_factory = LAZY_INSTANCE_INITIALIZER;

static void CreatePlatformServiceProvider(
    mojo::InterfaceRequest<mojo::ServiceProvider> request) {
  g_service_provider.Get().reset(new mojo::ServiceProviderImpl(request.Pass()));
  g_network_service_factory.Get().reset(new mojo::NetworkServiceFactory());
  g_service_provider.Get()->AddService(g_network_service_factory.Get().get());
E
Eric Seidel 已提交
32
#if !TARGET_OS_IPHONE
E
Eric Seidel 已提交
33
  g_service_provider.Get()->AddService(&TestRunner::Shared());
E
Eric Seidel 已提交
34
#endif
C
Chinmay Garde 已提交
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
}

mojo::ServiceProviderPtr CreateServiceProvider(
    ServiceProviderContext* context) {
  DCHECK(context);
  mojo::MessagePipe pipe;
  auto request = mojo::MakeRequest<mojo::ServiceProvider>(pipe.handle1.Pass());
  context->platform_task_runner->PostTask(
      FROM_HERE,
      base::Bind(CreatePlatformServiceProvider, base::Passed(request.Pass())));
  return mojo::MakeProxy(
      mojo::InterfacePtrInfo<mojo::ServiceProvider>(pipe.handle0.Pass(), 0u));
}

}  // namespace shell
}  // namespace sky