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

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

Issue 1266643003: ApplicationImpl cleanup, part 1: (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 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/application/public/cpp/application_runner.h" 5 #include "mojo/application/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/debug/stack_trace.h" 9 #include "base/debug/stack_trace.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 53
54 { 54 {
55 scoped_ptr<base::MessageLoop> loop; 55 scoped_ptr<base::MessageLoop> loop;
56 if (message_loop_type_ == base::MessageLoop::TYPE_CUSTOM) 56 if (message_loop_type_ == base::MessageLoop::TYPE_CUSTOM)
57 loop.reset(new base::MessageLoop(common::MessagePumpMojo::Create())); 57 loop.reset(new base::MessageLoop(common::MessagePumpMojo::Create()));
58 else 58 else
59 loop.reset(new base::MessageLoop(message_loop_type_)); 59 loop.reset(new base::MessageLoop(message_loop_type_));
60 60
61 ApplicationImpl impl(delegate_.get(), 61 ApplicationImpl impl(delegate_.get(),
62 MakeRequest<Application>(MakeScopedHandle( 62 MakeRequest<Application>(MakeScopedHandle(
63 MessagePipeHandle(application_request_handle)))); 63 MessagePipeHandle(application_request_handle))),
64 base::MessageLoop::QuitWhenIdleClosure());
64 loop->Run(); 65 loop->Run();
65 // It's very common for the delegate to cache the app and terminate on 66 // It's very common for the delegate to cache the app and terminate on
66 // errors. If we don't delete the delegate before the app we run the risk 67 // errors. If we don't delete the delegate before the app we run the risk
67 // of the delegate having a stale reference to the app and trying to use it. 68 // of the delegate having a stale reference to the app and trying to use it.
68 // Note that we destruct the message loop first because that might trigger 69 // Note that we destruct the message loop first because that might trigger
69 // connection error handlers and they might access objects created by the 70 // connection error handlers and they might access objects created by the
70 // delegate. 71 // delegate.
71 loop.reset(); 72 loop.reset();
72 delegate_.reset(); 73 delegate_.reset();
73 } 74 }
74 75
75 // By default the worker pool continues running until all tasks are done or 76 // By default the worker pool continues running until all tasks are done or
76 // the process is shut down. However, because the application could be 77 // the process is shut down. However, because the application could be
77 // unloaded before process shutdown, we have to wait for the worker pool to 78 // unloaded before process shutdown, we have to wait for the worker pool to
78 // shut down cleanly. 79 // shut down cleanly.
79 base::WorkerPool::ShutDownCleanly(); 80 base::WorkerPool::ShutDownCleanly();
80 81
81 return MOJO_RESULT_OK; 82 return MOJO_RESULT_OK;
82 } 83 }
83 84
84 MojoResult ApplicationRunner::Run(MojoHandle application_request_handle) { 85 MojoResult ApplicationRunner::Run(MojoHandle application_request_handle) {
85 return Run(application_request_handle, true); 86 return Run(application_request_handle, true);
86 } 87 }
87 88
88 } // namespace mojo 89 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698