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

Side by Side Diff: components/ui_devtools/devtools_server.cc

Issue 2928603002: Create and remove |UiDevToolsServer::server_| in the same thread. (Closed)
Patch Set: . Created 3 years, 5 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 "components/ui_devtools/devtools_server.h" 5 #include "components/ui_devtools/devtools_server.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/format_macros.h" 10 #include "base/format_macros.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 return; 58 return;
59 // If io_thread_task_runner not passed in, create an I/O thread 59 // If io_thread_task_runner not passed in, create an I/O thread
60 thread_.reset(new base::Thread("UiDevToolsServerThread")); 60 thread_.reset(new base::Thread("UiDevToolsServerThread"));
61 base::Thread::Options options; 61 base::Thread::Options options;
62 options.message_loop_type = base::MessageLoop::TYPE_IO; 62 options.message_loop_type = base::MessageLoop::TYPE_IO;
63 CHECK(thread_->StartWithOptions(options)); 63 CHECK(thread_->StartWithOptions(options));
64 io_thread_task_runner_ = thread_->task_runner(); 64 io_thread_task_runner_ = thread_->task_runner();
65 } 65 }
66 66
67 UiDevToolsServer::~UiDevToolsServer() { 67 UiDevToolsServer::~UiDevToolsServer() {
68 if (io_thread_task_runner_)
69 io_thread_task_runner_->DeleteSoon(FROM_HERE, server_.release());
70 if (thread_ && thread_->IsRunning())
71 thread_->Stop();
68 devtools_server_ = nullptr; 72 devtools_server_ = nullptr;
69 } 73 }
70 74
71 // static 75 // static
72 std::unique_ptr<UiDevToolsServer> UiDevToolsServer::Create( 76 std::unique_ptr<UiDevToolsServer> UiDevToolsServer::Create(
73 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner) { 77 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner) {
74 std::unique_ptr<UiDevToolsServer> server; 78 std::unique_ptr<UiDevToolsServer> server;
75 if (IsUiDevToolsEnabled() && !devtools_server_) { 79 if (IsUiDevToolsEnabled() && !devtools_server_) {
76 // TODO(mhashmi): Change port if more than one inspectable clients 80 // TODO(mhashmi): Change port if more than one inspectable clients
77 server.reset(new UiDevToolsServer(io_thread_task_runner)); 81 server.reset(new UiDevToolsServer(io_thread_task_runner));
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 return; 179 return;
176 UiDevToolsClient* client = it->second; 180 UiDevToolsClient* client = it->second;
177 DCHECK(client); 181 DCHECK(client);
178 main_thread_task_runner_->PostTask( 182 main_thread_task_runner_->PostTask(
179 FROM_HERE, 183 FROM_HERE,
180 base::Bind(&UiDevToolsClient::Disconnect, base::Unretained(client))); 184 base::Bind(&UiDevToolsClient::Disconnect, base::Unretained(client)));
181 connections_.erase(it); 185 connections_.erase(it);
182 } 186 }
183 187
184 } // namespace ui_devtools 188 } // namespace ui_devtools
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