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/bind.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 "mojo/public/cpp/application/application_connection.h" | 11 #include "mojo/public/cpp/application/application_connection.h" |
11 #include "mojo/public/cpp/application/application_delegate.h" | 12 #include "mojo/public/cpp/application/application_delegate.h" |
12 #include "mojo/public/cpp/application/application_impl.h" | 13 #include "mojo/public/cpp/application/application_impl.h" |
13 #include "mojo/public/cpp/bindings/interface_ptr.h" | |
14 #include "mojo/public/interfaces/service_provider/service_provider.mojom.h" | |
15 #include "mojo/services/network/network_context.h" | 14 #include "mojo/services/network/network_context.h" |
16 #include "mojo/services/network/network_service_impl.h" | 15 #include "mojo/services/network/network_service_impl.h" |
17 #include "mojo/services/public/interfaces/profile/profile_service.mojom.h" | |
18 | |
19 namespace { | |
20 | |
21 void OnPathReceived(base::FilePath* path, const mojo::String& path_as_string) { | |
22 DCHECK(!path_as_string.is_null()); | |
23 #if defined(OS_POSIX) | |
24 *path = base::FilePath(path_as_string); | |
25 #elif defined(OS_WIN) | |
26 *path = base::FilePath::FromUTF8Unsafe(path_as_string); | |
27 #else | |
28 #error Not implemented | |
29 #endif | |
30 } | |
31 | |
32 } // namespace | |
33 | 16 |
34 class Delegate : public mojo::ApplicationDelegate { | 17 class Delegate : public mojo::ApplicationDelegate { |
35 public: | 18 public: |
36 Delegate() {} | 19 Delegate() {} |
37 | 20 |
38 virtual void Initialize(mojo::ApplicationImpl* app) MOJO_OVERRIDE { | 21 virtual void Initialize(mojo::ApplicationImpl* app) MOJO_OVERRIDE { |
39 mojo::InterfacePtr<mojo::ProfileService> profile_service; | |
40 app->ConnectToService("mojo:profile_service", &profile_service); | |
41 base::FilePath base_path; | 22 base::FilePath base_path; |
42 profile_service->GetPath( | 23 CHECK(PathService::Get(base::DIR_TEMP, &base_path)); |
43 mojo::ProfileService::PATH_KEY_DIR_TEMP, | |
44 base::Bind(&OnPathReceived, base::Unretained(&base_path))); | |
45 profile_service.WaitForIncomingMethodCall(); | |
46 DCHECK(!base_path.value().empty()); | |
47 base_path = base_path.Append(FILE_PATH_LITERAL("network_service")); | 24 base_path = base_path.Append(FILE_PATH_LITERAL("network_service")); |
48 context_.reset(new mojo::NetworkContext(base_path)); | 25 context_.reset(new mojo::NetworkContext(base_path)); |
49 } | 26 } |
50 | 27 |
51 virtual bool ConfigureIncomingConnection( | 28 virtual bool ConfigureIncomingConnection( |
52 mojo::ApplicationConnection* connection) MOJO_OVERRIDE { | 29 mojo::ApplicationConnection* connection) MOJO_OVERRIDE { |
53 DCHECK(context_); | 30 DCHECK(context_); |
54 connection->AddService<mojo::NetworkServiceImpl>(context_.get()); | 31 connection->AddService<mojo::NetworkServiceImpl>(context_.get()); |
55 return true; | 32 return true; |
56 } | 33 } |
(...skipping 12 matching lines...) Expand all Loading... |
69 // The IO message loop allows us to use net::URLRequest on this thread. | 46 // The IO message loop allows us to use net::URLRequest on this thread. |
70 base::MessageLoopForIO loop; | 47 base::MessageLoopForIO loop; |
71 | 48 |
72 Delegate delegate; | 49 Delegate delegate; |
73 mojo::ApplicationImpl app( | 50 mojo::ApplicationImpl app( |
74 &delegate, mojo::MakeScopedHandle(mojo::MessagePipeHandle(shell_handle))); | 51 &delegate, mojo::MakeScopedHandle(mojo::MessagePipeHandle(shell_handle))); |
75 | 52 |
76 loop.Run(); | 53 loop.Run(); |
77 return MOJO_RESULT_OK; | 54 return MOJO_RESULT_OK; |
78 } | 55 } |
OLD | NEW |