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

Side by Side Diff: content/browser/child_process_launcher.cc

Issue 2910083002: Replace deprecated base::NonThreadSafe in content/browser in favor of SequenceChecker. (Closed)
Patch Set: Created 3 years, 6 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 | « content/browser/child_process_launcher.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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 "content/browser/child_process_launcher.h" 5 #include "content/browser/child_process_launcher.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/i18n/icu_util.h" 10 #include "base/i18n/icu_util.h"
(...skipping 23 matching lines...) Expand all
34 broker_client_invitation_(std::move(broker_client_invitation)), 34 broker_client_invitation_(std::move(broker_client_invitation)),
35 process_error_callback_(process_error_callback), 35 process_error_callback_(process_error_callback),
36 #if defined(ADDRESS_SANITIZER) || defined(LEAK_SANITIZER) || \ 36 #if defined(ADDRESS_SANITIZER) || defined(LEAK_SANITIZER) || \
37 defined(MEMORY_SANITIZER) || defined(THREAD_SANITIZER) || \ 37 defined(MEMORY_SANITIZER) || defined(THREAD_SANITIZER) || \
38 defined(UNDEFINED_SANITIZER) 38 defined(UNDEFINED_SANITIZER)
39 terminate_child_on_shutdown_(false), 39 terminate_child_on_shutdown_(false),
40 #else 40 #else
41 terminate_child_on_shutdown_(terminate_on_shutdown), 41 terminate_child_on_shutdown_(terminate_on_shutdown),
42 #endif 42 #endif
43 weak_factory_(this) { 43 weak_factory_(this) {
44 DCHECK(CalledOnValidThread()); 44 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
45 CHECK(BrowserThread::GetCurrentThreadIdentifier(&client_thread_id_)); 45 CHECK(BrowserThread::GetCurrentThreadIdentifier(&client_thread_id_));
46 46
47 helper_ = new ChildProcessLauncherHelper( 47 helper_ = new ChildProcessLauncherHelper(
48 child_process_id, client_thread_id_, 48 child_process_id, client_thread_id_,
49 std::move(command_line), std::move(delegate), 49 std::move(command_line), std::move(delegate),
50 weak_factory_.GetWeakPtr(), terminate_on_shutdown); 50 weak_factory_.GetWeakPtr(), terminate_on_shutdown);
51 helper_->StartLaunchOnClientThread(); 51 helper_->StartLaunchOnClientThread();
52 } 52 }
53 53
54 ChildProcessLauncher::~ChildProcessLauncher() { 54 ChildProcessLauncher::~ChildProcessLauncher() {
55 DCHECK(CalledOnValidThread()); 55 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
56 if (process_.process.IsValid() && terminate_child_on_shutdown_) { 56 if (process_.process.IsValid() && terminate_child_on_shutdown_) {
57 // Client has gone away, so just kill the process. 57 // Client has gone away, so just kill the process.
58 ChildProcessLauncherHelper::ForceNormalProcessTerminationAsync( 58 ChildProcessLauncherHelper::ForceNormalProcessTerminationAsync(
59 std::move(process_)); 59 std::move(process_));
60 } 60 }
61 } 61 }
62 62
63 void ChildProcessLauncher::SetProcessPriority(bool background, 63 void ChildProcessLauncher::SetProcessPriority(bool background,
64 bool boost_for_pending_views) { 64 bool boost_for_pending_views) {
65 DCHECK(CalledOnValidThread()); 65 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
66 base::Process to_pass = process_.process.Duplicate(); 66 base::Process to_pass = process_.process.Duplicate();
67 BrowserThread::PostTask( 67 BrowserThread::PostTask(
68 BrowserThread::PROCESS_LAUNCHER, FROM_HERE, 68 BrowserThread::PROCESS_LAUNCHER, FROM_HERE,
69 base::Bind( 69 base::Bind(
70 &ChildProcessLauncherHelper::SetProcessPriorityOnLauncherThread, 70 &ChildProcessLauncherHelper::SetProcessPriorityOnLauncherThread,
71 helper_, base::Passed(&to_pass), background, 71 helper_, base::Passed(&to_pass), background,
72 boost_for_pending_views)); 72 boost_for_pending_views));
73 } 73 }
74 74
75 void ChildProcessLauncher::Notify( 75 void ChildProcessLauncher::Notify(
76 ChildProcessLauncherHelper::Process process, 76 ChildProcessLauncherHelper::Process process,
77 mojo::edk::ScopedPlatformHandle server_handle, 77 mojo::edk::ScopedPlatformHandle server_handle,
78 int error_code) { 78 int error_code) {
79 DCHECK(CalledOnValidThread()); 79 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
80 starting_ = false; 80 starting_ = false;
81 process_ = std::move(process); 81 process_ = std::move(process);
82 82
83 // Take ownership of the broker client invitation here so it's destroyed when 83 // Take ownership of the broker client invitation here so it's destroyed when
84 // we go out of scope regardless of the outcome below. 84 // we go out of scope regardless of the outcome below.
85 std::unique_ptr<mojo::edk::OutgoingBrokerClientInvitation> invitation = 85 std::unique_ptr<mojo::edk::OutgoingBrokerClientInvitation> invitation =
86 std::move(broker_client_invitation_); 86 std::move(broker_client_invitation_);
87 if (process_.process.IsValid()) { 87 if (process_.process.IsValid()) {
88 // Set up Mojo IPC to the new process. 88 // Set up Mojo IPC to the new process.
89 DCHECK(invitation); 89 DCHECK(invitation);
90 invitation->Send( 90 invitation->Send(
91 process_.process.Handle(), 91 process_.process.Handle(),
92 mojo::edk::ConnectionParams(mojo::edk::TransportProtocol::kLegacy, 92 mojo::edk::ConnectionParams(mojo::edk::TransportProtocol::kLegacy,
93 std::move(server_handle)), 93 std::move(server_handle)),
94 process_error_callback_); 94 process_error_callback_);
95 client_->OnProcessLaunched(); 95 client_->OnProcessLaunched();
96 } else { 96 } else {
97 termination_status_ = base::TERMINATION_STATUS_LAUNCH_FAILED; 97 termination_status_ = base::TERMINATION_STATUS_LAUNCH_FAILED;
98 98
99 // NOTE: May delete |this|. 99 // NOTE: May delete |this|.
100 client_->OnProcessLaunchFailed(error_code); 100 client_->OnProcessLaunchFailed(error_code);
101 } 101 }
102 } 102 }
103 103
104 bool ChildProcessLauncher::IsStarting() { 104 bool ChildProcessLauncher::IsStarting() {
105 // TODO(crbug.com/469248): This fails in some tests. 105 // TODO(crbug.com/469248): This fails in some tests.
106 // DCHECK(CalledOnValidThread()); 106 // DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
107 return starting_; 107 return starting_;
108 } 108 }
109 109
110 const base::Process& ChildProcessLauncher::GetProcess() const { 110 const base::Process& ChildProcessLauncher::GetProcess() const {
111 // TODO(crbug.com/469248): This fails in some tests. 111 // TODO(crbug.com/469248): This fails in some tests.
112 // DCHECK(CalledOnValidThread()); 112 // DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
113 return process_.process; 113 return process_.process;
114 } 114 }
115 115
116 base::TerminationStatus ChildProcessLauncher::GetChildTerminationStatus( 116 base::TerminationStatus ChildProcessLauncher::GetChildTerminationStatus(
117 bool known_dead, 117 bool known_dead,
118 int* exit_code) { 118 int* exit_code) {
119 DCHECK(CalledOnValidThread()); 119 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
120 if (!process_.process.IsValid()) { 120 if (!process_.process.IsValid()) {
121 // Process is already gone, so return the cached termination status. 121 // Process is already gone, so return the cached termination status.
122 if (exit_code) 122 if (exit_code)
123 *exit_code = exit_code_; 123 *exit_code = exit_code_;
124 return termination_status_; 124 return termination_status_;
125 } 125 }
126 126
127 termination_status_ = 127 termination_status_ =
128 helper_->GetTerminationStatus(process_, known_dead, &exit_code_); 128 helper_->GetTerminationStatus(process_, known_dead, &exit_code_);
129 if (exit_code) 129 if (exit_code)
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 #endif // OS_ANDROID 175 #endif // OS_ANDROID
176 176
177 ChildProcessLauncher::Client* ChildProcessLauncher::ReplaceClientForTest( 177 ChildProcessLauncher::Client* ChildProcessLauncher::ReplaceClientForTest(
178 Client* client) { 178 Client* client) {
179 Client* ret = client_; 179 Client* ret = client_;
180 client_ = client; 180 client_ = client;
181 return ret; 181 return ret;
182 } 182 }
183 183
184 } // namespace content 184 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/child_process_launcher.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698