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 "chrome/app/android/chrome_main_delegate_android.h" | 5 #include "chrome/app/android/chrome_main_delegate_android.h" |
6 | 6 |
7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
| 8 #include "base/base_paths_android.h" |
| 9 #include "base/files/file_path.h" |
| 10 #include "base/files/file_util.h" |
| 11 #include "base/logging.h" |
| 12 #include "base/path_service.h" |
8 #include "base/trace_event/trace_event.h" | 13 #include "base/trace_event/trace_event.h" |
9 #include "chrome/browser/android/chrome_startup_flags.h" | 14 #include "chrome/browser/android/chrome_startup_flags.h" |
10 #include "chrome/browser/android/metrics/uma_utils.h" | 15 #include "chrome/browser/android/metrics/uma_utils.h" |
11 #include "chrome/browser/android/metrics/uma_utils.h" | 16 #include "chrome/browser/android/metrics/uma_utils.h" |
12 #include "chrome/browser/media/android/remote/remote_media_player_manager.h" | 17 #include "chrome/browser/media/android/remote/remote_media_player_manager.h" |
| 18 #include "components/policy/core/browser/android/android_combined_policy_provide
r.h" |
13 #include "components/startup_metric_utils/startup_metric_utils.h" | 19 #include "components/startup_metric_utils/startup_metric_utils.h" |
14 #include "content/browser/media/android/browser_media_player_manager.h" | 20 #include "content/browser/media/android/browser_media_player_manager.h" |
15 #include "content/public/browser/browser_main_runner.h" | 21 #include "content/public/browser/browser_main_runner.h" |
16 | 22 |
| 23 #if defined(SAFE_BROWSING_DB_REMOTE) |
| 24 #include "chrome/browser/safe_browsing/safe_browsing_api_handler.h" |
| 25 #endif |
| 26 |
17 namespace { | 27 namespace { |
18 | 28 |
19 content::BrowserMediaPlayerManager* CreateRemoteMediaPlayerManager( | 29 content::BrowserMediaPlayerManager* CreateRemoteMediaPlayerManager( |
20 content::RenderFrameHost* render_frame_host) { | 30 content::RenderFrameHost* render_frame_host) { |
21 return new remote_media::RemoteMediaPlayerManager(render_frame_host); | 31 return new remote_media::RemoteMediaPlayerManager(render_frame_host); |
22 } | 32 } |
23 | 33 |
24 } // namespace | 34 } // namespace |
25 | 35 |
26 // ChromeMainDelegateAndroid is created when the library is loaded. It is always | 36 // ChromeMainDelegateAndroid is created when the library is loaded. It is always |
27 // done in the process's main Java thread. But for non browser process, e.g. | 37 // done in the process's main Java thread. But for non browser process, e.g. |
28 // renderer process, it is not the native Chrome's main thread. | 38 // renderer process, it is not the native Chrome's main thread. |
29 ChromeMainDelegateAndroid::ChromeMainDelegateAndroid() { | 39 ChromeMainDelegateAndroid::ChromeMainDelegateAndroid() { |
30 } | 40 } |
31 | 41 |
32 ChromeMainDelegateAndroid::~ChromeMainDelegateAndroid() { | 42 ChromeMainDelegateAndroid::~ChromeMainDelegateAndroid() { |
33 } | 43 } |
| 44 |
| 45 bool ChromeMainDelegateAndroid::BasicStartupComplete(int* exit_code) { |
| 46 #if defined(SAFE_BROWSING_DB_REMOTE) |
| 47 safe_browsing_api_handler_.reset(CreateSafeBrowsingApiHandler()); |
| 48 SafeBrowsingApiHandler::SetInstance(safe_browsing_api_handler_.get()); |
| 49 #endif |
| 50 |
| 51 policy::android::AndroidCombinedPolicyProvider::SetShouldWaitForPolicy(true); |
| 52 SetChromeSpecificCommandLineFlags(); |
| 53 content::BrowserMediaPlayerManager::RegisterFactory( |
| 54 &CreateRemoteMediaPlayerManager); |
| 55 |
| 56 return ChromeMainDelegate::BasicStartupComplete(exit_code); |
| 57 } |
| 58 |
34 void ChromeMainDelegateAndroid::SandboxInitialized( | 59 void ChromeMainDelegateAndroid::SandboxInitialized( |
35 const std::string& process_type) { | 60 const std::string& process_type) { |
36 ChromeMainDelegate::SandboxInitialized(process_type); | 61 ChromeMainDelegate::SandboxInitialized(process_type); |
37 } | 62 } |
38 | 63 |
39 int ChromeMainDelegateAndroid::RunProcess( | 64 int ChromeMainDelegateAndroid::RunProcess( |
40 const std::string& process_type, | 65 const std::string& process_type, |
41 const content::MainFunctionParams& main_function_params) { | 66 const content::MainFunctionParams& main_function_params) { |
42 TRACE_EVENT0("startup", "ChromeMainDelegateAndroid::RunProcess") | 67 TRACE_EVENT0("startup", "ChromeMainDelegateAndroid::RunProcess") |
43 if (process_type.empty()) { | 68 if (process_type.empty()) { |
| 69 // By default, Android creates the directory accessible by others. |
| 70 // We'd like to tighten security and make it accessible only by |
| 71 // the browser process. |
| 72 base::FilePath data_path; |
| 73 bool ok = PathService::Get(base::DIR_ANDROID_APP_DATA, &data_path); |
| 74 if (ok) { |
| 75 int permissions; |
| 76 ok = base::GetPosixFilePermissions(data_path, &permissions); |
| 77 if (ok) { |
| 78 permissions &= base::FILE_PERMISSION_USER_MASK; |
| 79 } else { |
| 80 permissions = base::FILE_PERMISSION_READ_BY_USER | |
| 81 base::FILE_PERMISSION_WRITE_BY_USER | |
| 82 base::FILE_PERMISSION_EXECUTE_BY_USER; |
| 83 } |
| 84 |
| 85 ok = base::SetPosixFilePermissions(data_path, permissions); |
| 86 } |
| 87 if (!ok) |
| 88 LOG(ERROR) << "Failed to set permission of " << data_path.value(); |
| 89 |
44 // Because the browser process can be started asynchronously as a series of | 90 // Because the browser process can be started asynchronously as a series of |
45 // UI thread tasks a second request to start it can come in while the | 91 // UI thread tasks a second request to start it can come in while the |
46 // first request is still being processed. Chrome must keep the same | 92 // first request is still being processed. Chrome must keep the same |
47 // browser runner for the second request. | 93 // browser runner for the second request. |
48 // Also only record the start time the first time round, since this is the | 94 // Also only record the start time the first time round, since this is the |
49 // start time of the application, and will be same for all requests. | 95 // start time of the application, and will be same for all requests. |
50 if (!browser_runner_.get()) { | 96 if (!browser_runner_.get()) { |
51 base::Time time = chrome::android::GetMainEntryPointTime(); | 97 base::Time time = chrome::android::GetMainEntryPointTime(); |
52 startup_metric_utils::RecordMainEntryPointTime(time); | 98 startup_metric_utils::RecordMainEntryPointTime(time); |
53 browser_runner_.reset(content::BrowserMainRunner::Create()); | 99 browser_runner_.reset(content::BrowserMainRunner::Create()); |
54 } | 100 } |
55 return browser_runner_->Initialize(main_function_params); | 101 return browser_runner_->Initialize(main_function_params); |
56 } | 102 } |
57 | 103 |
58 return ChromeMainDelegate::RunProcess(process_type, main_function_params); | 104 return ChromeMainDelegate::RunProcess(process_type, main_function_params); |
59 } | 105 } |
60 | 106 |
61 bool ChromeMainDelegateAndroid::BasicStartupComplete(int* exit_code) { | 107 void ChromeMainDelegateAndroid::ProcessExiting( |
62 SetChromeSpecificCommandLineFlags(); | 108 const std::string& process_type) { |
| 109 #if defined(SAFE_BROWSING_DB_REMOTE) |
| 110 SafeBrowsingApiHandler::SetInstance(nullptr); |
| 111 #endif |
| 112 } |
63 | 113 |
64 content::BrowserMediaPlayerManager::RegisterFactory( | 114 #if defined(SAFE_BROWSING_DB_REMOTE) |
65 &CreateRemoteMediaPlayerManager); | 115 SafeBrowsingApiHandler* |
66 | 116 ChromeMainDelegateAndroid::CreateSafeBrowsingApiHandler() { |
67 return ChromeMainDelegate::BasicStartupComplete(exit_code); | 117 return nullptr; |
68 } | 118 } |
| 119 #endif |
OLD | NEW |