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

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

Issue 2131493002: ShellConnection -> ServiceContext (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@st
Patch Set: . Created 4 years, 5 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
« no previous file with comments | « services/shell/public/cpp/connector.h ('k') | services/shell/public/cpp/lib/service_context.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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 "base/run_loop.h" 12 #include "base/run_loop.h"
13 #include "services/shell/public/cpp/service.h" 13 #include "services/shell/public/cpp/service.h"
14 #include "services/shell/public/cpp/shell_connection.h" 14 #include "services/shell/public/cpp/service_context.h"
15 15
16 namespace shell { 16 namespace shell {
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(Service* client) 21 ApplicationRunner::ApplicationRunner(Service* client)
22 : client_(std::unique_ptr<Service>(client)), 22 : client_(std::unique_ptr<Service>(client)),
23 message_loop_type_(base::MessageLoop::TYPE_DEFAULT), 23 message_loop_type_(base::MessageLoop::TYPE_DEFAULT),
24 has_run_(false) {} 24 has_run_(false) {}
(...skipping 19 matching lines...) Expand all
44 std::unique_ptr<base::AtExitManager> at_exit; 44 std::unique_ptr<base::AtExitManager> at_exit;
45 if (init_base) { 45 if (init_base) {
46 InitBaseCommandLine(); 46 InitBaseCommandLine();
47 at_exit.reset(new base::AtExitManager); 47 at_exit.reset(new base::AtExitManager);
48 } 48 }
49 49
50 { 50 {
51 std::unique_ptr<base::MessageLoop> loop; 51 std::unique_ptr<base::MessageLoop> loop;
52 loop.reset(new base::MessageLoop(message_loop_type_)); 52 loop.reset(new base::MessageLoop(message_loop_type_));
53 53
54 connection_.reset(new ShellConnection( 54 context_.reset(new ServiceContext(
55 client_.get(), 55 client_.get(),
56 mojo::MakeRequest<mojom::Service>(mojo::MakeScopedHandle( 56 mojo::MakeRequest<mojom::Service>(mojo::MakeScopedHandle(
57 mojo::MessagePipeHandle(service_request_handle))))); 57 mojo::MessagePipeHandle(service_request_handle)))));
58 base::RunLoop run_loop; 58 base::RunLoop run_loop;
59 connection_->SetConnectionLostClosure(run_loop.QuitClosure()); 59 context_->SetConnectionLostClosure(run_loop.QuitClosure());
60 run_loop.Run(); 60 run_loop.Run();
61 // 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.
62 // 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
63 // 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.
64 // 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
65 // connection error handlers and they might access objects created by the 65 // connection error handlers and they might access objects created by the
66 // client. 66 // client.
67 loop.reset(); 67 loop.reset();
68 client_.reset(); 68 client_.reset();
69 connection_.reset(); 69 context_.reset();
70 } 70 }
71 return MOJO_RESULT_OK; 71 return MOJO_RESULT_OK;
72 } 72 }
73 73
74 MojoResult ApplicationRunner::Run(MojoHandle service_request_handle) { 74 MojoResult ApplicationRunner::Run(MojoHandle service_request_handle) {
75 bool init_base = true; 75 bool init_base = true;
76 if (base::CommandLine::InitializedForCurrentProcess()) { 76 if (base::CommandLine::InitializedForCurrentProcess()) {
77 init_base = 77 init_base =
78 !base::CommandLine::ForCurrentProcess()->HasSwitch("single-process"); 78 !base::CommandLine::ForCurrentProcess()->HasSwitch("single-process");
79 } 79 }
80 return Run(service_request_handle, init_base); 80 return Run(service_request_handle, init_base);
81 } 81 }
82 82
83 void ApplicationRunner::DestroyShellConnection() { 83 void ApplicationRunner::DestroyServiceContext() {
84 connection_.reset(); 84 context_.reset();
85 } 85 }
86 86
87 void ApplicationRunner::Quit() { 87 void ApplicationRunner::Quit() {
88 base::MessageLoop::current()->QuitWhenIdle(); 88 base::MessageLoop::current()->QuitWhenIdle();
89 } 89 }
90 90
91 } // namespace shell 91 } // namespace shell
OLDNEW
« no previous file with comments | « services/shell/public/cpp/connector.h ('k') | services/shell/public/cpp/lib/service_context.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698