1 // Copyright 2014 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 "base/base_paths.h"
6 #include "base/files/file_path.h"
7 #include "base/message_loop/message_loop.h"
8 #include "base/path_service.h"
9 #include "mojo/application/application_runner_chromium.h"
10 #include "mojo/public/c/system/main.h"
11 #include "mojo/public/cpp/application/application_connection.h"
12 #include "mojo/public/cpp/application/application_delegate.h"
13 #include "mojo/public/cpp/application/interface_factory.h"
14 #include "mojo/services/network/network_context.h"
15 #include "mojo/services/network/network_service_impl.h"
17 class NetworkServiceDelegate
18 : public mojo::ApplicationDelegate
,
19 public mojo::InterfaceFactory
<mojo::NetworkService
> {
21 void Initialize(mojo::ApplicationImpl
* app
) override
{
22 base::FilePath base_path
;
23 CHECK(PathService::Get(base::DIR_TEMP
, &base_path
));
24 base_path
= base_path
.Append(FILE_PATH_LITERAL("network_service"));
25 context_
.reset(new mojo::NetworkContext(base_path
));
28 // mojo::ApplicationDelegate implementation.
29 bool ConfigureIncomingConnection(
30 mojo::ApplicationConnection
* connection
) override
{
32 connection
->AddService(this);
36 // mojo::InterfaceFactory<mojo::NetworkService> implementation.
37 void Create(mojo::ApplicationConnection
* connection
,
38 mojo::InterfaceRequest
<mojo::NetworkService
> request
) override
{
40 new mojo::NetworkServiceImpl(connection
, context_
.get()), &request
);
43 scoped_ptr
<mojo::NetworkContext
> context_
;
46 MojoResult
MojoMain(MojoHandle shell_handle
) {
47 mojo::ApplicationRunnerChromium
runner(new NetworkServiceDelegate
);
48 runner
.set_message_loop_type(base::MessageLoop::TYPE_IO
);
49 return runner
.Run(shell_handle
);