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

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

Issue 1517743003: Make ApplicationRunner's ctor's ApplicationDelegate* argument an std::unique_ptr instead. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years 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/public/cpp/application/application_runner.h" 5 #include "mojo/public/cpp/application/application_runner.h"
6 6
7 #include "mojo/public/cpp/application/application_delegate.h" 7 #include "mojo/public/cpp/application/application_delegate.h"
8 #include "mojo/public/cpp/application/application_impl.h" 8 #include "mojo/public/cpp/application/application_impl.h"
9 #include "mojo/public/cpp/environment/environment.h" 9 #include "mojo/public/cpp/environment/environment.h"
10 #include "mojo/public/cpp/environment/logging.h" 10 #include "mojo/public/cpp/environment/logging.h"
11 #include "mojo/public/cpp/utility/run_loop.h" 11 #include "mojo/public/cpp/utility/run_loop.h"
12 12
13 namespace mojo { 13 namespace mojo {
14 namespace { 14 namespace {
15 bool g_running = false; 15 bool g_running = false;
16 } // namespace 16 } // namespace
17 17
18 // static 18 // static
19 void ApplicationImpl::Terminate() { 19 void ApplicationImpl::Terminate() {
20 RunLoop::current()->Quit(); 20 RunLoop::current()->Quit();
21 } 21 }
22 22
23 ApplicationRunner::ApplicationRunner(ApplicationDelegate* delegate) 23 ApplicationRunner::ApplicationRunner(
24 : delegate_(delegate) {} 24 std::unique_ptr<ApplicationDelegate> delegate)
25 : delegate_(std::move(delegate)) {}
25 26
26 ApplicationRunner::~ApplicationRunner() { 27 ApplicationRunner::~ApplicationRunner() {
27 assert(!delegate_); 28 assert(!delegate_);
28 } 29 }
29 30
30 // static 31 // static
31 void ApplicationRunner::SetDefaultLogger(const MojoLogger* logger) { 32 void ApplicationRunner::SetDefaultLogger(const MojoLogger* logger) {
32 MOJO_DCHECK(g_running); 33 MOJO_DCHECK(g_running);
33 Environment::SetDefaultLogger(logger); 34 Environment::SetDefaultLogger(logger);
34 } 35 }
35 36
36 // static 37 // static
37 const MojoLogger* ApplicationRunner::GetDefaultLogger() { 38 const MojoLogger* ApplicationRunner::GetDefaultLogger() {
38 MOJO_DCHECK(g_running); 39 MOJO_DCHECK(g_running);
39 return Environment::GetDefaultLogger(); 40 return Environment::GetDefaultLogger();
40 } 41 }
41 42
42 MojoResult ApplicationRunner::Run(MojoHandle app_request_handle) { 43 MojoResult ApplicationRunner::Run(MojoHandle app_request_handle) {
43 MOJO_DCHECK(!g_running) 44 MOJO_DCHECK(!g_running)
44 << "Another ApplicationRunner::Run() is already running!"; 45 << "Another ApplicationRunner::Run() is already running!";
45 46
46 g_running = true; 47 g_running = true;
47 Environment env; 48 Environment env;
48 { 49 {
49 RunLoop loop; 50 RunLoop loop;
50 ApplicationImpl app(delegate_, MakeRequest<Application>(MakeScopedHandle( 51 ApplicationImpl app(delegate_.get(),
51 MessagePipeHandle(app_request_handle)))); 52 MakeRequest<Application>(MakeScopedHandle(
53 MessagePipeHandle(app_request_handle))));
52 loop.Run(); 54 loop.Run();
53 } 55 }
54 56
55 delete delegate_; 57 delegate_.reset();
56 delegate_ = nullptr;
57 58
58 g_running = false; 59 g_running = false;
59 60
60 return MOJO_RESULT_OK; 61 return MOJO_RESULT_OK;
61 } 62 }
62 63
63 } // namespace mojo 64 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/application/application_runner.h ('k') | mojo/public/cpp/bindings/tests/versioning_test_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698