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

Side by Side Diff: content/common/mojo/embedded_application_runner.cc

Issue 2007383002: Fix invalid DCHECK in EmbeddedApplicationRunner (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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 | « no previous file | 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/common/mojo/embedded_application_runner.h" 5 #include "content/common/mojo/embedded_application_runner.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 12 matching lines...) Expand all
23 Instance(const base::StringPiece& name, 23 Instance(const base::StringPiece& name,
24 const MojoApplicationInfo& info, 24 const MojoApplicationInfo& info,
25 const base::Closure& quit_closure) 25 const base::Closure& quit_closure)
26 : name_(name.as_string()), 26 : name_(name.as_string()),
27 factory_callback_(info.application_factory), 27 factory_callback_(info.application_factory),
28 use_own_thread_(!info.application_task_runner && info.use_own_thread), 28 use_own_thread_(!info.application_task_runner && info.use_own_thread),
29 quit_closure_(quit_closure), 29 quit_closure_(quit_closure),
30 quit_task_runner_(base::ThreadTaskRunnerHandle::Get()), 30 quit_task_runner_(base::ThreadTaskRunnerHandle::Get()),
31 application_task_runner_(info.application_task_runner) { 31 application_task_runner_(info.application_task_runner) {
32 application_thread_checker_.DetachFromThread(); 32 application_thread_checker_.DetachFromThread();
33
34 if (!use_own_thread_ && !application_task_runner_) 33 if (!use_own_thread_ && !application_task_runner_)
35 application_task_runner_ = base::ThreadTaskRunnerHandle::Get(); 34 application_task_runner_ = base::ThreadTaskRunnerHandle::Get();
36 } 35 }
37 36
38 void BindShellClientRequest(shell::mojom::ShellClientRequest request) { 37 void BindShellClientRequest(shell::mojom::ShellClientRequest request) {
39 DCHECK(runner_thread_checker_.CalledOnValidThread()); 38 DCHECK(runner_thread_checker_.CalledOnValidThread());
40 39
41 if (use_own_thread_ && !thread_) { 40 if (use_own_thread_ && !thread_) {
42 // Start a new thread if necessary. 41 // Start a new thread if necessary.
43 thread_.reset(new base::Thread(name_)); 42 thread_.reset(new base::Thread(name_));
44 thread_->Start(); 43 thread_->Start();
45 application_task_runner_ = thread_->task_runner(); 44 application_task_runner_ = thread_->task_runner();
45 application_thread_checker_.DetachFromThread();
46 } 46 }
47 47
48 DCHECK(application_task_runner_); 48 DCHECK(application_task_runner_);
49 application_task_runner_->PostTask( 49 application_task_runner_->PostTask(
50 FROM_HERE, 50 FROM_HERE,
51 base::Bind(&Instance::BindShellClientRequestOnApplicationThread, this, 51 base::Bind(&Instance::BindShellClientRequestOnApplicationThread, this,
52 base::Passed(&request))); 52 base::Passed(&request)));
53 } 53 }
54 54
55 void ShutDown() { 55 void ShutDown() {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 const bool use_own_thread_; 119 const bool use_own_thread_;
120 const base::Closure quit_closure_; 120 const base::Closure quit_closure_;
121 const scoped_refptr<base::SingleThreadTaskRunner> quit_task_runner_; 121 const scoped_refptr<base::SingleThreadTaskRunner> quit_task_runner_;
122 122
123 // Thread checker used to ensure certain operations happen only on the 123 // Thread checker used to ensure certain operations happen only on the
124 // runner's (i.e. our owner's) thread. 124 // runner's (i.e. our owner's) thread.
125 base::ThreadChecker runner_thread_checker_; 125 base::ThreadChecker runner_thread_checker_;
126 126
127 // Thread checker used to ensure certain operations happen only on the 127 // Thread checker used to ensure certain operations happen only on the
128 // application task runner's thread. 128 // application task runner's thread.
129 base::ThreadChecker application_thread_checker_; 129 base::ThreadChecker application_thread_checker_;
xhwang 2016/05/25 17:30:27 Does it make sense to just use application_task_
130 130
131 // These fields must only be accessed from the runner's thread. 131 // These fields must only be accessed from the runner's thread.
132 std::unique_ptr<base::Thread> thread_; 132 std::unique_ptr<base::Thread> thread_;
133 scoped_refptr<base::SingleThreadTaskRunner> application_task_runner_; 133 scoped_refptr<base::SingleThreadTaskRunner> application_task_runner_;
134 134
135 // These fields must only be accessed from the application thread, except in 135 // These fields must only be accessed from the application thread, except in
136 // the destructor which may run on either the runner thread or the application 136 // the destructor which may run on either the runner thread or the application
137 // thread. 137 // thread.
138 std::unique_ptr<shell::ShellClient> shell_client_; 138 std::unique_ptr<shell::ShellClient> shell_client_;
139 std::vector<std::unique_ptr<shell::ShellConnection>> shell_connections_; 139 std::vector<std::unique_ptr<shell::ShellConnection>> shell_connections_;
(...skipping 23 matching lines...) Expand all
163 const base::Closure& quit_closure) { 163 const base::Closure& quit_closure) {
164 quit_closure_ = quit_closure; 164 quit_closure_ = quit_closure;
165 } 165 }
166 166
167 void EmbeddedApplicationRunner::OnQuit() { 167 void EmbeddedApplicationRunner::OnQuit() {
168 if (!quit_closure_.is_null()) 168 if (!quit_closure_.is_null())
169 quit_closure_.Run(); 169 quit_closure_.Run();
170 } 170 }
171 171
172 } // namespace content 172 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698