| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "mojo/services/network/network_service_delegate.h" | 5 #include "mojo/services/network/network_service_delegate.h" |
| 6 | 6 |
| 7 #include "base/at_exit.h" | 7 #include "base/at_exit.h" |
| 8 #include "base/base_paths.h" | 8 #include "base/base_paths.h" |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
| 12 #include "mojo/application/public/cpp/application_connection.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" |
| 13 | 15 |
| 14 NetworkServiceDelegate::NetworkServiceDelegate() : app_(nullptr) {} | 16 NetworkServiceDelegate::NetworkServiceDelegate() : app_(nullptr) {} |
| 15 | 17 |
| 16 NetworkServiceDelegate::~NetworkServiceDelegate() {} | 18 NetworkServiceDelegate::~NetworkServiceDelegate() {} |
| 17 | 19 |
| 18 void NetworkServiceDelegate::Initialize(mojo::ApplicationImpl* app) { | 20 void NetworkServiceDelegate::Initialize(mojo::ApplicationImpl* app) { |
| 19 app_ = app; | 21 app_ = app; |
| 20 base::FilePath base_path; | 22 base::FilePath base_path; |
| 21 CHECK(PathService::Get(base::DIR_TEMP, &base_path)); | 23 CHECK(PathService::Get(base::DIR_TEMP, &base_path)); |
| 22 base_path = base_path.Append(FILE_PATH_LITERAL("network_service")); | 24 base_path = base_path.Append(FILE_PATH_LITERAL("network_service")); |
| 23 context_.reset(new mojo::NetworkContext(base_path)); | 25 context_.reset(new mojo::NetworkContext(base_path)); |
| 24 } | 26 } |
| 25 | 27 |
| 26 bool NetworkServiceDelegate::ConfigureIncomingConnection( | 28 bool NetworkServiceDelegate::ConfigureIncomingConnection( |
| 27 mojo::ApplicationConnection* connection) { | 29 mojo::ApplicationConnection* connection) { |
| 28 DCHECK(context_); | 30 DCHECK(context_); |
| 29 connection->AddService(this); | 31 connection->AddService<mojo::NetworkService>(this); |
| 32 connection->AddService<mojo::URLLoaderFactory>(this); |
| 30 return true; | 33 return true; |
| 31 } | 34 } |
| 32 | 35 |
| 33 void NetworkServiceDelegate::Quit() { | 36 void NetworkServiceDelegate::Quit() { |
| 34 // Destroy the NetworkContext now as it requires MessageLoop::current() upon | 37 // Destroy the NetworkContext now as it requires MessageLoop::current() upon |
| 35 // destruction and it is the last moment we know for sure that it is | 38 // destruction and it is the last moment we know for sure that it is |
| 36 // running. | 39 // running. |
| 37 context_.reset(); | 40 context_.reset(); |
| 38 } | 41 } |
| 39 | 42 |
| 40 void NetworkServiceDelegate::Create( | 43 void NetworkServiceDelegate::Create( |
| 41 mojo::ApplicationConnection* connection, | 44 mojo::ApplicationConnection* connection, |
| 42 mojo::InterfaceRequest<mojo::NetworkService> request) { | 45 mojo::InterfaceRequest<mojo::NetworkService> request) { |
| 43 new mojo::NetworkServiceImpl( | 46 new mojo::NetworkServiceImpl( |
| 44 connection, | 47 connection, |
| 45 context_.get(), | 48 context_.get(), |
| 46 app_->app_lifetime_helper()->CreateAppRefCount(), | 49 app_->app_lifetime_helper()->CreateAppRefCount(), |
| 47 request.Pass()); | 50 request.Pass()); |
| 48 } | 51 } |
| 52 |
| 53 void NetworkServiceDelegate::Create( |
| 54 mojo::ApplicationConnection* connection, |
| 55 mojo::InterfaceRequest<mojo::URLLoaderFactory> request) { |
| 56 new mojo::URLLoaderFactoryImpl( |
| 57 connection, |
| 58 context_.get(), |
| 59 app_->app_lifetime_helper()->CreateAppRefCount(), |
| 60 request.Pass()); |
| 61 } |
| OLD | NEW |