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

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

Issue 1882423004: Move shell service to toplevel shell namespace (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 8 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 "services/shell/public/cpp/application_runner.h" 5 #include "services/shell/public/cpp/application_runner.h"
6 6
7 #include "base/at_exit.h" 7 #include "base/at_exit.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
12 #include "base/process/launch.h" 11 #include "base/process/launch.h"
13 #include "base/run_loop.h" 12 #include "base/run_loop.h"
14 #include "services/shell/public/cpp/shell_client.h" 13 #include "services/shell/public/cpp/shell_client.h"
15 #include "services/shell/public/cpp/shell_connection.h" 14 #include "services/shell/public/cpp/shell_connection.h"
16 15
17 namespace mojo { 16 namespace shell {
18 17
19 int g_application_runner_argc; 18 int g_application_runner_argc;
20 const char* const* g_application_runner_argv; 19 const char* const* g_application_runner_argv;
21 20
22 ApplicationRunner::ApplicationRunner(ShellClient* client) 21 ApplicationRunner::ApplicationRunner(ShellClient* client)
23 : client_(scoped_ptr<ShellClient>(client)), 22 : client_(std::unique_ptr<ShellClient>(client)),
24 message_loop_type_(base::MessageLoop::TYPE_DEFAULT), 23 message_loop_type_(base::MessageLoop::TYPE_DEFAULT),
25 has_run_(false) {} 24 has_run_(false) {}
26 25
27 ApplicationRunner::~ApplicationRunner() {} 26 ApplicationRunner::~ApplicationRunner() {}
28 27
29 void ApplicationRunner::InitBaseCommandLine() { 28 void ApplicationRunner::InitBaseCommandLine() {
30 base::CommandLine::Init(g_application_runner_argc, g_application_runner_argv); 29 base::CommandLine::Init(g_application_runner_argc, g_application_runner_argv);
31 } 30 }
32 31
33 void ApplicationRunner::set_message_loop_type(base::MessageLoop::Type type) { 32 void ApplicationRunner::set_message_loop_type(base::MessageLoop::Type type) {
34 DCHECK_NE(base::MessageLoop::TYPE_CUSTOM, type); 33 DCHECK_NE(base::MessageLoop::TYPE_CUSTOM, type);
35 DCHECK(!has_run_); 34 DCHECK(!has_run_);
36 35
37 message_loop_type_ = type; 36 message_loop_type_ = type;
38 } 37 }
39 38
40 MojoResult ApplicationRunner::Run(MojoHandle shell_client_request_handle, 39 MojoResult ApplicationRunner::Run(MojoHandle shell_client_request_handle,
41 bool init_base) { 40 bool init_base) {
42 DCHECK(!has_run_); 41 DCHECK(!has_run_);
43 has_run_ = true; 42 has_run_ = true;
44 43
45 scoped_ptr<base::AtExitManager> at_exit; 44 std::unique_ptr<base::AtExitManager> at_exit;
46 if (init_base) { 45 if (init_base) {
47 InitBaseCommandLine(); 46 InitBaseCommandLine();
48 at_exit.reset(new base::AtExitManager); 47 at_exit.reset(new base::AtExitManager);
49 } 48 }
50 49
51 { 50 {
52 scoped_ptr<base::MessageLoop> loop; 51 std::unique_ptr<base::MessageLoop> loop;
53 loop.reset(new base::MessageLoop(message_loop_type_)); 52 loop.reset(new base::MessageLoop(message_loop_type_));
54 53
55 connection_.reset(new ShellConnection( 54 connection_.reset(new ShellConnection(
56 client_.get(), 55 client_.get(),
57 MakeRequest<shell::mojom::ShellClient>(MakeScopedHandle( 56 mojo::MakeRequest<mojom::ShellClient>(mojo::MakeScopedHandle(
58 MessagePipeHandle(shell_client_request_handle))))); 57 mojo::MessagePipeHandle(shell_client_request_handle)))));
59 base::RunLoop run_loop; 58 base::RunLoop run_loop;
60 connection_->set_connection_lost_closure(run_loop.QuitClosure()); 59 connection_->set_connection_lost_closure(run_loop.QuitClosure());
61 run_loop.Run(); 60 run_loop.Run();
62 // It's very common for the client to cache the app and terminate on errors. 61 // It's very common for the client to cache the app and terminate on errors.
63 // If we don't delete the client before the app we run the risk of the 62 // If we don't delete the client before the app we run the risk of the
64 // client having a stale reference to the app and trying to use it. 63 // 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 64 // Note that we destruct the message loop first because that might trigger
66 // connection error handlers and they might access objects created by the 65 // connection error handlers and they might access objects created by the
67 // client. 66 // client.
68 loop.reset(); 67 loop.reset();
(...skipping 13 matching lines...) Expand all
82 } 81 }
83 82
84 void ApplicationRunner::DestroyShellConnection() { 83 void ApplicationRunner::DestroyShellConnection() {
85 connection_.reset(); 84 connection_.reset();
86 } 85 }
87 86
88 void ApplicationRunner::Quit() { 87 void ApplicationRunner::Quit() {
89 base::MessageLoop::current()->QuitWhenIdle(); 88 base::MessageLoop::current()->QuitWhenIdle();
90 } 89 }
91 90
92 } // namespace mojo 91 } // namespace shell
OLDNEW
« no previous file with comments | « services/shell/public/cpp/interface_registry.h ('k') | services/shell/public/cpp/lib/application_test_base.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698