Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(17)

Side by Side Diff: mojo/shell/public/cpp/lib/application_runner.cc

Issue 1675083002: Rename ApplicationDelegate to ShellClient (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@delegate
Patch Set: . Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "mojo/shell/public/cpp/application_runner.h" 5 #include "mojo/shell/public/cpp/application_runner.h"
6 6
7 #include "base/at_exit.h" 7 #include "base/at_exit.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "base/process/launch.h" 11 #include "base/process/launch.h"
12 #include "mojo/message_pump/message_pump_mojo.h" 12 #include "mojo/message_pump/message_pump_mojo.h"
13 #include "mojo/shell/public/cpp/application_delegate.h"
14 #include "mojo/shell/public/cpp/application_impl.h" 13 #include "mojo/shell/public/cpp/application_impl.h"
14 #include "mojo/shell/public/cpp/shell_client.h"
15 15
16 namespace mojo { 16 namespace mojo {
17 17
18 int g_application_runner_argc; 18 int g_application_runner_argc;
19 const char* const* g_application_runner_argv; 19 const char* const* g_application_runner_argv;
20 20
21 ApplicationRunner::ApplicationRunner(ApplicationDelegate* delegate) 21 ApplicationRunner::ApplicationRunner(ShellClient* client)
22 : delegate_(scoped_ptr<ApplicationDelegate>(delegate)), 22 : client_(scoped_ptr<ShellClient>(client)),
23 message_loop_type_(base::MessageLoop::TYPE_CUSTOM), 23 message_loop_type_(base::MessageLoop::TYPE_CUSTOM),
24 has_run_(false) {} 24 has_run_(false) {}
25 25
26 ApplicationRunner::~ApplicationRunner() {} 26 ApplicationRunner::~ApplicationRunner() {}
27 27
28 void ApplicationRunner::InitBaseCommandLine() { 28 void ApplicationRunner::InitBaseCommandLine() {
29 base::CommandLine::Init(g_application_runner_argc, g_application_runner_argv); 29 base::CommandLine::Init(g_application_runner_argc, g_application_runner_argv);
30 } 30 }
31 31
32 void ApplicationRunner::set_message_loop_type(base::MessageLoop::Type type) { 32 void ApplicationRunner::set_message_loop_type(base::MessageLoop::Type type) {
(...skipping 14 matching lines...) Expand all
47 at_exit.reset(new base::AtExitManager); 47 at_exit.reset(new base::AtExitManager);
48 } 48 }
49 49
50 { 50 {
51 scoped_ptr<base::MessageLoop> loop; 51 scoped_ptr<base::MessageLoop> loop;
52 if (message_loop_type_ == base::MessageLoop::TYPE_CUSTOM) 52 if (message_loop_type_ == base::MessageLoop::TYPE_CUSTOM)
53 loop.reset(new base::MessageLoop(common::MessagePumpMojo::Create())); 53 loop.reset(new base::MessageLoop(common::MessagePumpMojo::Create()));
54 else 54 else
55 loop.reset(new base::MessageLoop(message_loop_type_)); 55 loop.reset(new base::MessageLoop(message_loop_type_));
56 56
57 ApplicationImpl impl(delegate_.get(), 57 ApplicationImpl impl(client_.get(),
58 MakeRequest<shell::mojom::Application>( 58 MakeRequest<shell::mojom::Application>(
59 MakeScopedHandle(MessagePipeHandle( 59 MakeScopedHandle(MessagePipeHandle(
60 application_request_handle)))); 60 application_request_handle))));
61 loop->Run(); 61 loop->Run();
62 // It's very common for the delegate to cache the app and terminate on 62 // It's very common for the client to cache the app and terminate on errors.
63 // errors. If we don't delete the delegate before the app we run the risk 63 // If we don't delete the client before the app we run the risk of the
64 // of the delegate having a stale reference to the app and trying to use it. 64 // client having a stale reference to the app and trying to use it.
65 // Note that we destruct the message loop first because that might trigger 65 // Note that we destruct the message loop first because that might trigger
66 // connection error handlers and they might access objects created by the 66 // connection error handlers and they might access objects created by the
67 // delegate. 67 // client.
68 loop.reset(); 68 loop.reset();
69 delegate_.reset(); 69 client_.reset();
70 } 70 }
71 return MOJO_RESULT_OK; 71 return MOJO_RESULT_OK;
72 } 72 }
73 73
74 MojoResult ApplicationRunner::Run(MojoHandle application_request_handle) { 74 MojoResult ApplicationRunner::Run(MojoHandle application_request_handle) {
75 return Run(application_request_handle, true); 75 return Run(application_request_handle, true);
76 } 76 }
77 77
78 } // namespace mojo 78 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/shell/public/cpp/lib/application_impl.cc ('k') | mojo/shell/public/cpp/lib/application_test_base.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698