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

Side by Side Diff: content/browser/mojo/mojo_application_host.cc

Issue 1585493002: [mojo] Ports EDK (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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
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 "content/browser/mojo/mojo_application_host.h" 5 #include "content/browser/mojo/mojo_application_host.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "build/build_config.h" 9 #include "build/build_config.h"
10 #include "content/common/mojo/mojo_messages.h" 10 #include "content/common/mojo/mojo_messages.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 service_registry_->BindRemoteServiceProvider(std::move(exposed_services)); 43 service_registry_->BindRemoteServiceProvider(std::move(exposed_services));
44 } 44 }
45 45
46 mojo::Binding<ApplicationSetup> binding_; 46 mojo::Binding<ApplicationSetup> binding_;
47 ServiceRegistryImpl* service_registry_; 47 ServiceRegistryImpl* service_registry_;
48 }; 48 };
49 49
50 } // namespace 50 } // namespace
51 51
52 MojoApplicationHost::MojoApplicationHost() 52 MojoApplicationHost::MojoApplicationHost()
53 : did_activate_(false) { 53 : did_activate_(false), weak_factory_(this) {
54 #if defined(OS_ANDROID) 54 #if defined(OS_ANDROID)
55 service_registry_android_.reset( 55 service_registry_android_.reset(
56 new ServiceRegistryAndroid(&service_registry_)); 56 new ServiceRegistryAndroid(&service_registry_));
57 #endif 57 #endif
58 } 58 }
59 59
60 MojoApplicationHost::~MojoApplicationHost() { 60 MojoApplicationHost::~MojoApplicationHost() {
61 } 61 }
62 62
63 bool MojoApplicationHost::Init() { 63 bool MojoApplicationHost::Init() {
64 DCHECK(!client_handle_.is_valid()) << "Already initialized!"; 64 DCHECK(!client_handle_.is_valid()) << "Already initialized!";
65 65
66 mojo::embedder::PlatformChannelPair channel_pair; 66 mojo::embedder::PlatformChannelPair channel_pair;
67 67
68 scoped_refptr<base::TaskRunner> io_task_runner; 68 scoped_refptr<base::TaskRunner> io_task_runner;
69 if (io_task_runner_override_) { 69 if (io_task_runner_override_) {
70 io_task_runner = io_task_runner_override_; 70 io_task_runner = io_task_runner_override_;
71 } else { 71 } else {
72 io_task_runner = 72 io_task_runner =
73 BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO) 73 BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO)
74 ->task_runner(); 74 ->task_runner();
75 } 75 }
76 76
77 mojo::ScopedMessagePipeHandle message_pipe = channel_init_.Init(
78 PlatformFileFromScopedPlatformHandle(channel_pair.PassServerHandle()),
79 io_task_runner);
80 if (!message_pipe.is_valid())
81 return false;
82
83 // Forward this to the client once we know its process handle. 77 // Forward this to the client once we know its process handle.
84 client_handle_ = channel_pair.PassClientHandle(); 78 client_handle_ = channel_pair.PassClientHandle();
85 79
86 application_setup_.reset(new ApplicationSetupImpl( 80 channel_init_.Init(
87 &service_registry_, 81 PlatformFileFromScopedPlatformHandle(channel_pair.PassServerHandle()),
88 mojo::MakeRequest<ApplicationSetup>(std::move(message_pipe)))); 82 io_task_runner,
83 base::Bind(&MojoApplicationHost::OnMessagePipeCreated,
84 weak_factory_.GetWeakPtr()));
85
89 return true; 86 return true;
90 } 87 }
91 88
92 void MojoApplicationHost::Activate(IPC::Sender* sender, 89 void MojoApplicationHost::Activate(IPC::Sender* sender,
93 base::ProcessHandle process_handle) { 90 base::ProcessHandle process_handle) {
94 DCHECK(!did_activate_); 91 DCHECK(!did_activate_);
95 DCHECK(client_handle_.is_valid()); 92 DCHECK(client_handle_.is_valid());
96 93
97 base::PlatformFile client_file = 94 base::PlatformFile client_file =
98 PlatformFileFromScopedPlatformHandle(std::move(client_handle_)); 95 PlatformFileFromScopedPlatformHandle(std::move(client_handle_));
99 did_activate_ = sender->Send(new MojoMsg_Activate( 96 did_activate_ = sender->Send(new MojoMsg_Activate(
100 IPC::GetFileHandleForProcess(client_file, process_handle, true))); 97 IPC::GetFileHandleForProcess(client_file, process_handle, true)));
101 } 98 }
102 99
103 void MojoApplicationHost::WillDestroySoon() { 100 void MojoApplicationHost::WillDestroySoon() {
104 channel_init_.WillDestroySoon(); 101 channel_init_.WillDestroySoon();
105 } 102 }
106 103
107 void MojoApplicationHost::OverrideIOTaskRunnerForTest( 104 void MojoApplicationHost::OverrideIOTaskRunnerForTest(
108 scoped_refptr<base::TaskRunner> io_task_runner) { 105 scoped_refptr<base::TaskRunner> io_task_runner) {
109 io_task_runner_override_ = io_task_runner; 106 io_task_runner_override_ = io_task_runner;
110 } 107 }
111 108
109 void MojoApplicationHost::OnMessagePipeCreated(
110 mojo::ScopedMessagePipeHandle pipe) {
111 DCHECK(pipe.is_valid());
112 application_setup_.reset(new ApplicationSetupImpl(
113 &service_registry_,
114 mojo::MakeRequest<ApplicationSetup>(std::move(pipe))));
115 }
116
112 } // namespace content 117 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698