Migrate example & mock call-sites off QuitCurrent*Deprecated().
- Migrate //mash and //ui/views examples off QuitCurrent*Deprecated(). - Migrate //net mock off it as well. These are the final remaining call-sites that codesearch identifies as not-test-specific (even though the mock is a mock ;). Bug: 859095 Change-Id: I417f9c93aa6ef6eaae4cf22948e07750d176d83d Reviewed-on: https://chromium-review.googlesource.com/1226455 Commit-Queue: Wez <wez@chromium.org> Reviewed-by: Scott Violet <sky@chromium.org> Cr-Commit-Position: refs/heads/master@{#593230}
This commit is contained in:
ash/shell
mash
catalog_viewer
example
task_viewer
net/proxy_resolution
ui
@ -19,6 +19,7 @@
|
||||
#include "ash/shell.h"
|
||||
#include "ash/shell/example_factory.h"
|
||||
#include "ash/shell/toplevel_window.h"
|
||||
#include "base/bind_helpers.h"
|
||||
#include "base/callback.h"
|
||||
#include "base/files/file_path.h"
|
||||
#include "base/i18n/case_conversion.h"
|
||||
@ -119,7 +120,7 @@ class WindowTypeShelfItem : public app_list::AppListItem {
|
||||
break;
|
||||
}
|
||||
case EXAMPLES_WINDOW: {
|
||||
views::examples::ShowExamplesWindow(views::examples::QUIT_ON_CLOSE);
|
||||
views::examples::ShowExamplesWindow(base::DoNothing());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -104,9 +104,10 @@ void ShellBrowserMainParts::PreMainMessageLoopRun() {
|
||||
|
||||
window_watcher_ = std::make_unique<WindowWatcher>();
|
||||
|
||||
ash::shell::InitWindowTypeLauncher(base::Bind(
|
||||
&views::examples::ShowExamplesWindowWithContent,
|
||||
views::examples::DO_NOTHING_ON_CLOSE, browser_context_.get(), nullptr));
|
||||
ash::shell::InitWindowTypeLauncher(
|
||||
base::Bind(&views::examples::ShowExamplesWindowWithContent,
|
||||
base::Passed(base::OnceClosure()),
|
||||
base::Unretained(browser_context_.get()), nullptr));
|
||||
|
||||
ash::Shell::GetPrimaryRootWindow()->GetHost()->Show();
|
||||
|
||||
|
@ -218,7 +218,7 @@ void CatalogViewer::RemoveWindow(views::Widget* window) {
|
||||
DCHECK(it != windows_.end());
|
||||
windows_.erase(it);
|
||||
if (windows_.empty())
|
||||
base::RunLoop::QuitCurrentWhenIdleDeprecated();
|
||||
context()->QuitNow();
|
||||
}
|
||||
|
||||
void CatalogViewer::OnStart() {
|
||||
|
@ -46,7 +46,9 @@ class ViewsExamples : public service_manager::Service,
|
||||
|
||||
// mash::mojom::Launchable:
|
||||
void Launch(uint32_t what, mash::mojom::LaunchMode how) override {
|
||||
views::examples::ShowExamplesWindow(views::examples::QUIT_ON_CLOSE);
|
||||
views::examples::ShowExamplesWindow(
|
||||
base::BindOnce(&service_manager::ServiceContext::QuitNow,
|
||||
base::Unretained(context())));
|
||||
}
|
||||
|
||||
void Create(mash::mojom::LaunchableRequest request) {
|
||||
|
@ -449,7 +449,7 @@ void WindowTypeLauncher::RemoveWindow(views::Widget* window) {
|
||||
DCHECK(it != windows_.end());
|
||||
windows_.erase(it);
|
||||
if (windows_.empty())
|
||||
base::RunLoop::QuitCurrentWhenIdleDeprecated();
|
||||
context()->QuitNow();
|
||||
}
|
||||
|
||||
void WindowTypeLauncher::OnStart() {
|
||||
|
@ -293,7 +293,7 @@ void TaskViewer::RemoveWindow(views::Widget* widget) {
|
||||
DCHECK(it != windows_.end());
|
||||
windows_.erase(it);
|
||||
if (windows_.empty())
|
||||
base::RunLoop::QuitCurrentWhenIdleDeprecated();
|
||||
context()->QuitNow();
|
||||
}
|
||||
|
||||
void TaskViewer::OnStart() {
|
||||
|
@ -15,7 +15,6 @@ namespace net {
|
||||
|
||||
MockPacFileFetcher::MockPacFileFetcher()
|
||||
: pending_request_text_(NULL),
|
||||
waiting_for_fetch_(false),
|
||||
is_shutdown_(false) {}
|
||||
|
||||
MockPacFileFetcher::~MockPacFileFetcher() = default;
|
||||
@ -28,8 +27,8 @@ int MockPacFileFetcher::Fetch(
|
||||
const NetworkTrafficAnnotationTag traffic_annotation) {
|
||||
DCHECK(!has_pending_request());
|
||||
|
||||
if (waiting_for_fetch_)
|
||||
base::RunLoop::QuitCurrentWhenIdleDeprecated();
|
||||
if (on_fetch_complete_)
|
||||
std::move(on_fetch_complete_).Run();
|
||||
|
||||
if (is_shutdown_)
|
||||
return ERR_CONTEXT_SHUT_DOWN;
|
||||
@ -74,9 +73,9 @@ bool MockPacFileFetcher::has_pending_request() const {
|
||||
|
||||
void MockPacFileFetcher::WaitUntilFetch() {
|
||||
DCHECK(!has_pending_request());
|
||||
waiting_for_fetch_ = true;
|
||||
base::RunLoop().Run();
|
||||
waiting_for_fetch_ = false;
|
||||
base::RunLoop run_loop;
|
||||
on_fetch_complete_ = run_loop.QuitClosure();
|
||||
run_loop.Run();
|
||||
}
|
||||
|
||||
} // namespace net
|
||||
|
@ -44,7 +44,7 @@ class MockPacFileFetcher : public PacFileFetcher {
|
||||
GURL pending_request_url_;
|
||||
CompletionOnceCallback pending_request_callback_;
|
||||
base::string16* pending_request_text_;
|
||||
bool waiting_for_fetch_;
|
||||
base::OnceClosure on_fetch_complete_;
|
||||
bool is_shutdown_;
|
||||
};
|
||||
|
||||
|
@ -118,9 +118,10 @@ int main(int argc, char** argv) {
|
||||
display::Screen::SetScreenInstance(desktop_screen.get());
|
||||
#endif
|
||||
|
||||
views::examples::ShowExamplesWindow(views::examples::QUIT_ON_CLOSE);
|
||||
base::RunLoop run_loop;
|
||||
views::examples::ShowExamplesWindow(run_loop.QuitClosure());
|
||||
|
||||
base::RunLoop().Run();
|
||||
run_loop.Run();
|
||||
|
||||
ui::ResourceBundle::CleanupSharedInstance();
|
||||
}
|
||||
|
@ -131,11 +131,11 @@ class ComboboxModelExampleList : public ui::ComboboxModel {
|
||||
class ExamplesWindowContents : public WidgetDelegateView,
|
||||
public ComboboxListener {
|
||||
public:
|
||||
ExamplesWindowContents(Operation operation, ExampleVector examples)
|
||||
ExamplesWindowContents(base::OnceClosure on_close, ExampleVector examples)
|
||||
: combobox_(new Combobox(&combobox_model_)),
|
||||
example_shown_(new View),
|
||||
status_label_(new Label),
|
||||
operation_(operation) {
|
||||
on_close_(std::move(on_close)) {
|
||||
instance_ = this;
|
||||
combobox_->set_listener(this);
|
||||
combobox_model_.SetExamples(std::move(examples));
|
||||
@ -188,8 +188,8 @@ class ExamplesWindowContents : public WidgetDelegateView,
|
||||
}
|
||||
void WindowClosing() override {
|
||||
instance_ = NULL;
|
||||
if (operation_ == QUIT_ON_CLOSE)
|
||||
base::RunLoop::QuitCurrentWhenIdleDeprecated();
|
||||
if (on_close_)
|
||||
std::move(on_close_).Run();
|
||||
}
|
||||
gfx::Size CalculatePreferredSize() const override {
|
||||
return gfx::Size(800, 300);
|
||||
@ -212,7 +212,7 @@ class ExamplesWindowContents : public WidgetDelegateView,
|
||||
Combobox* combobox_;
|
||||
View* example_shown_;
|
||||
Label* status_label_;
|
||||
const Operation operation_;
|
||||
base::OnceClosure on_close_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(ExamplesWindowContents);
|
||||
};
|
||||
@ -220,7 +220,7 @@ class ExamplesWindowContents : public WidgetDelegateView,
|
||||
// static
|
||||
ExamplesWindowContents* ExamplesWindowContents::instance_ = NULL;
|
||||
|
||||
void ShowExamplesWindow(Operation operation,
|
||||
void ShowExamplesWindow(base::OnceClosure on_close,
|
||||
gfx::NativeWindow window_context,
|
||||
ExampleVector extra_examples) {
|
||||
if (ExamplesWindowContents::instance()) {
|
||||
@ -230,7 +230,7 @@ void ShowExamplesWindow(Operation operation,
|
||||
Widget* widget = new Widget;
|
||||
Widget::InitParams params;
|
||||
params.delegate =
|
||||
new ExamplesWindowContents(operation, std::move(examples));
|
||||
new ExamplesWindowContents(std::move(on_close), std::move(examples));
|
||||
params.context = window_context;
|
||||
widget->Init(params);
|
||||
widget->Show();
|
||||
|
@ -15,16 +15,11 @@
|
||||
namespace views {
|
||||
namespace examples {
|
||||
|
||||
enum Operation {
|
||||
DO_NOTHING_ON_CLOSE = 0,
|
||||
QUIT_ON_CLOSE,
|
||||
};
|
||||
|
||||
// Shows a window with the views examples in it. |extra_examples| contains any
|
||||
// additional examples to add. |window_context| is used to determine where the
|
||||
// window should be created (see |Widget::InitParams::context| for details).
|
||||
VIEWS_EXAMPLES_EXPORT void ShowExamplesWindow(
|
||||
Operation operation,
|
||||
base::OnceClosure on_close,
|
||||
gfx::NativeWindow window_context = nullptr,
|
||||
std::vector<std::unique_ptr<ExampleBase>> extra_examples =
|
||||
std::vector<std::unique_ptr<ExampleBase>>());
|
||||
|
@ -14,12 +14,13 @@
|
||||
namespace views {
|
||||
namespace examples {
|
||||
|
||||
void ShowExamplesWindowWithContent(Operation operation,
|
||||
void ShowExamplesWindowWithContent(base::OnceClosure on_close,
|
||||
content::BrowserContext* browser_context,
|
||||
gfx::NativeWindow window_context) {
|
||||
std::vector<std::unique_ptr<ExampleBase>> extra_examples;
|
||||
extra_examples.push_back(std::make_unique<WebViewExample>(browser_context));
|
||||
ShowExamplesWindow(operation, window_context, std::move(extra_examples));
|
||||
ShowExamplesWindow(std::move(on_close), window_context,
|
||||
std::move(extra_examples));
|
||||
}
|
||||
|
||||
} // namespace examples
|
||||
|
@ -18,7 +18,7 @@ namespace examples {
|
||||
|
||||
// Shows a window with the views examples in it.
|
||||
VIEWS_EXAMPLES_WITH_CONTENT_EXPORT void ShowExamplesWindowWithContent(
|
||||
Operation operation,
|
||||
base::OnceClosure on_close,
|
||||
content::BrowserContext* browser_context,
|
||||
gfx::NativeWindow window_context);
|
||||
|
||||
|
@ -15,11 +15,12 @@
|
||||
|
||||
namespace {
|
||||
|
||||
void ShowContentExampleWindow(content::BrowserContext* browser_context,
|
||||
void ShowContentExampleWindow(ui::ViewsContentClient* views_content_client,
|
||||
content::BrowserContext* browser_context,
|
||||
gfx::NativeWindow window_context) {
|
||||
views::examples::ShowExamplesWindowWithContent(views::examples::QUIT_ON_CLOSE,
|
||||
browser_context,
|
||||
window_context);
|
||||
views::examples::ShowExamplesWindowWithContent(
|
||||
std::move(views_content_client->quit_closure()), browser_context,
|
||||
window_context);
|
||||
|
||||
// These lines serve no purpose other than to introduce an explicit content
|
||||
// dependency. If the main executable doesn't have this dependency, the linker
|
||||
@ -45,6 +46,7 @@ int main(int argc, const char** argv) {
|
||||
ui::ViewsContentClient views_content_client(argc, argv);
|
||||
#endif
|
||||
|
||||
views_content_client.set_task(base::Bind(&ShowContentExampleWindow));
|
||||
views_content_client.set_task(base::Bind(
|
||||
&ShowContentExampleWindow, base::Unretained(&views_content_client)));
|
||||
return views_content_client.RunMain();
|
||||
}
|
||||
|
@ -66,6 +66,13 @@ class VIEWS_CONTENT_CLIENT_EXPORT ViewsContentClient {
|
||||
void set_task(const Task& task) { task_ = task; }
|
||||
const Task& task() const { return task_; }
|
||||
|
||||
// Called by ViewsContentClientMainParts to supply the quit-closure to use
|
||||
// to exit RunMain().
|
||||
void set_quit_closure(base::OnceClosure quit_closure) {
|
||||
quit_closure_ = std::move(quit_closure);
|
||||
}
|
||||
base::OnceClosure& quit_closure() { return quit_closure_; }
|
||||
|
||||
private:
|
||||
#if defined(OS_WIN)
|
||||
HINSTANCE instance_;
|
||||
@ -75,6 +82,7 @@ class VIEWS_CONTENT_CLIENT_EXPORT ViewsContentClient {
|
||||
const char** argv_;
|
||||
#endif
|
||||
Task task_;
|
||||
base::OnceClosure quit_closure_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(ViewsContentClient);
|
||||
};
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "ui/base/ime/input_method_initializer.h"
|
||||
#include "ui/base/material_design/material_design_controller.h"
|
||||
#include "ui/views/test/desktop_test_views_delegate.h"
|
||||
#include "ui/views_content_client/views_content_client.h"
|
||||
|
||||
namespace ui {
|
||||
|
||||
@ -44,6 +45,7 @@ void ViewsContentClientMainParts::PostMainMessageLoopRun() {
|
||||
|
||||
bool ViewsContentClientMainParts::MainMessageLoopRun(int* result_code) {
|
||||
base::RunLoop run_loop;
|
||||
views_content_client_->set_quit_closure(run_loop.QuitClosure());
|
||||
run_loop.Run();
|
||||
return true;
|
||||
}
|
||||
|
Reference in New Issue
Block a user