Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / mojo / services / network / network_service.cc
blob015a5fc181e24826d854eedc0f7c90fa8ecc95b9
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/at_exit.h"
6 #include "base/base_paths.h"
7 #include "base/command_line.h"
8 #include "base/files/file_path.h"
9 #include "base/message_loop/message_loop.h"
10 #include "base/path_service.h"
11 #include "mojo/application/application_runner_chromium.h"
12 #include "mojo/services/network/network_context.h"
13 #include "mojo/services/network/network_service_impl.h"
14 #include "third_party/mojo/src/mojo/public/c/system/main.h"
15 #include "third_party/mojo/src/mojo/public/cpp/application/application_connection.h"
16 #include "third_party/mojo/src/mojo/public/cpp/application/application_delegate.h"
17 #include "third_party/mojo/src/mojo/public/cpp/application/interface_factory.h"
18 #include "third_party/mojo/src/mojo/public/cpp/bindings/interface_ptr.h"
20 class NetworkServiceDelegate
21 : public mojo::ApplicationDelegate,
22 public mojo::InterfaceFactory<mojo::NetworkService> {
23 private:
24 void Initialize(mojo::ApplicationImpl* app) override {
25 base::FilePath base_path;
26 CHECK(PathService::Get(base::DIR_TEMP, &base_path));
27 base_path = base_path.Append(FILE_PATH_LITERAL("network_service"));
28 context_.reset(new mojo::NetworkContext(base_path));
31 // mojo::ApplicationDelegate implementation.
32 bool ConfigureIncomingConnection(
33 mojo::ApplicationConnection* connection) override {
34 DCHECK(context_);
35 connection->AddService(this);
36 return true;
39 void Quit() override {
40 // Destroy the NetworkContext now as it requires MessageLoop::current() upon
41 // destruction and it is the last moment we know for sure that it is
42 // running.
43 context_.reset();
46 // mojo::InterfaceFactory<mojo::NetworkService> implementation.
47 void Create(mojo::ApplicationConnection* connection,
48 mojo::InterfaceRequest<mojo::NetworkService> request) override {
49 mojo::BindToRequest(
50 new mojo::NetworkServiceImpl(connection, context_.get()), &request);
53 private:
54 scoped_ptr<mojo::NetworkContext> context_;
57 MojoResult MojoMain(MojoHandle shell_handle) {
58 mojo::ApplicationRunnerChromium runner(new NetworkServiceDelegate);
59 runner.set_message_loop_type(base::MessageLoop::TYPE_IO);
60 return runner.Run(shell_handle);