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

Side by Side Diff: tools/android/forwarder2/device_forwarder_main.cc

Issue 1571643003: Fix crash in device_forwarder (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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
« 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 <signal.h> 5 #include <signal.h>
6 #include <stdlib.h> 6 #include <stdlib.h>
7 7
8 #include <iostream> 8 #include <iostream>
9 #include <string> 9 #include <string>
10 10
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 } 45 }
46 46
47 class ServerDelegate : public Daemon::ServerDelegate { 47 class ServerDelegate : public Daemon::ServerDelegate {
48 public: 48 public:
49 ServerDelegate() : initialized_(false) {} 49 ServerDelegate() : initialized_(false) {}
50 50
51 ~ServerDelegate() override { 51 ~ServerDelegate() override {
52 if (!controller_thread_.get()) 52 if (!controller_thread_.get())
53 return; 53 return;
54 // The DeviceController instance, if any, is constructed on the controller 54 // The DeviceController instance, if any, is constructed on the controller
55 // thread. Make sure that it gets deleted on that same thread. Note that 55 // thread. Make sure that it gets deleted on that same thread.
56 // DeleteSoon() is not used here since it would imply reading |controller_| 56 controller_thread_->task_runner()->DeleteSoon(
jbudorick 2016/01/08 21:41:08 I hadn't reviewed yet because I'd like to look int
Xianzhu 2016/01/08 21:47:03 I don't think the previous comment is correct. The
jbudorick 2016/01/08 22:11:37 It looks like the original would avoid that risk b
57 // from the main thread while it's set on the internal thread. 57 FROM_HERE, controller_.release());
58 controller_thread_->task_runner()->PostTask(
59 FROM_HERE,
60 base::Bind(&ServerDelegate::DeleteControllerOnInternalThread,
61 base::Unretained(this)));
62 }
63
64 void DeleteControllerOnInternalThread() {
65 DCHECK(
66 controller_thread_->task_runner()->RunsTasksOnCurrentThread());
67 controller_.reset();
68 } 58 }
69 59
70 // Daemon::ServerDelegate: 60 // Daemon::ServerDelegate:
71 void Init() override { 61 void Init() override {
72 DCHECK(!g_notifier); 62 DCHECK(!g_notifier);
73 g_notifier = new forwarder2::PipeNotifier(); 63 g_notifier = new forwarder2::PipeNotifier();
74 signal(SIGTERM, KillHandler); 64 signal(SIGTERM, KillHandler);
75 signal(SIGINT, KillHandler); 65 signal(SIGINT, KillHandler);
76 controller_thread_.reset(new base::Thread("controller_thread")); 66 controller_thread_.reset(new base::Thread("controller_thread"));
77 controller_thread_->Start(); 67 controller_thread_->Start();
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 return 1; 150 return 1;
161 return client_delegate.has_failed(); 151 return client_delegate.has_failed();
162 } 152 }
163 153
164 } // namespace 154 } // namespace
165 } // namespace forwarder2 155 } // namespace forwarder2
166 156
167 int main(int argc, char** argv) { 157 int main(int argc, char** argv) {
168 return forwarder2::RunDeviceForwarder(argc, argv); 158 return forwarder2::RunDeviceForwarder(argc, argv);
169 } 159 }
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