diff --git a/atom/browser/api/atom_api_app.cc b/atom/browser/api/atom_api_app.cc index fc946567b11..d01f3f3749a 100644 --- a/atom/browser/api/atom_api_app.cc +++ b/atom/browser/api/atom_api_app.cc @@ -407,7 +407,12 @@ bool NotificationCallbackWrapper( const base::FilePath& cwd) { // Make sure the callback is called after app gets ready. if (Browser::Get()->is_ready()) { - callback.Run(cmd, cwd); + // We definitely want to call this callback on the UI thread + content::BrowserThread::PostTask( + content::BrowserThread::UI, + FROM_HERE, + base::Bind(base::IgnoreResult(callback), cmd, cwd) + ); } else { scoped_refptr task_runner( base::ThreadTaskRunnerHandle::Get()); @@ -522,7 +527,6 @@ App::App(v8::Isolate* isolate) { base::ProcessMetrics::CreateCurrentProcessMetrics())); app_metrics_[pid] = std::move(process_metric); Init(isolate); - App::self_ = this; } App::~App() { @@ -533,12 +537,6 @@ App::~App() { content::BrowserChildProcessObserver::Remove(this); } -App* App::self_ = nullptr; - -App* App::Get() { - return App::self_; -} - void App::OnBeforeQuit(bool* prevent_default) { *prevent_default = Emit("before-quit"); } @@ -586,7 +584,7 @@ void App::OnFinishLaunching(const base::DictionaryValue& launch_info) { Emit("ready", launch_info); } -void App::PreMainMessageLoopRun() { +void App::OnPreMainMessageLoopRun() { if (process_singleton_) { process_singleton_->OnBrowserReady(); } diff --git a/atom/browser/api/atom_api_app.h b/atom/browser/api/atom_api_app.h index 82403e9da44..6d54b85a9e4 100644 --- a/atom/browser/api/atom_api_app.h +++ b/atom/browser/api/atom_api_app.h @@ -74,8 +74,6 @@ class App : public AtomBrowserClient::Delegate, static void BuildPrototype(v8::Isolate* isolate, v8::Local prototype); - static App* Get(); - // Called when window with disposition needs to be created. void OnCreateWindow( const GURL& target_url, @@ -101,7 +99,6 @@ class App : public AtomBrowserClient::Delegate, protected: explicit App(v8::Isolate* isolate); ~App() override; - static App* self_; // BrowserObserver: void OnBeforeQuit(bool* prevent_default) override; @@ -116,6 +113,7 @@ class App : public AtomBrowserClient::Delegate, void OnLogin(LoginHandler* login_handler, const base::DictionaryValue& request_details) override; void OnAccessibilitySupportChanged() override; + void OnPreMainMessageLoopRun() override; #if defined(OS_MACOSX) void OnWillContinueUserActivity( bool* prevent_default, diff --git a/atom/browser/atom_browser_main_parts.cc b/atom/browser/atom_browser_main_parts.cc index 7d2cf4fc1b6..89ab75c33cb 100644 --- a/atom/browser/atom_browser_main_parts.cc +++ b/atom/browser/atom_browser_main_parts.cc @@ -185,7 +185,7 @@ void AtomBrowserMainParts::PreMainMessageLoopRun() { Browser::Get()->DidFinishLaunching(*empty_info); #endif - atom::api::App::Get()->PreMainMessageLoopRun(); + Browser::Get()->PreMainMessageLoopRun(); } bool AtomBrowserMainParts::MainMessageLoopRun(int* result_code) { diff --git a/atom/browser/browser.cc b/atom/browser/browser.cc index c714dc1f46a..1e4bc5e8e72 100644 --- a/atom/browser/browser.cc +++ b/atom/browser/browser.cc @@ -171,6 +171,12 @@ void Browser::RequestLogin( observer.OnLogin(login_handler, *(request_details.get())); } +void Browser::PreMainMessageLoopRun() { + for (BrowserObserver& observer : observers_) { + observer.OnPreMainMessageLoopRun(); + } +} + void Browser::NotifyAndShutdown() { if (is_shutdown_) return; diff --git a/atom/browser/browser.h b/atom/browser/browser.h index 3549d45a8aa..b5e31160c8f 100644 --- a/atom/browser/browser.h +++ b/atom/browser/browser.h @@ -224,6 +224,8 @@ class Browser : public WindowListObserver { void RequestLogin(LoginHandler* login_handler, std::unique_ptr request_details); + void PreMainMessageLoopRun(); + void AddObserver(BrowserObserver* obs) { observers_.AddObserver(obs); } diff --git a/atom/browser/browser_observer.h b/atom/browser/browser_observer.h index d6b2c9954a1..987e37115e7 100644 --- a/atom/browser/browser_observer.h +++ b/atom/browser/browser_observer.h @@ -55,6 +55,9 @@ class BrowserObserver { // The browser's accessibility suppport has changed. virtual void OnAccessibilitySupportChanged() {} + // The app message loop is ready + virtual void OnPreMainMessageLoopRun() {} + #if defined(OS_MACOSX) // The browser wants to report that an user activity will resume. (macOS only) virtual void OnWillContinueUserActivity( diff --git a/chromium_src/chrome/browser/process_singleton_posix.cc b/chromium_src/chrome/browser/process_singleton_posix.cc index 5c7c7cccde7..6ea5b545279 100644 --- a/chromium_src/chrome/browser/process_singleton_posix.cc +++ b/chromium_src/chrome/browser/process_singleton_posix.cc @@ -1048,10 +1048,9 @@ bool ProcessSingleton::Create() { if (listen(sock, 5) < 0) NOTREACHED() << "listen failed: " << base::safe_strerror(errno); - DCHECK(BrowserThread::IsMessageLoopValid(BrowserThread::IO)); sock_ = sock; - - if (atom::Browser::Get()->is_ready()) { + + if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) { StartListeningOnSocket(); } else { listen_on_ready_ = true;