Fix race initialising DevtoolsNetworkController

This commit is contained in:
deepak1556 2016-04-14 06:59:14 +05:30
parent 2f107fcbe1
commit de60acbfde
10 changed files with 130 additions and 35 deletions

View file

@ -0,0 +1,60 @@
// Copyright (c) 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE-CHROMIUM file.
#include "browser/net/devtools_network_controller_handle.h"
#include "base/bind.h"
#include "browser/net/devtools_network_conditions.h"
#include "browser/net/devtools_network_controller.h"
#include "content/public/browser/browser_thread.h"
using content::BrowserThread;
namespace brightray {
DevToolsNetworkControllerHandle::DevToolsNetworkControllerHandle() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
}
DevToolsNetworkControllerHandle::~DevToolsNetworkControllerHandle() {
BrowserThread::DeleteSoon(BrowserThread::IO,
FROM_HERE,
controller_.release());
}
void DevToolsNetworkControllerHandle::SetNetworkState(
const std::string& client_id,
scoped_ptr<DevToolsNetworkConditions> conditions) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::Bind(&DevToolsNetworkControllerHandle::SetNetworkStateOnIO,
base::Unretained(this), client_id, base::Passed(&conditions)));
}
DevToolsNetworkController* DevToolsNetworkControllerHandle::GetController() {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
LazyInitialize();
return controller_.get();
}
void DevToolsNetworkControllerHandle::LazyInitialize() {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
if (!controller_)
controller_.reset(new DevToolsNetworkController);
}
void DevToolsNetworkControllerHandle::SetNetworkStateOnIO(
const std::string& client_id,
scoped_ptr<DevToolsNetworkConditions> conditions) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
LazyInitialize();
controller_->SetNetworkState(client_id, std::move(conditions));
}
} // namespace brightray