blob: a8db8f485733a4fed5cd047db88519201f07e47f [file] [log] [blame]
// Copyright 2014 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/base_paths.h"
#include "base/files/file_path.h"
#include "base/message_loop/message_loop.h"
#include "base/path_service.h"
#include "mojo/application/application_runner_chromium.h"
#include "mojo/public/c/system/main.h"
#include "mojo/public/cpp/application/application_connection.h"
#include "mojo/public/cpp/application/application_delegate.h"
#include "mojo/public/cpp/application/interface_factory.h"
#include "mojo/services/network/network_context.h"
#include "mojo/services/network/network_service_impl.h"
class NetworkServiceDelegate
: public mojo::ApplicationDelegate,
public mojo::InterfaceFactory<mojo::NetworkService> {
private:
void Initialize(mojo::ApplicationImpl* app) override {
base::FilePath base_path;
CHECK(PathService::Get(base::DIR_TEMP, &base_path));
base_path = base_path.Append(FILE_PATH_LITERAL("network_service"));
context_.reset(new mojo::NetworkContext(base_path));
}
// mojo::ApplicationDelegate implementation.
bool ConfigureIncomingConnection(
mojo::ApplicationConnection* connection) override {
DCHECK(context_);
connection->AddService(this);
return true;
}
// mojo::InterfaceFactory<mojo::NetworkService> implementation.
void Create(mojo::ApplicationConnection* connection,
mojo::InterfaceRequest<mojo::NetworkService> request) override {
mojo::BindToRequest(
new mojo::NetworkServiceImpl(connection, context_.get()), &request);
}
scoped_ptr<mojo::NetworkContext> context_;
};
MojoResult MojoMain(MojoHandle shell_handle) {
mojo::ApplicationRunnerChromium runner(new NetworkServiceDelegate);
runner.set_message_loop_type(base::MessageLoop::TYPE_IO);
return runner.Run(shell_handle);
}