Popular sites on the NTP: re-download popular suggestions once per Chrome run
[chromium-blink-merge.git] / chrome / browser / chrome_browser_main_android.cc
blobc8dcda4df20fee65cdeac974df51daa0aa6dda68
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/signin/signin_manager_factory.h"
16 #include "chrome/common/chrome_paths.h"
17 #include "chrome/common/chrome_switches.h"
18 #include "components/crash/content/app/breakpad_linux.h"
19 #include "components/crash/content/browser/crash_dump_manager_android.h"
20 #include "components/enhanced_bookmarks/persistent_image_store.h"
21 #include "components/signin/core/browser/signin_manager.h"
22 #include "content/public/browser/android/compositor.h"
23 #include "content/public/browser/browser_thread.h"
24 #include "content/public/common/main_function_params.h"
25 #include "media/base/android/media_client_android.h"
26 #include "net/android/network_change_notifier_factory_android.h"
27 #include "net/base/network_change_notifier.h"
28 #include "ui/base/resource/resource_bundle_android.h"
29 #include "ui/base/ui_base_paths.h"
31 namespace {
33 void DeleteFileTask(
34 const base::FilePath& file_path) {
35 if (base::PathExists(file_path))
36 base::DeleteFile(file_path, false);
39 } // namespace
41 ChromeBrowserMainPartsAndroid::ChromeBrowserMainPartsAndroid(
42 const content::MainFunctionParams& parameters)
43 : ChromeBrowserMainParts(parameters) {
46 ChromeBrowserMainPartsAndroid::~ChromeBrowserMainPartsAndroid() {
49 int ChromeBrowserMainPartsAndroid::PreCreateThreads() {
50 TRACE_EVENT0("startup", "ChromeBrowserMainPartsAndroid::PreCreateThreads")
52 // The CrashDumpManager must be initialized before any child process is
53 // created (as they need to access it during creation). Such processes
54 // are created on the PROCESS_LAUNCHER thread, and so the manager is
55 // initialized before that thread is created.
56 #if defined(GOOGLE_CHROME_BUILD)
57 // TODO(jcivelli): we should not initialize the crash-reporter when it was not
58 // enabled. Right now if it is disabled we still generate the minidumps but we
59 // do not upload them.
60 bool breakpad_enabled = true;
61 #else
62 bool breakpad_enabled = false;
63 #endif
65 // Allow Breakpad to be enabled in Chromium builds for testing purposes.
66 if (!breakpad_enabled)
67 breakpad_enabled = base::CommandLine::ForCurrentProcess()->HasSwitch(
68 switches::kEnableCrashReporterForTesting);
70 if (breakpad_enabled) {
71 base::FilePath crash_dump_dir;
72 PathService::Get(chrome::DIR_CRASH_DUMPS, &crash_dump_dir);
73 crash_dump_manager_.reset(new breakpad::CrashDumpManager(crash_dump_dir));
76 bool has_language_splits =
77 base::android::BuildInfo::GetInstance()->has_language_apk_splits();
78 ui::SetLocalePaksStoredInApk(has_language_splits);
80 return ChromeBrowserMainParts::PreCreateThreads();
83 void ChromeBrowserMainPartsAndroid::PostProfileInit() {
84 ChromeBrowserMainParts::PostProfileInit();
86 // Previously we stored information related to salient images for bookmarks
87 // in a local file. We replaced the salient images with favicons. As part
88 // of the clean up, the local file needs to be deleted. See crbug.com/499415.
89 base::FilePath bookmark_image_file_path = profile()->GetPath().Append(
90 PersistentImageStore::kBookmarkImageStoreDb);
91 content::BrowserThread::PostDelayedTask(
92 content::BrowserThread::FILE, FROM_HERE,
93 base::Bind(&DeleteFileTask, bookmark_image_file_path),
94 base::TimeDelta::FromMinutes(1));
97 void ChromeBrowserMainPartsAndroid::PreEarlyInitialization() {
98 TRACE_EVENT0("startup",
99 "ChromeBrowserMainPartsAndroid::PreEarlyInitialization")
100 net::NetworkChangeNotifier::SetFactory(
101 new net::NetworkChangeNotifierFactoryAndroid());
103 content::Compositor::Initialize();
105 // Chrome on Android does not use default MessageLoop. It has its own
106 // Android specific MessageLoop.
107 DCHECK(!main_message_loop_.get());
109 // Create and start the MessageLoop.
110 // This is a critical point in the startup process.
112 TRACE_EVENT0("startup",
113 "ChromeBrowserMainPartsAndroid::PreEarlyInitialization:CreateUiMsgLoop");
114 main_message_loop_.reset(new base::MessageLoopForUI);
118 TRACE_EVENT0("startup",
119 "ChromeBrowserMainPartsAndroid::PreEarlyInitialization:StartUiMsgLoop");
120 base::MessageLoopForUI::current()->Start();
123 ChromeBrowserMainParts::PreEarlyInitialization();
126 void ChromeBrowserMainPartsAndroid::PreMainMessageLoopRun() {
127 media::SetMediaClientAndroid(new ChromeMediaClientAndroid);
129 ChromeBrowserMainParts::PreMainMessageLoopRun();
132 void ChromeBrowserMainPartsAndroid::PostBrowserStart() {
133 ChromeBrowserMainParts::PostBrowserStart();
135 content::BrowserThread::GetBlockingPool()->PostDelayedTask(FROM_HERE,
136 base::Bind(&SeccompSupportDetector::StartDetection),
137 base::TimeDelta::FromMinutes(1));
140 void ChromeBrowserMainPartsAndroid::ShowMissingLocaleMessageBox() {
141 NOTREACHED();