Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / devtools / devtools_network_controller_handle.cc
blob0cd13494a7785c5e9320e2eeef5f1b68f4063d9f
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/devtools/devtools_network_controller_handle.h"
7 #include "base/bind.h"
8 #include "chrome/browser/devtools/devtools_network_conditions.h"
9 #include "chrome/browser/devtools/devtools_network_controller.h"
10 #include "content/public/browser/browser_thread.h"
12 using content::BrowserThread;
14 DevToolsNetworkControllerHandle::DevToolsNetworkControllerHandle() {
15 DCHECK_CURRENTLY_ON(BrowserThread::UI);
18 DevToolsNetworkControllerHandle::~DevToolsNetworkControllerHandle() {}
20 void DevToolsNetworkControllerHandle::SetNetworkState(
21 const std::string& client_id,
22 scoped_ptr<DevToolsNetworkConditions> conditions) {
23 DCHECK_CURRENTLY_ON(BrowserThread::UI);
25 BrowserThread::PostTask(
26 BrowserThread::IO, FROM_HERE,
27 base::Bind(&DevToolsNetworkControllerHandle::SetNetworkStateOnIO,
28 base::Unretained(this), client_id, base::Passed(&conditions)));
31 DevToolsNetworkController* DevToolsNetworkControllerHandle::GetController() {
32 DCHECK_CURRENTLY_ON(BrowserThread::IO);
34 LazyInitialize();
35 return controller_.get();
38 void DevToolsNetworkControllerHandle::LazyInitialize() {
39 DCHECK_CURRENTLY_ON(BrowserThread::IO);
41 if (!controller_)
42 controller_.reset(new DevToolsNetworkController);
45 void DevToolsNetworkControllerHandle::SetNetworkStateOnIO(
46 const std::string& client_id,
47 scoped_ptr<DevToolsNetworkConditions> conditions) {
48 DCHECK_CURRENTLY_ON(BrowserThread::IO);
50 LazyInitialize();
51 controller_->SetNetworkState(client_id, conditions.Pass());