Chromium Code Reviews| 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/bind.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 "mojo/public/cpp/application/application_connection.h" | 10 #include "mojo/public/cpp/application/application_connection.h" |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 25 #elif defined(OS_WIN) | 25 #elif defined(OS_WIN) |
| 26 *path = base::FilePath::FromUTF8Unsafe(path_as_string); | 26 *path = base::FilePath::FromUTF8Unsafe(path_as_string); |
| 27 #else | 27 #else |
| 28 #error Not implemented | 28 #error Not implemented |
| 29 #endif | 29 #endif |
| 30 } | 30 } |
| 31 | 31 |
| 32 } // namespace | 32 } // namespace |
| 33 | 33 |
| 34 class Delegate : public mojo::ApplicationDelegate { | 34 class Delegate : public mojo::ApplicationDelegate { |
| 35 typedef mojo::ContextInterfaceProvider<mojo::NetworkServiceImpl, | |
| 36 mojo::NetworkContext, | |
| 37 mojo::NetworkService> NetworkProvider; | |
| 38 | |
| 35 public: | 39 public: |
| 36 Delegate() {} | 40 Delegate() {} |
| 37 | 41 |
| 38 virtual void Initialize(mojo::ApplicationImpl* app) MOJO_OVERRIDE { | 42 virtual void Initialize(mojo::ApplicationImpl* app) MOJO_OVERRIDE { |
| 39 mojo::InterfacePtr<mojo::ProfileService> profile_service; | 43 mojo::InterfacePtr<mojo::ProfileService> profile_service; |
| 40 app->ConnectToService("mojo:profile_service", &profile_service); | 44 app->ConnectToService("mojo:profile_service", &profile_service); |
| 41 base::FilePath base_path; | 45 base::FilePath base_path; |
| 42 profile_service->GetPath(mojo::ProfileService::DIR_TEMP, | 46 profile_service->GetPath(mojo::ProfileService::DIR_TEMP, |
| 43 base::Bind(&OnPathReceived, | 47 base::Bind(&OnPathReceived, |
| 44 base::Unretained(&base_path))); | 48 base::Unretained(&base_path))); |
| 45 profile_service.WaitForIncomingMethodCall(); | 49 profile_service.WaitForIncomingMethodCall(); |
| 46 DCHECK(!base_path.value().empty()); | 50 DCHECK(!base_path.value().empty()); |
| 47 base_path = base_path.Append(FILE_PATH_LITERAL("network_service")); | 51 base_path = base_path.Append(FILE_PATH_LITERAL("network_service")); |
| 48 context_.reset(new mojo::NetworkContext(base_path)); | 52 context_.reset(new mojo::NetworkContext(base_path)); |
| 53 network_service_provider_.reset(new NetworkProvider(context_.get())); | |
| 49 } | 54 } |
| 50 | 55 |
| 56 // mojo::ApplicationDelegate implementation. | |
| 51 virtual bool ConfigureIncomingConnection( | 57 virtual bool ConfigureIncomingConnection( |
| 52 mojo::ApplicationConnection* connection) MOJO_OVERRIDE { | 58 mojo::ApplicationConnection* connection) MOJO_OVERRIDE { |
| 53 DCHECK(context_); | 59 DCHECK(context_); |
| 54 connection->AddService<mojo::NetworkServiceImpl>(context_.get()); | 60 connection->AddServiceProvider(network_service_provider_.get()); |
|
jamesr
2014/07/11 20:07:10
here, instead of implementing InterfaceProvider<>:
| |
| 55 return true; | 61 return true; |
| 56 } | 62 } |
| 57 | 63 |
| 58 private: | 64 private: |
| 59 scoped_ptr<mojo::NetworkContext> context_; | 65 scoped_ptr<mojo::NetworkContext> context_; |
| 66 scoped_ptr<NetworkProvider> network_service_provider_; | |
| 60 }; | 67 }; |
| 61 | 68 |
| 62 extern "C" APPLICATION_EXPORT MojoResult CDECL MojoMain( | 69 extern "C" APPLICATION_EXPORT MojoResult CDECL MojoMain( |
| 63 MojoHandle shell_handle) { | 70 MojoHandle shell_handle) { |
| 64 base::CommandLine::Init(0, NULL); | 71 base::CommandLine::Init(0, NULL); |
| 65 base::AtExitManager at_exit; | 72 base::AtExitManager at_exit; |
| 66 | 73 |
| 67 // The IO message loop allows us to use net::URLRequest on this thread. | 74 // The IO message loop allows us to use net::URLRequest on this thread. |
| 68 base::MessageLoopForIO loop; | 75 base::MessageLoopForIO loop; |
| 69 | 76 |
| 70 Delegate delegate; | 77 Delegate delegate; |
| 71 mojo::ApplicationImpl app( | 78 mojo::ApplicationImpl app( |
| 72 &delegate, mojo::MakeScopedHandle(mojo::MessagePipeHandle(shell_handle))); | 79 &delegate, mojo::MakeScopedHandle(mojo::MessagePipeHandle(shell_handle))); |
| 73 | 80 |
| 74 loop.Run(); | 81 loop.Run(); |
| 75 return MOJO_RESULT_OK; | 82 return MOJO_RESULT_OK; |
| 76 } | 83 } |
| OLD | NEW |