| 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 13 matching lines...) Expand all Loading... |
| 24 *path = base::FilePath(path_as_string); | 24 *path = base::FilePath(path_as_string); |
| 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 public mojo::InterfaceProvider<mojo::NetworkService> { |
| 35 public: | 36 public: |
| 36 Delegate() {} | 37 Delegate() {} |
| 37 | 38 |
| 38 virtual void Initialize(mojo::ApplicationImpl* app) MOJO_OVERRIDE { | 39 virtual void Initialize(mojo::ApplicationImpl* app) MOJO_OVERRIDE { |
| 39 mojo::InterfacePtr<mojo::ProfileService> profile_service; | 40 mojo::InterfacePtr<mojo::ProfileService> profile_service; |
| 40 app->ConnectToService("mojo:profile_service", &profile_service); | 41 app->ConnectToService("mojo:profile_service", &profile_service); |
| 41 base::FilePath base_path; | 42 base::FilePath base_path; |
| 42 profile_service->GetPath(mojo::ProfileService::DIR_TEMP, | 43 profile_service->GetPath(mojo::ProfileService::DIR_TEMP, |
| 43 base::Bind(&OnPathReceived, | 44 base::Bind(&OnPathReceived, |
| 44 base::Unretained(&base_path))); | 45 base::Unretained(&base_path))); |
| 45 profile_service.WaitForIncomingMethodCall(); | 46 profile_service.WaitForIncomingMethodCall(); |
| 46 DCHECK(!base_path.value().empty()); | 47 DCHECK(!base_path.value().empty()); |
| 47 base_path = base_path.Append(FILE_PATH_LITERAL("network_service")); | 48 base_path = base_path.Append(FILE_PATH_LITERAL("network_service")); |
| 48 context_.reset(new mojo::NetworkContext(base_path)); | 49 context_.reset(new mojo::NetworkContext(base_path)); |
| 49 } | 50 } |
| 50 | 51 |
| 52 // mojo::ApplicationDelegate implementation. |
| 51 virtual bool ConfigureIncomingConnection( | 53 virtual bool ConfigureIncomingConnection( |
| 52 mojo::ApplicationConnection* connection) MOJO_OVERRIDE { | 54 mojo::ApplicationConnection* connection) MOJO_OVERRIDE { |
| 53 DCHECK(context_); | 55 DCHECK(context_); |
| 54 connection->AddService<mojo::NetworkServiceImpl>(context_.get()); | 56 connection->AddServiceProvider(this); |
| 55 return true; | 57 return true; |
| 56 } | 58 } |
| 57 | 59 |
| 60 // mojo::InterfaceProvider<mojo::NetworkService> implementation. |
| 61 virtual void BindToRequest( |
| 62 mojo::ApplicationConnection* connection, |
| 63 mojo::InterfaceRequest<mojo::NetworkService> request) MOJO_OVERRIDE { |
| 64 mojo::BindToRequest(new mojo::NetworkServiceImpl(context_.get()), &request); |
| 65 } |
| 66 |
| 58 private: | 67 private: |
| 59 scoped_ptr<mojo::NetworkContext> context_; | 68 scoped_ptr<mojo::NetworkContext> context_; |
| 60 }; | 69 }; |
| 61 | 70 |
| 62 extern "C" APPLICATION_EXPORT MojoResult CDECL MojoMain( | 71 extern "C" APPLICATION_EXPORT MojoResult CDECL MojoMain( |
| 63 MojoHandle shell_handle) { | 72 MojoHandle shell_handle) { |
| 64 base::CommandLine::Init(0, NULL); | 73 base::CommandLine::Init(0, NULL); |
| 65 base::AtExitManager at_exit; | 74 base::AtExitManager at_exit; |
| 66 | 75 |
| 67 // The IO message loop allows us to use net::URLRequest on this thread. | 76 // The IO message loop allows us to use net::URLRequest on this thread. |
| 68 base::MessageLoopForIO loop; | 77 base::MessageLoopForIO loop; |
| 69 | 78 |
| 70 Delegate delegate; | 79 Delegate delegate; |
| 71 mojo::ApplicationImpl app( | 80 mojo::ApplicationImpl app( |
| 72 &delegate, mojo::MakeScopedHandle(mojo::MessagePipeHandle(shell_handle))); | 81 &delegate, mojo::MakeScopedHandle(mojo::MessagePipeHandle(shell_handle))); |
| 73 | 82 |
| 74 loop.Run(); | 83 loop.Run(); |
| 75 return MOJO_RESULT_OK; | 84 return MOJO_RESULT_OK; |
| 76 } | 85 } |
| OLD | NEW |