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

Side by Side Diff: shell/in_process_dynamic_service_runner.cc

Issue 865253002: Delete temporary application file as soon as the application is launched. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Follow review Created 5 years, 11 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 "shell/in_process_dynamic_service_runner.h" 5 #include "shell/in_process_dynamic_service_runner.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback_helpers.h" 8 #include "base/callback_helpers.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/message_loop/message_loop_proxy.h" 10 #include "base/message_loop/message_loop_proxy.h"
11 #include "base/threading/platform_thread.h" 11 #include "base/threading/platform_thread.h"
12 12
13 namespace mojo { 13 namespace mojo {
14 namespace shell { 14 namespace shell {
15 15
16 InProcessDynamicServiceRunner::InProcessDynamicServiceRunner(Context* context) 16 InProcessDynamicServiceRunner::InProcessDynamicServiceRunner(Context* context)
17 : app_library_(nullptr) { 17 : cleanup_behavior_(DynamicServiceRunner::DontDeleteAppPath),
18 app_library_(nullptr) {
18 } 19 }
19 20
20 InProcessDynamicServiceRunner::~InProcessDynamicServiceRunner() { 21 InProcessDynamicServiceRunner::~InProcessDynamicServiceRunner() {
21 // It is important to let the thread exit before unloading the DSO (when 22 // It is important to let the thread exit before unloading the DSO (when
22 // app_library_ is destructed), because the library may have registered 23 // app_library_ is destructed), because the library may have registered
23 // thread-local data and destructors to run on thread termination. 24 // thread-local data and destructors to run on thread termination.
24 if (thread_) { 25 if (thread_) {
25 DCHECK(thread_->HasBeenStarted()); 26 DCHECK(thread_->HasBeenStarted());
26 DCHECK(!thread_->HasBeenJoined()); 27 DCHECK(!thread_->HasBeenJoined());
27 thread_->Join(); 28 thread_->Join();
28 } 29 }
29 } 30 }
30 31
31 void InProcessDynamicServiceRunner::Start( 32 void InProcessDynamicServiceRunner::Start(
32 const base::FilePath& app_path, 33 const base::FilePath& app_path,
34 DynamicServiceRunner::CleanupBehavior cleanup_behavior,
33 ScopedMessagePipeHandle service_handle, 35 ScopedMessagePipeHandle service_handle,
34 const base::Closure& app_completed_callback) { 36 const base::Closure& app_completed_callback) {
35 app_path_ = app_path; 37 app_path_ = app_path;
38 cleanup_behavior_ = cleanup_behavior;
36 39
37 DCHECK(!service_handle_.is_valid()); 40 DCHECK(!service_handle_.is_valid());
38 service_handle_ = service_handle.Pass(); 41 service_handle_ = service_handle.Pass();
39 42
40 DCHECK(app_completed_callback_runner_.is_null()); 43 DCHECK(app_completed_callback_runner_.is_null());
41 app_completed_callback_runner_ = 44 app_completed_callback_runner_ =
42 base::Bind(&base::TaskRunner::PostTask, base::MessageLoopProxy::current(), 45 base::Bind(&base::TaskRunner::PostTask, base::MessageLoopProxy::current(),
43 FROM_HERE, app_completed_callback); 46 FROM_HERE, app_completed_callback);
44 47
45 DCHECK(!thread_); 48 DCHECK(!thread_);
46 thread_.reset(new base::DelegateSimpleThread(this, "app_thread")); 49 thread_.reset(new base::DelegateSimpleThread(this, "app_thread"));
47 thread_->Start(); 50 thread_->Start();
48 } 51 }
49 52
50 void InProcessDynamicServiceRunner::Run() { 53 void InProcessDynamicServiceRunner::Run() {
51 DVLOG(2) << "Loading/running Mojo app in process from library: " 54 DVLOG(2) << "Loading/running Mojo app in process from library: "
52 << app_path_.value() 55 << app_path_.value()
53 << " thread id=" << base::PlatformThread::CurrentId(); 56 << " thread id=" << base::PlatformThread::CurrentId();
54 57
55 app_library_.Reset(LoadAndRunService(app_path_, service_handle_.Pass())); 58 app_library_.Reset(
59 LoadAndRunService(app_path_, cleanup_behavior_, service_handle_.Pass()));
56 app_completed_callback_runner_.Run(); 60 app_completed_callback_runner_.Run();
57 app_completed_callback_runner_.Reset(); 61 app_completed_callback_runner_.Reset();
58 } 62 }
59 63
60 } // namespace shell 64 } // namespace shell
61 } // namespace mojo 65 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698