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 "mojo/services/network/network_service_delegate.h"
7 #include "base/at_exit.h"
8 #include "base/base_paths.h"
9 #include "base/files/file_path.h"
10 #include "base/message_loop/message_loop.h"
11 #include "base/path_service.h"
12 #include "mojo/application/public/cpp/application_connection.h"
13 #include "mojo/services/network/network_service_impl.h"
14 #include "mojo/services/network/url_loader_factory_impl.h"
16 NetworkServiceDelegate::NetworkServiceDelegate() : app_(nullptr) {}
18 NetworkServiceDelegate::~NetworkServiceDelegate() {}
20 void NetworkServiceDelegate::Initialize(mojo::ApplicationImpl
* app
) {
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 bool NetworkServiceDelegate::ConfigureIncomingConnection(
29 mojo::ApplicationConnection
* connection
) {
31 connection
->AddService
<mojo::NetworkService
>(this);
32 connection
->AddService
<mojo::URLLoaderFactory
>(this);
36 void NetworkServiceDelegate::Quit() {
37 // Destroy the NetworkContext now as it requires MessageLoop::current() upon
38 // destruction and it is the last moment we know for sure that it is
43 void NetworkServiceDelegate::Create(
44 mojo::ApplicationConnection
* connection
,
45 mojo::InterfaceRequest
<mojo::NetworkService
> request
) {
46 new mojo::NetworkServiceImpl(
49 app_
->app_lifetime_helper()->CreateAppRefCount(),
53 void NetworkServiceDelegate::Create(
54 mojo::ApplicationConnection
* connection
,
55 mojo::InterfaceRequest
<mojo::URLLoaderFactory
> request
) {
56 new mojo::URLLoaderFactoryImpl(
59 app_
->app_lifetime_helper()->CreateAppRefCount(),