| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/renderer/render_thread_impl.h" | 5 #include "content/renderer/render_thread_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 return; | 363 return; |
| 364 isolate->LowMemoryNotification(); | 364 isolate->LowMemoryNotification(); |
| 365 } | 365 } |
| 366 | 366 |
| 367 class RenderFrameSetupImpl : public RenderFrameSetup { | 367 class RenderFrameSetupImpl : public RenderFrameSetup { |
| 368 public: | 368 public: |
| 369 explicit RenderFrameSetupImpl( | 369 explicit RenderFrameSetupImpl( |
| 370 mojo::InterfaceRequest<RenderFrameSetup> request) | 370 mojo::InterfaceRequest<RenderFrameSetup> request) |
| 371 : routing_id_highmark_(-1), binding_(this, std::move(request)) {} | 371 : routing_id_highmark_(-1), binding_(this, std::move(request)) {} |
| 372 | 372 |
| 373 void ExchangeServiceProviders( | 373 void ExchangeInterfaceProviders( |
| 374 int32_t frame_routing_id, | 374 int32_t frame_routing_id, |
| 375 mojo::InterfaceRequest<mojo::ServiceProvider> services, | 375 mojo::InterfaceRequest<mojo::InterfaceProvider> services, |
| 376 mojo::ServiceProviderPtr exposed_services) | 376 mojo::InterfaceProviderPtr exposed_services) |
| 377 override { | 377 override { |
| 378 // TODO(morrita): This is for investigating http://crbug.com/415059 and | 378 // TODO(morrita): This is for investigating http://crbug.com/415059 and |
| 379 // should be removed once it is fixed. | 379 // should be removed once it is fixed. |
| 380 CHECK_LT(routing_id_highmark_, frame_routing_id); | 380 CHECK_LT(routing_id_highmark_, frame_routing_id); |
| 381 routing_id_highmark_ = frame_routing_id; | 381 routing_id_highmark_ = frame_routing_id; |
| 382 | 382 |
| 383 RenderFrameImpl* frame = RenderFrameImpl::FromRoutingID(frame_routing_id); | 383 RenderFrameImpl* frame = RenderFrameImpl::FromRoutingID(frame_routing_id); |
| 384 // We can receive a GetServiceProviderForFrame message for a frame not yet | 384 // We can receive a GetServiceProviderForFrame message for a frame not yet |
| 385 // created due to a race between the message and a ViewMsg_New IPC that | 385 // created due to a race between the message and a ViewMsg_New IPC that |
| 386 // triggers creation of the RenderFrame we want. | 386 // triggers creation of the RenderFrame we want. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 407 blink::WebGraphicsContext3D::Attributes attributes; | 407 blink::WebGraphicsContext3D::Attributes attributes; |
| 408 attributes.shareResources = true; | 408 attributes.shareResources = true; |
| 409 attributes.depth = false; | 409 attributes.depth = false; |
| 410 attributes.stencil = false; | 410 attributes.stencil = false; |
| 411 attributes.antialias = false; | 411 attributes.antialias = false; |
| 412 attributes.noAutomaticFlushes = true; | 412 attributes.noAutomaticFlushes = true; |
| 413 return attributes; | 413 return attributes; |
| 414 } | 414 } |
| 415 | 415 |
| 416 void SetupEmbeddedWorkerOnWorkerThread( | 416 void SetupEmbeddedWorkerOnWorkerThread( |
| 417 mojo::InterfaceRequest<mojo::ServiceProvider> services, | 417 mojo::InterfaceRequest<mojo::InterfaceProvider> services, |
| 418 mojo::InterfacePtrInfo<mojo::ServiceProvider> exposed_services) { | 418 mojo::InterfacePtrInfo<mojo::InterfaceProvider> exposed_services) { |
| 419 ServiceWorkerContextClient* client = | 419 ServiceWorkerContextClient* client = |
| 420 ServiceWorkerContextClient::ThreadSpecificInstance(); | 420 ServiceWorkerContextClient::ThreadSpecificInstance(); |
| 421 // It is possible for client to be null if for some reason the worker died | 421 // It is possible for client to be null if for some reason the worker died |
| 422 // before this call made it to the worker thread. In that case just do | 422 // before this call made it to the worker thread. In that case just do |
| 423 // nothing and let mojo close the connection. | 423 // nothing and let mojo close the connection. |
| 424 if (!client) | 424 if (!client) |
| 425 return; | 425 return; |
| 426 client->BindServiceRegistry(std::move(services), | 426 client->BindServiceRegistry(std::move(services), |
| 427 mojo::MakeProxy(std::move(exposed_services))); | 427 mojo::MakeProxy(std::move(exposed_services))); |
| 428 } | 428 } |
| 429 | 429 |
| 430 class EmbeddedWorkerSetupImpl : public EmbeddedWorkerSetup { | 430 class EmbeddedWorkerSetupImpl : public EmbeddedWorkerSetup { |
| 431 public: | 431 public: |
| 432 explicit EmbeddedWorkerSetupImpl( | 432 explicit EmbeddedWorkerSetupImpl( |
| 433 mojo::InterfaceRequest<EmbeddedWorkerSetup> request) | 433 mojo::InterfaceRequest<EmbeddedWorkerSetup> request) |
| 434 : binding_(this, std::move(request)) {} | 434 : binding_(this, std::move(request)) {} |
| 435 | 435 |
| 436 void ExchangeServiceProviders( | 436 void ExchangeInterfaceProviders( |
| 437 int32_t thread_id, | 437 int32_t thread_id, |
| 438 mojo::InterfaceRequest<mojo::ServiceProvider> services, | 438 mojo::InterfaceRequest<mojo::InterfaceProvider> services, |
| 439 mojo::ServiceProviderPtr exposed_services) override { | 439 mojo::InterfaceProviderPtr exposed_services) override { |
| 440 WorkerThreadRegistry::Instance()->GetTaskRunnerFor(thread_id)->PostTask( | 440 WorkerThreadRegistry::Instance()->GetTaskRunnerFor(thread_id)->PostTask( |
| 441 FROM_HERE, | 441 FROM_HERE, |
| 442 base::Bind(&SetupEmbeddedWorkerOnWorkerThread, base::Passed(&services), | 442 base::Bind(&SetupEmbeddedWorkerOnWorkerThread, base::Passed(&services), |
| 443 base::Passed(exposed_services.PassInterface()))); | 443 base::Passed(exposed_services.PassInterface()))); |
| 444 } | 444 } |
| 445 | 445 |
| 446 private: | 446 private: |
| 447 mojo::StrongBinding<EmbeddedWorkerSetup> binding_; | 447 mojo::StrongBinding<EmbeddedWorkerSetup> binding_; |
| 448 }; | 448 }; |
| 449 | 449 |
| (...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1080 PendingRenderFrameConnectMap::iterator it = | 1080 PendingRenderFrameConnectMap::iterator it = |
| 1081 pending_render_frame_connects_.find(routing_id); | 1081 pending_render_frame_connects_.find(routing_id); |
| 1082 if (it == pending_render_frame_connects_.end()) | 1082 if (it == pending_render_frame_connects_.end()) |
| 1083 return; | 1083 return; |
| 1084 | 1084 |
| 1085 RenderFrameImpl* frame = RenderFrameImpl::FromRoutingID(routing_id); | 1085 RenderFrameImpl* frame = RenderFrameImpl::FromRoutingID(routing_id); |
| 1086 if (!frame) | 1086 if (!frame) |
| 1087 return; | 1087 return; |
| 1088 | 1088 |
| 1089 scoped_refptr<PendingRenderFrameConnect> connection(it->second); | 1089 scoped_refptr<PendingRenderFrameConnect> connection(it->second); |
| 1090 mojo::InterfaceRequest<mojo::ServiceProvider> services( | 1090 mojo::InterfaceRequest<mojo::InterfaceProvider> services( |
| 1091 std::move(connection->services())); | 1091 std::move(connection->services())); |
| 1092 mojo::ServiceProviderPtr exposed_services( | 1092 mojo::InterfaceProviderPtr exposed_services( |
| 1093 std::move(connection->exposed_services())); | 1093 std::move(connection->exposed_services())); |
| 1094 exposed_services.set_connection_error_handler(mojo::Closure()); | 1094 exposed_services.set_connection_error_handler(mojo::Closure()); |
| 1095 pending_render_frame_connects_.erase(it); | 1095 pending_render_frame_connects_.erase(it); |
| 1096 | 1096 |
| 1097 frame->BindServiceRegistry(std::move(services), std::move(exposed_services)); | 1097 frame->BindServiceRegistry(std::move(services), std::move(exposed_services)); |
| 1098 } | 1098 } |
| 1099 | 1099 |
| 1100 void RenderThreadImpl::RemoveRoute(int32_t routing_id) { | 1100 void RenderThreadImpl::RemoveRoute(int32_t routing_id) { |
| 1101 ChildThreadImpl::GetRouter()->RemoveRoute(routing_id); | 1101 ChildThreadImpl::GetRouter()->RemoveRoute(routing_id); |
| 1102 } | 1102 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1113 void RenderThreadImpl::RemoveEmbeddedWorkerRoute(int32_t routing_id) { | 1113 void RenderThreadImpl::RemoveEmbeddedWorkerRoute(int32_t routing_id) { |
| 1114 RemoveRoute(routing_id); | 1114 RemoveRoute(routing_id); |
| 1115 if (devtools_agent_message_filter_.get()) { | 1115 if (devtools_agent_message_filter_.get()) { |
| 1116 devtools_agent_message_filter_->RemoveEmbeddedWorkerRouteOnMainThread( | 1116 devtools_agent_message_filter_->RemoveEmbeddedWorkerRouteOnMainThread( |
| 1117 routing_id); | 1117 routing_id); |
| 1118 } | 1118 } |
| 1119 } | 1119 } |
| 1120 | 1120 |
| 1121 void RenderThreadImpl::RegisterPendingRenderFrameConnect( | 1121 void RenderThreadImpl::RegisterPendingRenderFrameConnect( |
| 1122 int routing_id, | 1122 int routing_id, |
| 1123 mojo::InterfaceRequest<mojo::ServiceProvider> services, | 1123 mojo::InterfaceRequest<mojo::InterfaceProvider> services, |
| 1124 mojo::ServiceProviderPtr exposed_services) { | 1124 mojo::InterfaceProviderPtr exposed_services) { |
| 1125 std::pair<PendingRenderFrameConnectMap::iterator, bool> result = | 1125 std::pair<PendingRenderFrameConnectMap::iterator, bool> result = |
| 1126 pending_render_frame_connects_.insert(std::make_pair( | 1126 pending_render_frame_connects_.insert(std::make_pair( |
| 1127 routing_id, | 1127 routing_id, |
| 1128 make_scoped_refptr(new PendingRenderFrameConnect( | 1128 make_scoped_refptr(new PendingRenderFrameConnect( |
| 1129 routing_id, std::move(services), std::move(exposed_services))))); | 1129 routing_id, std::move(services), std::move(exposed_services))))); |
| 1130 CHECK(result.second) << "Inserting a duplicate item."; | 1130 CHECK(result.second) << "Inserting a duplicate item."; |
| 1131 } | 1131 } |
| 1132 | 1132 |
| 1133 int RenderThreadImpl::GenerateRoutingID() { | 1133 int RenderThreadImpl::GenerateRoutingID() { |
| 1134 int routing_id = MSG_ROUTING_NONE; | 1134 int routing_id = MSG_ROUTING_NONE; |
| (...skipping 1006 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2141 void RenderThreadImpl::ReleaseFreeMemory() { | 2141 void RenderThreadImpl::ReleaseFreeMemory() { |
| 2142 base::allocator::ReleaseFreeMemory(); | 2142 base::allocator::ReleaseFreeMemory(); |
| 2143 discardable_shared_memory_manager()->ReleaseFreeMemory(); | 2143 discardable_shared_memory_manager()->ReleaseFreeMemory(); |
| 2144 | 2144 |
| 2145 if (blink_platform_impl_) | 2145 if (blink_platform_impl_) |
| 2146 blink::decommitFreeableMemory(); | 2146 blink::decommitFreeableMemory(); |
| 2147 } | 2147 } |
| 2148 | 2148 |
| 2149 RenderThreadImpl::PendingRenderFrameConnect::PendingRenderFrameConnect( | 2149 RenderThreadImpl::PendingRenderFrameConnect::PendingRenderFrameConnect( |
| 2150 int routing_id, | 2150 int routing_id, |
| 2151 mojo::InterfaceRequest<mojo::ServiceProvider> services, | 2151 mojo::InterfaceRequest<mojo::InterfaceProvider> services, |
| 2152 mojo::ServiceProviderPtr exposed_services) | 2152 mojo::InterfaceProviderPtr exposed_services) |
| 2153 : routing_id_(routing_id), | 2153 : routing_id_(routing_id), |
| 2154 services_(std::move(services)), | 2154 services_(std::move(services)), |
| 2155 exposed_services_(std::move(exposed_services)) { | 2155 exposed_services_(std::move(exposed_services)) { |
| 2156 // The RenderFrame may be deleted before the ExchangeServiceProviders message | 2156 // The RenderFrame may be deleted before the ExchangeInterfaceProviders |
| 2157 // is received. In that case, the RenderFrameHost should close the connection, | 2157 // message is received. In that case, the RenderFrameHost should close the |
| 2158 // which is detected by setting an error handler on |exposed_services_|. | 2158 // connection, which is detected by setting an error handler on |
| 2159 // |exposed_services_|. |
| 2159 exposed_services_.set_connection_error_handler(base::Bind( | 2160 exposed_services_.set_connection_error_handler(base::Bind( |
| 2160 &RenderThreadImpl::PendingRenderFrameConnect::OnConnectionError, | 2161 &RenderThreadImpl::PendingRenderFrameConnect::OnConnectionError, |
| 2161 base::Unretained(this))); | 2162 base::Unretained(this))); |
| 2162 } | 2163 } |
| 2163 | 2164 |
| 2164 RenderThreadImpl::PendingRenderFrameConnect::~PendingRenderFrameConnect() { | 2165 RenderThreadImpl::PendingRenderFrameConnect::~PendingRenderFrameConnect() { |
| 2165 } | 2166 } |
| 2166 | 2167 |
| 2167 void RenderThreadImpl::PendingRenderFrameConnect::OnConnectionError() { | 2168 void RenderThreadImpl::PendingRenderFrameConnect::OnConnectionError() { |
| 2168 size_t erased = | 2169 size_t erased = |
| 2169 RenderThreadImpl::current()->pending_render_frame_connects_.erase( | 2170 RenderThreadImpl::current()->pending_render_frame_connects_.erase( |
| 2170 routing_id_); | 2171 routing_id_); |
| 2171 DCHECK_EQ(1u, erased); | 2172 DCHECK_EQ(1u, erased); |
| 2172 } | 2173 } |
| 2173 | 2174 |
| 2174 } // namespace content | 2175 } // namespace content |
| OLD | NEW |