Rename vector icon header files.
[chromium-blink-merge.git] / chrome / browser / chrome_browser_main_android.cc
blobc25fabcb5fc31c638c6a76193c66450e431337c2
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.
5 #include "chrome/browser/chrome_browser_main_android.h"
7 #include "base/android/build_info.h"
8 #include "base/command_line.h"
9 #include "base/files/file_path.h"
10 #include "base/files/file_util.h"
11 #include "base/path_service.h"
12 #include "base/trace_event/trace_event.h"
13 #include "chrome/browser/android/chrome_media_client_android.h"
14 #include "chrome/browser/android/seccomp_support_detector.h"
15 #include "chrome/browser/google/google_search_counter_android.h"
16 #include "chrome/browser/signin/signin_manager_factory.h"
17 #include "chrome/common/chrome_paths.h"
18 #include "chrome/common/chrome_switches.h"
19 #include "components/crash/app/breakpad_linux.h"
20 #include "components/crash/browser/crash_dump_manager_android.h"
21 #include "components/enhanced_bookmarks/persistent_image_store.h"
22 #include "components/signin/core/browser/signin_manager.h"
23 #include "content/public/browser/android/compositor.h"
24 #include "content/public/browser/browser_thread.h"
25 #include "content/public/common/main_function_params.h"
26 #include "media/base/android/media_client_android.h"
27 #include "net/android/network_change_notifier_factory_android.h"
28 #include "net/base/network_change_notifier.h"
29 #include "ui/base/resource/resource_bundle_android.h"
30 #include "ui/base/ui_base_paths.h"
32 namespace {
34 void DeleteFileTask(
35 const base::FilePath& file_path) {
36 if (base::PathExists(file_path))
37 base::DeleteFile(file_path, false);
40 } // namespace
42 ChromeBrowserMainPartsAndroid::ChromeBrowserMainPartsAndroid(
43 const content::MainFunctionParams& parameters)
44 : ChromeBrowserMainParts(parameters) {
47 ChromeBrowserMainPartsAndroid::~ChromeBrowserMainPartsAndroid() {
50 int ChromeBrowserMainPartsAndroid::PreCreateThreads() {
51 TRACE_EVENT0("startup", "ChromeBrowserMainPartsAndroid::PreCreateThreads")
53 // The CrashDumpManager must be initialized before any child process is
54 // created (as they need to access it during creation). Such processes
55 // are created on the PROCESS_LAUNCHER thread, and so the manager is
56 // initialized before that thread is created.
57 #if defined(GOOGLE_CHROME_BUILD)
58 // TODO(jcivelli): we should not initialize the crash-reporter when it was not
59 // enabled. Right now if it is disabled we still generate the minidumps but we
60 // do not upload them.
61 bool breakpad_enabled = true;
62 #else
63 bool breakpad_enabled = false;
64 #endif
66 // Allow Breakpad to be enabled in Chromium builds for testing purposes.
67 if (!breakpad_enabled)
68 breakpad_enabled = base::CommandLine::ForCurrentProcess()->HasSwitch(
69 switches::kEnableCrashReporterForTesting);
71 if (breakpad_enabled) {
72 base::FilePath crash_dump_dir;
73 PathService::Get(chrome::DIR_CRASH_DUMPS, &crash_dump_dir);
74 crash_dump_manager_.reset(new breakpad::CrashDumpManager(crash_dump_dir));
77 bool has_language_splits =
78 base::android::BuildInfo::GetInstance()->has_language_apk_splits();
79 ui::SetLocalePaksStoredInApk(has_language_splits);
81 return ChromeBrowserMainParts::PreCreateThreads();
84 void ChromeBrowserMainPartsAndroid::PostProfileInit() {
85 Profile* main_profile = profile();
86 search_counter_.reset(new GoogleSearchCounterAndroid(main_profile));
88 ChromeBrowserMainParts::PostProfileInit();
90 // Previously we stored information related to salient images for bookmarks
91 // in a local file. We replaced the salient images with favicons. As part
92 // of the clean up, the local file needs to be deleted. See crbug.com/499415.
93 base::FilePath bookmark_image_file_path = main_profile->GetPath().Append(
94 PersistentImageStore::kBookmarkImageStoreDb);
95 content::BrowserThread::PostDelayedTask(
96 content::BrowserThread::FILE, FROM_HERE,
97 base::Bind(&DeleteFileTask,
98 bookmark_image_file_path),
99 base::TimeDelta::FromMinutes(1));
102 void ChromeBrowserMainPartsAndroid::PreEarlyInitialization() {
103 TRACE_EVENT0("startup",
104 "ChromeBrowserMainPartsAndroid::PreEarlyInitialization")
105 net::NetworkChangeNotifier::SetFactory(
106 new net::NetworkChangeNotifierFactoryAndroid());
108 content::Compositor::Initialize();
110 // Chrome on Android does not use default MessageLoop. It has its own
111 // Android specific MessageLoop.
112 DCHECK(!main_message_loop_.get());
114 // Create and start the MessageLoop.
115 // This is a critical point in the startup process.
117 TRACE_EVENT0("startup",
118 "ChromeBrowserMainPartsAndroid::PreEarlyInitialization:CreateUiMsgLoop");
119 main_message_loop_.reset(new base::MessageLoopForUI);
123 TRACE_EVENT0("startup",
124 "ChromeBrowserMainPartsAndroid::PreEarlyInitialization:StartUiMsgLoop");
125 base::MessageLoopForUI::current()->Start();
128 ChromeBrowserMainParts::PreEarlyInitialization();
131 void ChromeBrowserMainPartsAndroid::PreMainMessageLoopRun() {
132 media::SetMediaClientAndroid(new ChromeMediaClientAndroid);
134 ChromeBrowserMainParts::PreMainMessageLoopRun();
137 void ChromeBrowserMainPartsAndroid::PostBrowserStart() {
138 ChromeBrowserMainParts::PostBrowserStart();
140 content::BrowserThread::GetBlockingPool()->PostDelayedTask(FROM_HERE,
141 base::Bind(&SeccompSupportDetector::StartDetection),
142 base::TimeDelta::FromMinutes(1));
145 void ChromeBrowserMainPartsAndroid::ShowMissingLocaleMessageBox() {
146 NOTREACHED();