win: Don't hang when failed to create thread
This commit is contained in:
parent
c20e1e9d82
commit
63e83a7ef8
1 changed files with 25 additions and 14 deletions
|
@ -119,6 +119,17 @@ struct RunState {
|
||||||
base::MessageLoop* ui_message_loop;
|
base::MessageLoop* ui_message_loop;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bool CreateDialogThread(RunState* run_state) {
|
||||||
|
base::Thread* thread = new base::Thread("AtomShell_FileDialogThread");
|
||||||
|
thread->init_com_with_mta(false);
|
||||||
|
if (!thread->Start())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
run_state->dialog_thread = thread;
|
||||||
|
run_state->ui_message_loop = base::MessageLoop::current();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void RunOpenDialogInNewThread(const RunState& run_state,
|
void RunOpenDialogInNewThread(const RunState& run_state,
|
||||||
atom::NativeWindow* parent,
|
atom::NativeWindow* parent,
|
||||||
const std::string& title,
|
const std::string& title,
|
||||||
|
@ -202,16 +213,16 @@ void ShowOpenDialog(atom::NativeWindow* parent,
|
||||||
const Filters& filters,
|
const Filters& filters,
|
||||||
int properties,
|
int properties,
|
||||||
const OpenDialogCallback& callback) {
|
const OpenDialogCallback& callback) {
|
||||||
base::Thread* thread = new base::Thread("AtomShell_FileDialogThread");
|
RunState run_state;
|
||||||
thread->init_com_with_mta(false);
|
if (!CreateDialogThread(&run_state)) {
|
||||||
if (!thread->Start())
|
callback.Run(false, std::vector<base::FilePath>());
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
RunState state = { thread, base::MessageLoop::current() };
|
run_state.dialog_thread->message_loop()->PostTask(
|
||||||
thread->message_loop()->PostTask(
|
|
||||||
FROM_HERE,
|
FROM_HERE,
|
||||||
base::Bind(&RunOpenDialogInNewThread, state, parent, title, default_path,
|
base::Bind(&RunOpenDialogInNewThread, run_state, parent, title,
|
||||||
filters, properties, callback));
|
default_path, filters, properties, callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ShowSaveDialog(atom::NativeWindow* parent_window,
|
bool ShowSaveDialog(atom::NativeWindow* parent_window,
|
||||||
|
@ -259,16 +270,16 @@ void ShowSaveDialog(atom::NativeWindow* parent,
|
||||||
const base::FilePath& default_path,
|
const base::FilePath& default_path,
|
||||||
const Filters& filters,
|
const Filters& filters,
|
||||||
const SaveDialogCallback& callback) {
|
const SaveDialogCallback& callback) {
|
||||||
base::Thread* thread = new base::Thread("AtomShell_FileDialogThread");
|
RunState run_state;
|
||||||
thread->init_com_with_mta(false);
|
if (!CreateDialogThread(&run_state)) {
|
||||||
if (!thread->Start())
|
callback.Run(false, base::FilePath());
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
RunState state = { thread, base::MessageLoop::current() };
|
run_state.dialog_thread->message_loop()->PostTask(
|
||||||
thread->message_loop()->PostTask(
|
|
||||||
FROM_HERE,
|
FROM_HERE,
|
||||||
base::Bind(&RunSaveDialogInNewThread, state, parent, title, default_path,
|
base::Bind(&RunSaveDialogInNewThread, run_state, parent, title,
|
||||||
filters, callback));
|
default_path, filters, callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace file_dialog
|
} // namespace file_dialog
|
||||||
|
|
Loading…
Reference in a new issue