OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/browser/chromeos/chrome_browser_main_chromeos.h" | 5 #include "chrome/browser/chromeos/chrome_browser_main_chromeos.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "ash/shell.h" | 13 #include "ash/shell.h" |
14 #include "ash/sticky_keys/sticky_keys_controller.h" | 14 #include "ash/sticky_keys/sticky_keys_controller.h" |
15 #include "base/bind.h" | 15 #include "base/bind.h" |
16 #include "base/callback.h" | 16 #include "base/callback.h" |
17 #include "base/command_line.h" | 17 #include "base/command_line.h" |
18 #include "base/files/file_util.h" | 18 #include "base/files/file_util.h" |
19 #include "base/lazy_instance.h" | 19 #include "base/lazy_instance.h" |
20 #include "base/linux_util.h" | 20 #include "base/linux_util.h" |
21 #include "base/macros.h" | 21 #include "base/macros.h" |
22 #include "base/memory/ptr_util.h" | 22 #include "base/memory/ptr_util.h" |
| 23 #include "base/memory/weak_ptr.h" |
23 #include "base/path_service.h" | 24 #include "base/path_service.h" |
24 #include "base/strings/string_number_conversions.h" | 25 #include "base/strings/string_number_conversions.h" |
25 #include "base/strings/string_split.h" | 26 #include "base/strings/string_split.h" |
26 #include "base/sys_info.h" | 27 #include "base/sys_info.h" |
27 #include "base/task_scheduler/post_task.h" | 28 #include "base/task_scheduler/post_task.h" |
28 #include "chrome/browser/browser_process.h" | 29 #include "chrome/browser/browser_process.h" |
29 #include "chrome/browser/browser_process_platform_part_chromeos.h" | 30 #include "chrome/browser/browser_process_platform_part_chromeos.h" |
30 #include "chrome/browser/chrome_notification_types.h" | 31 #include "chrome/browser/chrome_notification_types.h" |
31 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" | 32 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" |
32 #include "chrome/browser/chromeos/accessibility/magnification_manager.h" | 33 #include "chrome/browser/chromeos/accessibility/magnification_manager.h" |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 #include "components/user_manager/user.h" | 140 #include "components/user_manager/user.h" |
140 #include "components/user_manager/user_manager.h" | 141 #include "components/user_manager/user_manager.h" |
141 #include "components/user_manager/user_names.h" | 142 #include "components/user_manager/user_names.h" |
142 #include "components/version_info/version_info.h" | 143 #include "components/version_info/version_info.h" |
143 #include "components/wallpaper/wallpaper_manager_base.h" | 144 #include "components/wallpaper/wallpaper_manager_base.h" |
144 #include "content/public/browser/browser_thread.h" | 145 #include "content/public/browser/browser_thread.h" |
145 #include "content/public/browser/media_capture_devices.h" | 146 #include "content/public/browser/media_capture_devices.h" |
146 #include "content/public/browser/notification_service.h" | 147 #include "content/public/browser/notification_service.h" |
147 #include "content/public/common/content_switches.h" | 148 #include "content/public/common/content_switches.h" |
148 #include "content/public/common/main_function_params.h" | 149 #include "content/public/common/main_function_params.h" |
| 150 #include "crypto/nss_util_internal.h" |
| 151 #include "crypto/scoped_nss_types.h" |
149 #include "dbus/object_path.h" | 152 #include "dbus/object_path.h" |
150 #include "device/bluetooth/bluetooth_adapter_factory.h" | 153 #include "device/bluetooth/bluetooth_adapter_factory.h" |
151 #include "device/bluetooth/dbus/bluez_dbus_manager.h" | 154 #include "device/bluetooth/dbus/bluez_dbus_manager.h" |
152 #include "media/audio/sounds/sounds_manager.h" | 155 #include "media/audio/sounds/sounds_manager.h" |
153 #include "net/base/network_change_notifier.h" | 156 #include "net/base/network_change_notifier.h" |
| 157 #include "net/cert/nss_cert_database.h" |
| 158 #include "net/cert/nss_cert_database_chromeos.h" |
154 #include "net/url_request/url_request.h" | 159 #include "net/url_request/url_request.h" |
155 #include "net/url_request/url_request_context_getter.h" | 160 #include "net/url_request/url_request_context_getter.h" |
156 #include "printing/backend/print_backend.h" | 161 #include "printing/backend/print_backend.h" |
157 #include "rlz/features/features.h" | 162 #include "rlz/features/features.h" |
158 #include "third_party/cros_system_api/dbus/service_constants.h" | 163 #include "third_party/cros_system_api/dbus/service_constants.h" |
159 #include "ui/base/ime/chromeos/ime_keyboard.h" | 164 #include "ui/base/ime/chromeos/ime_keyboard.h" |
160 #include "ui/base/ime/chromeos/input_method_manager.h" | 165 #include "ui/base/ime/chromeos/input_method_manager.h" |
161 #include "ui/base/touch/touch_device.h" | 166 #include "ui/base/touch/touch_device.h" |
162 #include "ui/chromeos/events/event_rewriter_chromeos.h" | 167 #include "ui/chromeos/events/event_rewriter_chromeos.h" |
163 #include "ui/chromeos/events/pref_names.h" | 168 #include "ui/chromeos/events/pref_names.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 ::switches::kTestType)) { | 203 ::switches::kTestType)) { |
199 network_portal_detector::SetNetworkPortalDetector( | 204 network_portal_detector::SetNetworkPortalDetector( |
200 new NetworkPortalDetectorStub()); | 205 new NetworkPortalDetectorStub()); |
201 } else { | 206 } else { |
202 network_portal_detector::SetNetworkPortalDetector( | 207 network_portal_detector::SetNetworkPortalDetector( |
203 new NetworkPortalDetectorImpl( | 208 new NetworkPortalDetectorImpl( |
204 g_browser_process->system_request_context(), true)); | 209 g_browser_process->system_request_context(), true)); |
205 } | 210 } |
206 } | 211 } |
207 | 212 |
| 213 // Called on UI Thread when the system slot has been retrieved. |
| 214 void GotSystemSlotOnUIThread( |
| 215 base::Callback<void(crypto::ScopedPK11Slot)> callback_ui_thread, |
| 216 crypto::ScopedPK11Slot system_slot) { |
| 217 callback_ui_thread.Run(std::move(system_slot)); |
| 218 } |
| 219 |
| 220 // Called on IO Thread when the system slot has been retrieved. |
| 221 void GotSystemSlotOnIOThread( |
| 222 base::Callback<void(crypto::ScopedPK11Slot)> callback_ui_thread, |
| 223 crypto::ScopedPK11Slot system_slot) { |
| 224 content::BrowserThread::PostTask( |
| 225 content::BrowserThread::UI, FROM_HERE, |
| 226 base::BindOnce(&GotSystemSlotOnUIThread, callback_ui_thread, |
| 227 std::move(system_slot))); |
| 228 } |
| 229 |
| 230 // Called on IO Thread, initiates retrieval of system slot. |callback_ui_thread| |
| 231 // will be executed on the UI thread when the system slot has been retrieved. |
| 232 void GetSystemSlotOnIOThread( |
| 233 base::Callback<void(crypto::ScopedPK11Slot)> callback_ui_thread) { |
| 234 auto callback = |
| 235 base::BindRepeating(&GotSystemSlotOnIOThread, callback_ui_thread); |
| 236 crypto::ScopedPK11Slot system_nss_slot = |
| 237 crypto::GetSystemNSSKeySlot(callback); |
| 238 if (system_nss_slot) { |
| 239 callback.Run(std::move(system_nss_slot)); |
| 240 } |
| 241 } |
| 242 |
208 } // namespace | 243 } // namespace |
209 | 244 |
210 namespace internal { | 245 namespace internal { |
211 | 246 |
212 // Wrapper class for initializing dbus related services and shutting them | 247 // Wrapper class for initializing dbus related services and shutting them |
213 // down. This gets instantiated in a scoped_ptr so that shutdown methods in the | 248 // down. This gets instantiated in a scoped_ptr so that shutdown methods in the |
214 // destructor will get called if and only if this has been instantiated. | 249 // destructor will get called if and only if this has been instantiated. |
215 class DBusServices { | 250 class DBusServices { |
216 public: | 251 public: |
217 explicit DBusServices(const content::MainFunctionParams& parameters) { | 252 explicit DBusServices(const content::MainFunctionParams& parameters) { |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 std::unique_ptr<CrosDBusService> cros_dbus_service_; | 393 std::unique_ptr<CrosDBusService> cros_dbus_service_; |
359 | 394 |
360 std::unique_ptr<CrosDBusService> proxy_resolution_service_; | 395 std::unique_ptr<CrosDBusService> proxy_resolution_service_; |
361 std::unique_ptr<CrosDBusService> kiosk_info_service_; | 396 std::unique_ptr<CrosDBusService> kiosk_info_service_; |
362 | 397 |
363 std::unique_ptr<NetworkConnectDelegateChromeOS> network_connect_delegate_; | 398 std::unique_ptr<NetworkConnectDelegateChromeOS> network_connect_delegate_; |
364 | 399 |
365 DISALLOW_COPY_AND_ASSIGN(DBusServices); | 400 DISALLOW_COPY_AND_ASSIGN(DBusServices); |
366 }; | 401 }; |
367 | 402 |
| 403 // Initializes a global NSSCertDatabase for the system token and starts |
| 404 // CertLoader with that database. Note that this is triggered from |
| 405 // PreMainMessageLoopRun, which is executed after PostMainMessageLoopStart, |
| 406 // where CertLoader is initialized. We can thus assume that CertLoader is |
| 407 // initialized. |
| 408 class SystemTokenCertDBInitializer { |
| 409 public: |
| 410 SystemTokenCertDBInitializer() : weak_ptr_factory_(this) {} |
| 411 ~SystemTokenCertDBInitializer() {} |
| 412 |
| 413 // Entry point, called on UI thread. |
| 414 void Initialize() { |
| 415 base::Callback<void(crypto::ScopedPK11Slot)> callback = |
| 416 base::BindRepeating(&SystemTokenCertDBInitializer::InitializeDatabase, |
| 417 weak_ptr_factory_.GetWeakPtr()); |
| 418 content::BrowserThread::PostTask( |
| 419 content::BrowserThread::IO, FROM_HERE, |
| 420 base::BindOnce(&GetSystemSlotOnIOThread, callback)); |
| 421 } |
| 422 |
| 423 private: |
| 424 // Initializes the global system token NSSCertDatabase with |system_slot|. |
| 425 // Also starts CertLoader with the system token database. |
| 426 void InitializeDatabase(crypto::ScopedPK11Slot system_slot) { |
| 427 // Currently, NSSCertDatabase requires a public slot to be set, so we use |
| 428 // the system slot there. We also want GetSystemSlot() to return the system |
| 429 // slot. As ScopedPK11Slot is actually a unique_ptr which will be moved into |
| 430 // the NSSCertDatabase, we need to create a copy, referencing the same slot |
| 431 // (using PK11_ReferenceSlot). |
| 432 crypto::ScopedPK11Slot system_slot_copy = |
| 433 crypto::ScopedPK11Slot(PK11_ReferenceSlot(system_slot.get())); |
| 434 auto database = base::MakeUnique<net::NSSCertDatabaseChromeOS>( |
| 435 std::move(system_slot) /* public_slot */, |
| 436 crypto::ScopedPK11Slot() /* private_slot */); |
| 437 database->SetSystemSlot(std::move(system_slot_copy)); |
| 438 system_token_cert_database_ = std::move(database); |
| 439 |
| 440 CertLoader::Get()->SetSystemNSSDB(system_token_cert_database_.get()); |
| 441 } |
| 442 |
| 443 // Global NSSCertDatabase which sees the system token. |
| 444 std::unique_ptr<net::NSSCertDatabase> system_token_cert_database_; |
| 445 |
| 446 base::WeakPtrFactory<SystemTokenCertDBInitializer> weak_ptr_factory_; |
| 447 }; |
| 448 |
368 } // namespace internal | 449 } // namespace internal |
369 | 450 |
370 // ChromeBrowserMainPartsChromeos ---------------------------------------------- | 451 // ChromeBrowserMainPartsChromeos ---------------------------------------------- |
371 | 452 |
372 ChromeBrowserMainPartsChromeos::ChromeBrowserMainPartsChromeos( | 453 ChromeBrowserMainPartsChromeos::ChromeBrowserMainPartsChromeos( |
373 const content::MainFunctionParams& parameters) | 454 const content::MainFunctionParams& parameters) |
374 : ChromeBrowserMainPartsLinux(parameters) { | 455 : ChromeBrowserMainPartsLinux(parameters) { |
375 } | 456 } |
376 | 457 |
377 ChromeBrowserMainPartsChromeos::~ChromeBrowserMainPartsChromeos() { | 458 ChromeBrowserMainPartsChromeos::~ChromeBrowserMainPartsChromeos() { |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 } | 544 } |
464 | 545 |
465 // Threads are initialized between MainMessageLoopStart and MainMessageLoopRun. | 546 // Threads are initialized between MainMessageLoopStart and MainMessageLoopRun. |
466 // about_flags settings are applied in ChromeBrowserMainParts::PreCreateThreads. | 547 // about_flags settings are applied in ChromeBrowserMainParts::PreCreateThreads. |
467 void ChromeBrowserMainPartsChromeos::PreMainMessageLoopRun() { | 548 void ChromeBrowserMainPartsChromeos::PreMainMessageLoopRun() { |
468 // Set the crypto thread after the IO thread has been created/started. | 549 // Set the crypto thread after the IO thread has been created/started. |
469 TPMTokenLoader::Get()->SetCryptoTaskRunner( | 550 TPMTokenLoader::Get()->SetCryptoTaskRunner( |
470 content::BrowserThread::GetTaskRunnerForThread( | 551 content::BrowserThread::GetTaskRunnerForThread( |
471 content::BrowserThread::IO)); | 552 content::BrowserThread::IO)); |
472 | 553 |
| 554 // Initialize NSS database for system token. |
| 555 TPMTokenLoader::Get()->EnsureStarted(); |
| 556 system_token_certdb_initializer_ = |
| 557 base::MakeUnique<internal::SystemTokenCertDBInitializer>(); |
| 558 system_token_certdb_initializer_->Initialize(); |
| 559 |
473 CrasAudioHandler::Initialize( | 560 CrasAudioHandler::Initialize( |
474 new AudioDevicesPrefHandlerImpl(g_browser_process->local_state())); | 561 new AudioDevicesPrefHandlerImpl(g_browser_process->local_state())); |
475 | 562 |
476 content::MediaCaptureDevices::GetInstance()->AddVideoCaptureObserver( | 563 content::MediaCaptureDevices::GetInstance()->AddVideoCaptureObserver( |
477 CrasAudioHandler::Get()); | 564 CrasAudioHandler::Get()); |
478 | 565 |
479 quirks::QuirksManager::Initialize( | 566 quirks::QuirksManager::Initialize( |
480 std::unique_ptr<quirks::QuirksManager::Delegate>( | 567 std::unique_ptr<quirks::QuirksManager::Delegate>( |
481 new quirks::QuirksManagerDelegateImpl()), | 568 new quirks::QuirksManagerDelegateImpl()), |
482 content::BrowserThread::GetBlockingPool(), | 569 content::BrowserThread::GetBlockingPool(), |
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
992 network_portal_detector::Shutdown(); | 1079 network_portal_detector::Shutdown(); |
993 | 1080 |
994 g_browser_process->platform_part()->ShutdownSessionManager(); | 1081 g_browser_process->platform_part()->ShutdownSessionManager(); |
995 g_browser_process->platform_part()->DestroyChromeUserManager(); | 1082 g_browser_process->platform_part()->DestroyChromeUserManager(); |
996 } | 1083 } |
997 | 1084 |
998 void ChromeBrowserMainPartsChromeos::PostDestroyThreads() { | 1085 void ChromeBrowserMainPartsChromeos::PostDestroyThreads() { |
999 // Destroy DBus services immediately after threads are stopped. | 1086 // Destroy DBus services immediately after threads are stopped. |
1000 dbus_services_.reset(); | 1087 dbus_services_.reset(); |
1001 | 1088 |
| 1089 // Reset SystemTokenCertDBInitializer after DBus services because it should |
| 1090 // outlive CertLoader. |
| 1091 system_token_certdb_initializer_.reset(); |
| 1092 |
1002 ChromeBrowserMainPartsLinux::PostDestroyThreads(); | 1093 ChromeBrowserMainPartsLinux::PostDestroyThreads(); |
1003 | 1094 |
1004 // Destroy DeviceSettingsService after g_browser_process. | 1095 // Destroy DeviceSettingsService after g_browser_process. |
1005 DeviceSettingsService::Shutdown(); | 1096 DeviceSettingsService::Shutdown(); |
1006 | 1097 |
1007 chromeos::ShutdownCloseTracking(); | 1098 chromeos::ShutdownCloseTracking(); |
1008 } | 1099 } |
1009 | 1100 |
1010 } // namespace chromeos | 1101 } // namespace chromeos |
OLD | NEW |