chrome_process_singleton.cc 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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
  3. // found in the LICENSE file.
  4. #include "chrome/browser/chrome_process_singleton.h"
  5. #include <utility>
  6. #include "chrome/browser/headless/headless_mode_util.h"
  7. ChromeProcessSingleton::ChromeProcessSingleton(
  8. const base::FilePath& user_data_dir)
  9. : startup_lock_(
  10. base::BindRepeating(&ChromeProcessSingleton::NotificationCallback,
  11. base::Unretained(this))),
  12. modal_dialog_lock_(startup_lock_.AsNotificationCallback()),
  13. process_singleton_(user_data_dir,
  14. modal_dialog_lock_.AsNotificationCallback()) {}
  15. ChromeProcessSingleton::~ChromeProcessSingleton() = default;
  16. ProcessSingleton::NotifyResult
  17. ChromeProcessSingleton::NotifyOtherProcessOrCreate() {
  18. // In headless mode we don't want to hand off pages to an existing processes,
  19. // so short circuit process singleton creation and bail out if we're not
  20. // the only process using this user data dir.
  21. if (headless::IsChromeNativeHeadless()) {
  22. return process_singleton_.Create() ? ProcessSingleton::PROCESS_NONE
  23. : ProcessSingleton::PROFILE_IN_USE;
  24. }
  25. return process_singleton_.NotifyOtherProcessOrCreate();
  26. }
  27. void ChromeProcessSingleton::StartWatching() {
  28. process_singleton_.StartWatching();
  29. }
  30. void ChromeProcessSingleton::Cleanup() {
  31. process_singleton_.Cleanup();
  32. }
  33. void ChromeProcessSingleton::SetModalDialogNotificationHandler(
  34. base::RepeatingClosure notification_handler) {
  35. modal_dialog_lock_.SetModalDialogNotificationHandler(
  36. std::move(notification_handler));
  37. }
  38. void ChromeProcessSingleton::Unlock(
  39. const ProcessSingleton::NotificationCallback& notification_callback) {
  40. notification_callback_ = notification_callback;
  41. startup_lock_.Unlock();
  42. }
  43. bool ChromeProcessSingleton::NotificationCallback(
  44. const base::CommandLine& command_line,
  45. const base::FilePath& current_directory) {
  46. DCHECK(notification_callback_);
  47. return notification_callback_.Run(command_line, current_directory);
  48. }