OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "base/at_exit.h" | 5 #include "base/at_exit.h" |
6 #include "base/base_paths.h" | 6 #include "base/base_paths.h" |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
11 #include "mojo/public/cpp/application/application_connection.h" | 11 #include "mojo/public/cpp/application/application_connection.h" |
12 #include "mojo/public/cpp/application/application_delegate.h" | 12 #include "mojo/public/cpp/application/application_delegate.h" |
13 #include "mojo/public/cpp/application/application_impl.h" | 13 #include "mojo/public/cpp/application/application_impl.h" |
| 14 #include "mojo/public/cpp/bindings/interface_factory_with_context.h" |
| 15 #include "mojo/public/cpp/bindings/interface_ptr.h" |
| 16 #include "mojo/public/interfaces/service_provider/service_provider.mojom.h" |
14 #include "mojo/services/network/network_context.h" | 17 #include "mojo/services/network/network_context.h" |
15 #include "mojo/services/network/network_service_impl.h" | 18 #include "mojo/services/network/network_service_impl.h" |
16 | 19 |
17 class Delegate : public mojo::ApplicationDelegate { | 20 class Delegate : public mojo::ApplicationDelegate { |
| 21 typedef mojo::InterfaceFactoryWithContext<mojo::NetworkServiceImpl, |
| 22 mojo::NetworkContext> |
| 23 NetworkFactory; |
| 24 |
18 public: | 25 public: |
19 Delegate() {} | 26 Delegate() {} |
20 | 27 |
21 virtual void Initialize(mojo::ApplicationImpl* app) MOJO_OVERRIDE { | 28 virtual void Initialize(mojo::ApplicationImpl* app) MOJO_OVERRIDE { |
22 base::FilePath base_path; | 29 base::FilePath base_path; |
23 CHECK(PathService::Get(base::DIR_TEMP, &base_path)); | 30 CHECK(PathService::Get(base::DIR_TEMP, &base_path)); |
24 base_path = base_path.Append(FILE_PATH_LITERAL("network_service")); | 31 base_path = base_path.Append(FILE_PATH_LITERAL("network_service")); |
25 context_.reset(new mojo::NetworkContext(base_path)); | 32 context_.reset(new mojo::NetworkContext(base_path)); |
| 33 network_service_factory_.reset(new NetworkFactory(context_.get())); |
26 } | 34 } |
27 | 35 |
| 36 // mojo::ApplicationDelegate implementation. |
28 virtual bool ConfigureIncomingConnection( | 37 virtual bool ConfigureIncomingConnection( |
29 mojo::ApplicationConnection* connection) MOJO_OVERRIDE { | 38 mojo::ApplicationConnection* connection) MOJO_OVERRIDE { |
30 DCHECK(context_); | 39 DCHECK(context_); |
31 connection->AddService<mojo::NetworkServiceImpl>(context_.get()); | 40 connection->AddService(network_service_factory_.get()); |
32 return true; | 41 return true; |
33 } | 42 } |
34 | 43 |
35 private: | 44 private: |
36 scoped_ptr<mojo::NetworkContext> context_; | 45 scoped_ptr<mojo::NetworkContext> context_; |
| 46 scoped_ptr<NetworkFactory> network_service_factory_; |
37 }; | 47 }; |
38 | 48 |
39 extern "C" APPLICATION_EXPORT MojoResult CDECL MojoMain( | 49 extern "C" APPLICATION_EXPORT MojoResult CDECL MojoMain( |
40 MojoHandle shell_handle) { | 50 MojoHandle shell_handle) { |
41 base::CommandLine::Init(0, NULL); | 51 base::CommandLine::Init(0, NULL); |
42 #if !defined(COMPONENT_BUILD) | 52 #if !defined(COMPONENT_BUILD) |
43 base::AtExitManager at_exit; | 53 base::AtExitManager at_exit; |
44 #endif | 54 #endif |
45 | 55 |
46 // The IO message loop allows us to use net::URLRequest on this thread. | 56 // The IO message loop allows us to use net::URLRequest on this thread. |
47 base::MessageLoopForIO loop; | 57 base::MessageLoopForIO loop; |
48 | 58 |
49 Delegate delegate; | 59 Delegate delegate; |
50 mojo::ApplicationImpl app( | 60 mojo::ApplicationImpl app( |
51 &delegate, mojo::MakeScopedHandle(mojo::MessagePipeHandle(shell_handle))); | 61 &delegate, mojo::MakeScopedHandle(mojo::MessagePipeHandle(shell_handle))); |
52 | 62 |
53 loop.Run(); | 63 loop.Run(); |
54 return MOJO_RESULT_OK; | 64 return MOJO_RESULT_OK; |
55 } | 65 } |
OLD | NEW |