| 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 <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/allocator/allocator_extension.h" | 12 #include "base/allocator/allocator_extension.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/lazy_instance.h" | 14 #include "base/lazy_instance.h" |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/memory/discardable_memory_allocator.h" | 16 #include "base/memory/discardable_memory_allocator.h" |
| 17 #include "base/memory/shared_memory.h" | 17 #include "base/memory/shared_memory.h" |
| 18 #include "base/metrics/field_trial.h" | 18 #include "base/metrics/field_trial.h" |
| 19 #include "base/metrics/histogram.h" | 19 #include "base/metrics/histogram.h" |
| 20 #include "base/path_service.h" | 20 #include "base/path_service.h" |
| 21 #include "base/single_thread_task_runner.h" | 21 #include "base/single_thread_task_runner.h" |
| 22 #include "base/strings/string16.h" | 22 #include "base/strings/string16.h" |
| 23 #include "base/strings/string_number_conversions.h" | 23 #include "base/strings/string_number_conversions.h" |
| 24 #include "base/strings/string_tokenizer.h" | 24 #include "base/strings/string_tokenizer.h" |
| 25 #include "base/strings/sys_string_conversions.h" | 25 #include "base/strings/sys_string_conversions.h" |
| 26 #include "base/strings/utf_string_conversions.h" | 26 #include "base/strings/utf_string_conversions.h" |
| 27 #include "base/threading/simple_thread.h" |
| 27 #include "base/threading/thread_local.h" | 28 #include "base/threading/thread_local.h" |
| 28 #include "base/threading/thread_restrictions.h" | 29 #include "base/threading/thread_restrictions.h" |
| 29 #include "base/trace_event/trace_event.h" | 30 #include "base/trace_event/trace_event.h" |
| 30 #include "base/values.h" | 31 #include "base/values.h" |
| 31 #include "cc/base/switches.h" | 32 #include "cc/base/switches.h" |
| 32 #include "cc/blink/web_external_bitmap_impl.h" | 33 #include "cc/blink/web_external_bitmap_impl.h" |
| 33 #include "cc/blink/web_layer_impl.h" | 34 #include "cc/blink/web_layer_impl.h" |
| 34 #include "cc/resources/tile_task_worker_pool.h" | 35 #include "cc/resources/tile_task_worker_pool.h" |
| 35 #include "content/child/appcache/appcache_dispatcher.h" | 36 #include "content/child/appcache/appcache_dispatcher.h" |
| 36 #include "content/child/appcache/appcache_frontend_impl.h" | 37 #include "content/child/appcache/appcache_frontend_impl.h" |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 } | 246 } |
| 246 | 247 |
| 247 private: | 248 private: |
| 248 const std::string scheme_; | 249 const std::string scheme_; |
| 249 const std::string host_; | 250 const std::string host_; |
| 250 const double zoom_level_; | 251 const double zoom_level_; |
| 251 | 252 |
| 252 DISALLOW_COPY_AND_ASSIGN(RenderViewZoomer); | 253 DISALLOW_COPY_AND_ASSIGN(RenderViewZoomer); |
| 253 }; | 254 }; |
| 254 | 255 |
| 256 class CompositorRasterThread : public base::SimpleThread { |
| 257 public: |
| 258 CompositorRasterThread(cc::TaskGraphRunner* task_graph_runner, |
| 259 const std::string& name_prefix) |
| 260 : base::SimpleThread(name_prefix), |
| 261 task_graph_runner_(task_graph_runner) {} |
| 262 |
| 263 // Overridden from base::SimpleThread: |
| 264 void Run() override { task_graph_runner_->Run(); } |
| 265 |
| 266 private: |
| 267 cc::TaskGraphRunner* task_graph_runner_; |
| 268 |
| 269 DISALLOW_COPY_AND_ASSIGN(CompositorRasterThread); |
| 270 }; |
| 271 |
| 255 std::string HostToCustomHistogramSuffix(const std::string& host) { | 272 std::string HostToCustomHistogramSuffix(const std::string& host) { |
| 256 if (host == "mail.google.com") | 273 if (host == "mail.google.com") |
| 257 return ".gmail"; | 274 return ".gmail"; |
| 258 if (host == "docs.google.com" || host == "drive.google.com") | 275 if (host == "docs.google.com" || host == "drive.google.com") |
| 259 return ".docs"; | 276 return ".docs"; |
| 260 if (host == "plus.google.com") | 277 if (host == "plus.google.com") |
| 261 return ".plus"; | 278 return ".plus"; |
| 262 return std::string(); | 279 return std::string(); |
| 263 } | 280 } |
| 264 | 281 |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 613 // Note that under Linux, the media library will normally already have | 630 // Note that under Linux, the media library will normally already have |
| 614 // been initialized by the Zygote before this instance became a Renderer. | 631 // been initialized by the Zygote before this instance became a Renderer. |
| 615 base::FilePath media_path; | 632 base::FilePath media_path; |
| 616 PathService::Get(DIR_MEDIA_LIBS, &media_path); | 633 PathService::Get(DIR_MEDIA_LIBS, &media_path); |
| 617 if (!media_path.empty()) | 634 if (!media_path.empty()) |
| 618 media::InitializeMediaLibrary(media_path); | 635 media::InitializeMediaLibrary(media_path); |
| 619 | 636 |
| 620 memory_pressure_listener_.reset(new base::MemoryPressureListener( | 637 memory_pressure_listener_.reset(new base::MemoryPressureListener( |
| 621 base::Bind(&RenderThreadImpl::OnMemoryPressure, base::Unretained(this)))); | 638 base::Bind(&RenderThreadImpl::OnMemoryPressure, base::Unretained(this)))); |
| 622 | 639 |
| 640 compositor_task_graph_runner_.reset(new cc::TaskGraphRunner); |
| 641 |
| 642 is_gather_pixel_refs_enabled_ = false; |
| 643 |
| 623 if (is_impl_side_painting_enabled_) { | 644 if (is_impl_side_painting_enabled_) { |
| 624 int num_raster_threads = 0; | 645 int num_raster_threads = 0; |
| 625 std::string string_value = | 646 std::string string_value = |
| 626 command_line.GetSwitchValueASCII(switches::kNumRasterThreads); | 647 command_line.GetSwitchValueASCII(switches::kNumRasterThreads); |
| 627 bool parsed_num_raster_threads = | 648 bool parsed_num_raster_threads = |
| 628 base::StringToInt(string_value, &num_raster_threads); | 649 base::StringToInt(string_value, &num_raster_threads); |
| 629 DCHECK(parsed_num_raster_threads) << string_value; | 650 DCHECK(parsed_num_raster_threads) << string_value; |
| 630 DCHECK_GT(num_raster_threads, 0); | 651 DCHECK_GT(num_raster_threads, 0); |
| 631 | 652 |
| 632 // In single process, browser compositor already initialized and set up | 653 // Note: Currently, gathering of pixel refs when using a single |
| 633 // worker threads, can't change the number later for the renderer compistor | 654 // raster thread doesn't provide any benefit. This might change |
| 634 // in the same process. | 655 // in the future but we avoid it for now to reduce the cost of |
| 635 if (!command_line.HasSwitch(switches::kSingleProcess)) | 656 // Picture::Create. |
| 636 cc::TileTaskWorkerPool::SetNumWorkerThreads(num_raster_threads); | 657 is_gather_pixel_refs_enabled_ = num_raster_threads > 1; |
| 637 | 658 |
| 659 while (compositor_raster_threads_.size() < |
| 660 static_cast<size_t>(num_raster_threads)) { |
| 661 scoped_ptr<CompositorRasterThread> raster_thread( |
| 662 new CompositorRasterThread( |
| 663 compositor_task_graph_runner_.get(), |
| 664 base::StringPrintf( |
| 665 "CompositorWorker%u", |
| 666 static_cast<unsigned>(compositor_raster_threads_.size() + 1)) |
| 667 .c_str())); |
| 668 raster_thread->Start(); |
| 638 #if defined(OS_ANDROID) || defined(OS_LINUX) | 669 #if defined(OS_ANDROID) || defined(OS_LINUX) |
| 639 if (!command_line.HasSwitch( | 670 if (!command_line.HasSwitch( |
| 640 switches::kUseNormalPriorityForTileTaskWorkerThreads)) { | 671 switches::kUseNormalPriorityForTileTaskWorkerThreads)) { |
| 641 cc::TileTaskWorkerPool::SetWorkerThreadPriority( | 672 raster_thread->SetThreadPriority(base::kThreadPriority_Background); |
| 642 base::kThreadPriority_Background); | 673 } |
| 674 #endif |
| 675 compositor_raster_threads_.push_back(raster_thread.Pass()); |
| 643 } | 676 } |
| 644 #endif | |
| 645 } | 677 } |
| 646 | 678 |
| 647 // In single process, browser main loop set up the discardable memory | 679 // In single process, browser main loop set up the discardable memory |
| 648 // allocator. | 680 // allocator. |
| 649 if (!command_line.HasSwitch(switches::kSingleProcess)) { | 681 if (!command_line.HasSwitch(switches::kSingleProcess)) { |
| 650 base::DiscardableMemoryAllocator::SetInstance( | 682 base::DiscardableMemoryAllocator::SetInstance( |
| 651 ChildThreadImpl::discardable_shared_memory_manager()); | 683 ChildThreadImpl::discardable_shared_memory_manager()); |
| 652 } | 684 } |
| 653 | 685 |
| 654 service_registry()->AddService<RenderFrameSetup>( | 686 service_registry()->AddService<RenderFrameSetup>( |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 715 } | 747 } |
| 716 | 748 |
| 717 media_thread_.reset(); | 749 media_thread_.reset(); |
| 718 | 750 |
| 719 // AudioMessageFilter may be accessed on |media_thread_|, so shutdown after. | 751 // AudioMessageFilter may be accessed on |media_thread_|, so shutdown after. |
| 720 RemoveFilter(audio_message_filter_.get()); | 752 RemoveFilter(audio_message_filter_.get()); |
| 721 audio_message_filter_ = NULL; | 753 audio_message_filter_ = NULL; |
| 722 | 754 |
| 723 compositor_thread_.reset(); | 755 compositor_thread_.reset(); |
| 724 | 756 |
| 757 // Shutdown raster threads. |
| 758 compositor_task_graph_runner_->Shutdown(); |
| 759 while (!compositor_raster_threads_.empty()) { |
| 760 compositor_raster_threads_.back()->Join(); |
| 761 compositor_raster_threads_.pop_back(); |
| 762 } |
| 763 compositor_task_graph_runner_.reset(); |
| 764 |
| 725 main_input_callback_.Cancel(); | 765 main_input_callback_.Cancel(); |
| 726 input_handler_manager_.reset(); | 766 input_handler_manager_.reset(); |
| 727 if (input_event_filter_.get()) { | 767 if (input_event_filter_.get()) { |
| 728 RemoveFilter(input_event_filter_.get()); | 768 RemoveFilter(input_event_filter_.get()); |
| 729 input_event_filter_ = NULL; | 769 input_event_filter_ = NULL; |
| 730 } | 770 } |
| 731 | 771 |
| 732 // RemoveEmbeddedWorkerRoute may be called while deleting | 772 // RemoveEmbeddedWorkerRoute may be called while deleting |
| 733 // EmbeddedWorkerDispatcher. So it must be deleted before deleting | 773 // EmbeddedWorkerDispatcher. So it must be deleted before deleting |
| 734 // RenderThreadImpl. | 774 // RenderThreadImpl. |
| (...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1397 #if defined(OS_ANDROID) | 1437 #if defined(OS_ANDROID) |
| 1398 if (SynchronousCompositorFactory* factory = | 1438 if (SynchronousCompositorFactory* factory = |
| 1399 SynchronousCompositorFactory::GetInstance()) { | 1439 SynchronousCompositorFactory::GetInstance()) { |
| 1400 return factory->CreateExternalBeginFrameSource(routing_id); | 1440 return factory->CreateExternalBeginFrameSource(routing_id); |
| 1401 } | 1441 } |
| 1402 #endif | 1442 #endif |
| 1403 return make_scoped_ptr(new CompositorExternalBeginFrameSource( | 1443 return make_scoped_ptr(new CompositorExternalBeginFrameSource( |
| 1404 compositor_message_filter_.get(), sync_message_filter(), routing_id)); | 1444 compositor_message_filter_.get(), sync_message_filter(), routing_id)); |
| 1405 } | 1445 } |
| 1406 | 1446 |
| 1447 cc::TaskGraphRunner* RenderThreadImpl::GetTaskGraphRunner() { |
| 1448 return compositor_task_graph_runner_.get(); |
| 1449 } |
| 1450 |
| 1451 bool RenderThreadImpl::IsGatherPixelRefsEnabled() { |
| 1452 return is_gather_pixel_refs_enabled_; |
| 1453 } |
| 1454 |
| 1407 bool RenderThreadImpl::IsMainThread() { | 1455 bool RenderThreadImpl::IsMainThread() { |
| 1408 return !!current(); | 1456 return !!current(); |
| 1409 } | 1457 } |
| 1410 | 1458 |
| 1411 base::MessageLoop* RenderThreadImpl::GetMainLoop() { | 1459 base::MessageLoop* RenderThreadImpl::GetMainLoop() { |
| 1412 return message_loop(); | 1460 return message_loop(); |
| 1413 } | 1461 } |
| 1414 | 1462 |
| 1415 scoped_refptr<base::MessageLoopProxy> RenderThreadImpl::GetIOLoopProxy() { | 1463 scoped_refptr<base::MessageLoopProxy> RenderThreadImpl::GetIOLoopProxy() { |
| 1416 return io_message_loop_proxy_; | 1464 return io_message_loop_proxy_; |
| (...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1799 } | 1847 } |
| 1800 | 1848 |
| 1801 void RenderThreadImpl::PendingRenderFrameConnect::OnConnectionError() { | 1849 void RenderThreadImpl::PendingRenderFrameConnect::OnConnectionError() { |
| 1802 size_t erased = | 1850 size_t erased = |
| 1803 RenderThreadImpl::current()->pending_render_frame_connects_.erase( | 1851 RenderThreadImpl::current()->pending_render_frame_connects_.erase( |
| 1804 routing_id_); | 1852 routing_id_); |
| 1805 DCHECK_EQ(1u, erased); | 1853 DCHECK_EQ(1u, erased); |
| 1806 } | 1854 } |
| 1807 | 1855 |
| 1808 } // namespace content | 1856 } // namespace content |
| OLD | NEW |