Home | History | Annotate | Download | only in browser
      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
      3 // found in the LICENSE file.
      4 
      5 #include "chrome/browser/chrome_browser_main_android.h"
      6 
      7 #include "base/command_line.h"
      8 #include "base/debug/trace_event.h"
      9 #include "base/path_service.h"
     10 #include "chrome/browser/google/google_search_counter_android.h"
     11 #include "chrome/common/chrome_paths.h"
     12 #include "chrome/common/chrome_switches.h"
     13 #include "components/breakpad/app/breakpad_linux.h"
     14 #include "components/breakpad/browser/crash_dump_manager_android.h"
     15 #include "content/public/browser/android/compositor.h"
     16 #include "content/public/common/main_function_params.h"
     17 #include "net/android/network_change_notifier_factory_android.h"
     18 #include "net/base/network_change_notifier.h"
     19 #include "ui/base/resource/resource_bundle.h"
     20 #include "ui/base/ui_base_paths.h"
     21 
     22 ChromeBrowserMainPartsAndroid::ChromeBrowserMainPartsAndroid(
     23     const content::MainFunctionParams& parameters)
     24     : ChromeBrowserMainParts(parameters) {
     25 }
     26 
     27 ChromeBrowserMainPartsAndroid::~ChromeBrowserMainPartsAndroid() {
     28 }
     29 
     30 void ChromeBrowserMainPartsAndroid::PreProfileInit() {
     31   TRACE_EVENT0("startup", "ChromeBrowserMainPartsAndroid::PreProfileInit")
     32 #if defined(GOOGLE_CHROME_BUILD)
     33   // TODO(jcivelli): we should not initialize the crash-reporter when it was not
     34   // enabled. Right now if it is disabled we still generate the minidumps but we
     35   // do not upload them.
     36   bool breakpad_enabled = true;
     37 #else
     38   bool breakpad_enabled = false;
     39 #endif
     40 
     41   // Allow Breakpad to be enabled in Chromium builds for testing purposes.
     42   if (!breakpad_enabled)
     43     breakpad_enabled = CommandLine::ForCurrentProcess()->HasSwitch(
     44           switches::kEnableCrashReporterForTesting);
     45 
     46   if (breakpad_enabled) {
     47     base::FilePath crash_dump_dir;
     48     PathService::Get(chrome::DIR_CRASH_DUMPS, &crash_dump_dir);
     49     crash_dump_manager_.reset(new breakpad::CrashDumpManager(crash_dump_dir));
     50   }
     51 
     52   ChromeBrowserMainParts::PreProfileInit();
     53 }
     54 
     55 void ChromeBrowserMainPartsAndroid::PostProfileInit() {
     56   search_counter_.reset(new GoogleSearchCounterAndroid(profile()));
     57   ChromeBrowserMainParts::PostProfileInit();
     58 }
     59 
     60 void ChromeBrowserMainPartsAndroid::PreEarlyInitialization() {
     61   TRACE_EVENT0("startup",
     62     "ChromeBrowserMainPartsAndroid::PreEarlyInitialization")
     63   net::NetworkChangeNotifier::SetFactory(
     64       new net::NetworkChangeNotifierFactoryAndroid());
     65 
     66   content::Compositor::Initialize();
     67 
     68   // Chrome on Android does not use default MessageLoop. It has its own
     69   // Android specific MessageLoop.
     70   DCHECK(!main_message_loop_.get());
     71 
     72   // Create and start the MessageLoop.
     73   // This is a critical point in the startup process.
     74   {
     75     TRACE_EVENT0("startup",
     76       "ChromeBrowserMainPartsAndroid::PreEarlyInitialization:CreateUiMsgLoop");
     77     main_message_loop_.reset(new base::MessageLoopForUI);
     78   }
     79 
     80   {
     81     TRACE_EVENT0("startup",
     82       "ChromeBrowserMainPartsAndroid::PreEarlyInitialization:StartUiMsgLoop");
     83     base::MessageLoopForUI::current()->Start();
     84   }
     85 
     86   ChromeBrowserMainParts::PreEarlyInitialization();
     87 }
     88 
     89 void ChromeBrowserMainPartsAndroid::ShowMissingLocaleMessageBox() {
     90   NOTREACHED();
     91 }
     92