Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / content / renderer / renderer_main.cc
index 2d298a6..e82712c 100644 (file)
@@ -14,9 +14,9 @@
 #include "base/metrics/histogram.h"
 #include "base/metrics/statistics_recorder.h"
 #include "base/metrics/stats_counters.h"
-#include "base/path_service.h"
 #include "base/pending_task.h"
 #include "base/strings/string_util.h"
+#include "base/sys_info.h"
 #include "base/threading/platform_thread.h"
 #include "base/time/time.h"
 #include "base/timer/hi_res_timer_manager.h"
 #include "content/public/common/content_switches.h"
 #include "content/public/common/main_function_params.h"
 #include "content/public/renderer/content_renderer_client.h"
-#include "content/renderer/browser_plugin/browser_plugin_manager_impl.h"
-#include "content/renderer/pepper/pepper_plugin_registry.h"
 #include "content/renderer/render_process_impl.h"
 #include "content/renderer/render_thread_impl.h"
 #include "content/renderer/renderer_main_platform_delegate.h"
 #include "ui/base/ui_base_switches.h"
-#include "webkit/child/webkit_child_helpers.h"
-#include "webkit/glue/webkit_glue.h"
 
 #if defined(OS_ANDROID)
-#include "base/android/sys_utils.h"
+#include "base/android/library_loader/library_loader_hooks.h"
 #include "third_party/skia/include/core/SkGraphics.h"
 #endif  // OS_ANDROID
 
 
 #include "base/mac/mac_util.h"
 #include "base/mac/scoped_nsautorelease_pool.h"
+#include "base/message_loop/message_pump_mac.h"
 #include "third_party/WebKit/public/web/WebView.h"
 #endif  // OS_MACOSX
 
+#if defined(ENABLE_PLUGINS)
+#include "content/renderer/pepper/pepper_plugin_registry.h"
+#endif
+
 #if defined(ENABLE_WEBRTC)
 #include "third_party/libjingle/overrides/init_webrtc.h"
 #endif
@@ -78,13 +79,13 @@ class RendererMessageLoopObserver : public base::MessageLoop::TaskObserver {
       : process_times_(base::Histogram::FactoryGet(
             "Chrome.ProcMsgL RenderThread",
             1, 3600000, 50, base::Histogram::kUmaTargetedHistogramFlag)) {}
-  virtual ~RendererMessageLoopObserver() {}
+  ~RendererMessageLoopObserver() override {}
 
-  virtual void WillProcessTask(const base::PendingTask& pending_task) OVERRIDE {
+  void WillProcessTask(const base::PendingTask& pending_task) override {
     begin_process_message_ = base::TimeTicks::Now();
   }
 
-  virtual void DidProcessTask(const base::PendingTask& pending_task) OVERRIDE {
+  void DidProcessTask(const base::PendingTask& pending_task) override {
     if (!begin_process_message_.is_null())
       process_times_->AddTime(base::TimeTicks::Now() - begin_process_message_);
   }
@@ -95,22 +96,6 @@ class RendererMessageLoopObserver : public base::MessageLoop::TaskObserver {
   DISALLOW_COPY_AND_ASSIGN(RendererMessageLoopObserver);
 };
 
-// For measuring memory usage after each task. Behind a command line flag.
-class MemoryObserver : public base::MessageLoop::TaskObserver {
- public:
-  MemoryObserver() {}
-  virtual ~MemoryObserver() {}
-
-  virtual void WillProcessTask(const base::PendingTask& pending_task) OVERRIDE {
-  }
-
-  virtual void DidProcessTask(const base::PendingTask& pending_task) OVERRIDE {
-    HISTOGRAM_MEMORY_KB("Memory.RendererUsed", webkit_glue::MemoryUsageKB());
-  }
- private:
-  DISALLOW_COPY_AND_ASSIGN(MemoryObserver);
-};
-
 }  // namespace
 
 // mainline routine for running as the Renderer process
@@ -141,7 +126,7 @@ int RendererMain(const MainFunctionParams& parameters) {
 #if defined(OS_ANDROID)
   const int kMB = 1024 * 1024;
   size_t font_cache_limit =
-      base::android::SysUtils::IsLowEndDevice() ? kMB : 8 * kMB;
+      base::SysInfo::IsLowEndDevice() ? kMB : 8 * kMB;
   SkGraphics::SetFontCacheLimit(font_cache_limit);
 #endif
 
@@ -159,34 +144,29 @@ int RendererMain(const MainFunctionParams& parameters) {
 
   RendererMessageLoopObserver task_observer;
 #if defined(OS_MACOSX)
-  // As long as we use Cocoa in the renderer (for the forseeable future as of
-  // now; see http://crbug.com/13890 for info) we need to have a UI loop.
-  base::MessageLoop main_message_loop(base::MessageLoop::TYPE_UI);
+  // As long as scrollbars on Mac are painted with Cocoa, the message pump
+  // needs to be backed by a Foundation-level loop to process NSTimers. See
+  // http://crbug.com/306348#c24 for details.
+  scoped_ptr<base::MessagePump> pump(new base::MessagePumpNSRunLoop());
+  base::MessageLoop main_message_loop(pump.Pass());
 #else
-  // The main message loop of the renderer services doesn't have IO or UI tasks,
-  // unless in-process-plugins is used.
-  base::MessageLoop main_message_loop(RenderProcessImpl::InProcessPlugins()
-                                          ? base::MessageLoop::TYPE_UI
-                                          : base::MessageLoop::TYPE_DEFAULT);
+  // The main message loop of the renderer services doesn't have IO or UI tasks.
+  base::MessageLoop main_message_loop;
 #endif
   main_message_loop.AddTaskObserver(&task_observer);
 
-  scoped_ptr<MemoryObserver> memory_observer;
-  if (parsed_command_line.HasSwitch(switches::kMemoryMetrics)) {
-    memory_observer.reset(new MemoryObserver());
-    main_message_loop.AddTaskObserver(memory_observer.get());
-  }
-
   base::PlatformThread::SetName("CrRendererMain");
 
-  platform.PlatformInitialize();
-
   bool no_sandbox = parsed_command_line.HasSwitch(switches::kNoSandbox);
-  platform.InitSandboxTests(no_sandbox);
 
   // Initialize histogram statistics gathering system.
   base::StatisticsRecorder::Initialize();
 
+#if defined(OS_ANDROID)
+  // If we have a pending chromium android linker histogram, record it.
+  base::android::RecordChromiumAndroidLinkerRendererHistogram();
+#endif
+
   // Initialize statistical testing infrastructure.  We set the entropy provider
   // to NULL to disallow the renderer process from creating its own one-time
   // randomized trials; they should be created in the browser process.
@@ -197,10 +177,14 @@ int RendererMain(const MainFunctionParams& parameters) {
     // reported in crash reports.
     bool result = base::FieldTrialList::CreateTrialsFromString(
         parsed_command_line.GetSwitchValueASCII(switches::kForceFieldTrials),
-        base::FieldTrialList::ACTIVATE_TRIALS);
+        base::FieldTrialList::ACTIVATE_TRIALS,
+        std::set<std::string>());
     DCHECK(result);
   }
 
+  // PlatformInitialize uses FieldTrials, so this must happen later.
+  platform.PlatformInitialize();
+
 #if defined(ENABLE_PLUGINS)
   // Load pepper plugins before engaging the sandbox.
   PepperPluginRegistry::GetInstance();
@@ -226,9 +210,9 @@ int RendererMain(const MainFunctionParams& parameters) {
     } else {
       LOG(ERROR) << "Running without renderer sandbox";
 #ifndef NDEBUG
-      // For convenience, we print the stack trace for crashes. We can't get
-      // symbols when the sandbox is enabled, so only try when the sandbox is
-      // disabled.
+      // For convenience, we print the stack traces for crashes.  When sandbox
+      // is enabled, the in-process stack dumping is enabled as part of the
+      // EnableSandbox() call.
       base::debug::EnableInProcessStackDumping();
 #endif
     }
@@ -239,8 +223,6 @@ int RendererMain(const MainFunctionParams& parameters) {
 
     base::HighResolutionTimerManager hi_res_timer_manager;
 
-    platform.RunSandboxTests(no_sandbox);
-
     startup_timer.Stop();  // End of Startup Time Measurement.
 
     if (run_loop) {