Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(95)

Side by Side Diff: mojo/services/network/main.cc

Issue 380413003: Mojo: Use InterfaceFactory<Interface> for service registration (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix network_service_loader Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/application/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 public mojo::InterfaceFactory<mojo::NetworkService> {
18 public: 22 public:
19 Delegate() {} 23 Delegate() {}
20 24
21 virtual void Initialize(mojo::ApplicationImpl* app) MOJO_OVERRIDE { 25 virtual void Initialize(mojo::ApplicationImpl* app) OVERRIDE {
22 base::FilePath base_path; 26 base::FilePath base_path;
23 CHECK(PathService::Get(base::DIR_TEMP, &base_path)); 27 CHECK(PathService::Get(base::DIR_TEMP, &base_path));
24 base_path = base_path.Append(FILE_PATH_LITERAL("network_service")); 28 base_path = base_path.Append(FILE_PATH_LITERAL("network_service"));
25 context_.reset(new mojo::NetworkContext(base_path)); 29 context_.reset(new mojo::NetworkContext(base_path));
26 } 30 }
27 31
32 // mojo::ApplicationDelegate implementation.
28 virtual bool ConfigureIncomingConnection( 33 virtual bool ConfigureIncomingConnection(
29 mojo::ApplicationConnection* connection) MOJO_OVERRIDE { 34 mojo::ApplicationConnection* connection) OVERRIDE {
30 DCHECK(context_); 35 DCHECK(context_);
31 connection->AddService<mojo::NetworkServiceImpl>(context_.get()); 36 connection->AddService(this);
32 return true; 37 return true;
33 } 38 }
34 39
40 // mojo::InterfaceFactory<mojo::NetworkService> implementation.
41 virtual void Create(
42 mojo::ApplicationConnection* connection,
43 mojo::InterfaceRequest<mojo::NetworkService> request) OVERRIDE {
44 mojo::BindToRequest(
45 new mojo::NetworkServiceImpl(connection, context_.get()), &request);
46 }
47
35 private: 48 private:
36 scoped_ptr<mojo::NetworkContext> context_; 49 scoped_ptr<mojo::NetworkContext> context_;
37 }; 50 };
38 51
39 extern "C" APPLICATION_EXPORT MojoResult CDECL MojoMain( 52 extern "C" APPLICATION_EXPORT MojoResult CDECL MojoMain(
40 MojoHandle shell_handle) { 53 MojoHandle shell_handle) {
41 base::CommandLine::Init(0, NULL); 54 base::CommandLine::Init(0, NULL);
42 #if !defined(COMPONENT_BUILD) 55 #if !defined(COMPONENT_BUILD)
43 base::AtExitManager at_exit; 56 base::AtExitManager at_exit;
44 #endif 57 #endif
(...skipping 10 matching lines...) Expand all
55 base::MessageLoopForIO loop; 68 base::MessageLoopForIO loop;
56 69
57 mojo::ApplicationImpl app( 70 mojo::ApplicationImpl app(
58 &delegate, 71 &delegate,
59 mojo::MakeScopedHandle(mojo::MessagePipeHandle(shell_handle))); 72 mojo::MakeScopedHandle(mojo::MessagePipeHandle(shell_handle)));
60 73
61 loop.Run(); 74 loop.Run();
62 } 75 }
63 return MOJO_RESULT_OK; 76 return MOJO_RESULT_OK;
64 } 77 }
OLDNEW
« no previous file with comments | « mojo/services/native_viewport/native_viewport_service.cc ('k') | mojo/services/network/url_loader_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698