refactor: add promise helper and change whenReady to be native impl (#13115)

* Add promise helper and change whenReady to be native impl

* remove commented code

* add GetInner helper to dedupe promise code

* add Promise.reject helper to be consistent with JS

* fix linting

* update promise impl per feedback

* remove param name from unused isolate

* Use non-depreceated resolvers for promises

* Add thread dchecks for promise helper, intiialize promise pointer to nullptr
This commit is contained in:
Samuel Attard 2018-06-28 07:06:08 +10:00 committed by Charles Kerr
parent e9971173d4
commit 92588be2bd
8 changed files with 145 additions and 18 deletions

View file

@ -154,10 +154,23 @@ void Browser::DidFinishLaunching(const base::DictionaryValue& launch_info) {
base::CreateDirectoryAndGetError(user_data, nullptr);
is_ready_ = true;
if (ready_promise_) {
ready_promise_->Resolve();
}
for (BrowserObserver& observer : observers_)
observer.OnFinishLaunching(launch_info);
}
util::Promise* Browser::WhenReady(v8::Isolate* isolate) {
if (!ready_promise_) {
ready_promise_ = new util::Promise(isolate);
if (is_ready()) {
ready_promise_->Resolve();
}
}
return ready_promise_;
}
void Browser::OnAccessibilitySupportChanged() {
for (BrowserObserver& observer : observers_)
observer.OnAccessibilitySupportChanged();