Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 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. | |
| 4 | |
| 5 #include "chrome/browser/devtools/devtools_network_controller.h" | |
| 6 | |
| 7 #include "chrome/browser/devtools/devtools_network_transaction.h" | |
| 8 #include "chrome/browser/profiles/profile.h" | |
| 9 #include "chrome/browser/profiles/profile_io_data.h" | |
| 10 #include "content/public/browser/browser_thread.h" | |
| 11 #include "content/public/browser/resource_context.h" | |
| 12 | |
| 13 namespace { | |
| 14 | |
| 15 const char kDevToolsRequestInitiator[] = "X-DevTools-Request-Initiator"; | |
| 16 | |
| 17 } // namespace | |
| 18 | |
| 19 DevToolsNetworkController::DevToolsNetworkController() { | |
| 20 } | |
| 21 | |
| 22 DevToolsNetworkController::~DevToolsNetworkController() { | |
| 23 } | |
| 24 | |
| 25 void DevToolsNetworkController::AddTransaction( | |
| 26 DevToolsNetworkTransaction* transaction) { | |
| 27 transactions_.insert(transaction); | |
|
pfeldman
2014/04/23 13:00:28
DCHECK every method on the IO thread please.
eustas
2014/04/29 08:14:42
Done. But I've used thread checker to avoid compex
| |
| 28 } | |
| 29 | |
| 30 void DevToolsNetworkController::RemoveTransaction( | |
| 31 DevToolsNetworkTransaction* transaction) { | |
| 32 DCHECK(transactions_.find(transaction) != transactions_.end()); | |
| 33 transactions_.erase(transaction); | |
| 34 } | |
| 35 | |
| 36 // static | |
| 37 void DevToolsNetworkController::DisableNetwork( | |
| 38 Profile* profile, | |
| 39 const std::string& client_id, | |
| 40 bool disable_network) { | |
| 41 DCHECK(profile); | |
| 42 content::ResourceContext* resource_context = profile->GetResourceContext(); | |
| 43 DCHECK(resource_context); | |
| 44 content::BrowserThread::PostTask( | |
| 45 content::BrowserThread::IO, | |
| 46 FROM_HERE, | |
| 47 base::Bind( | |
| 48 &DevToolsNetworkController::DisableNetworkOnIO, | |
| 49 resource_context, | |
| 50 client_id, | |
| 51 disable_network)); | |
| 52 } | |
| 53 | |
| 54 // static | |
| 55 void DevToolsNetworkController::DisableNetworkOnIO( | |
| 56 content::ResourceContext* resource_context, | |
| 57 const std::string& client_id, | |
| 58 bool disable_network) { | |
| 59 DCHECK(resource_context); | |
| 60 DevToolsNetworkController* controller = ProfileIOData::FromResourceContext( | |
| 61 resource_context)->network_controller(); | |
| 62 DCHECK(controller); | |
| 63 controller->DisableNetwork(client_id, disable_network); | |
| 64 } | |
| 65 | |
| 66 void DevToolsNetworkController::DisableNetwork( | |
| 67 const std::string& client_id, | |
| 68 bool disable_network) { | |
| 69 if (!disable_network) { | |
| 70 clients_.erase(client_id); | |
| 71 return; | |
| 72 } | |
| 73 clients_.insert(client_id); | |
| 74 | |
| 75 // Iterate over a copy of set, because failing of transaction could result in | |
| 76 // creating a new one, or (theoretically) destroying one. | |
| 77 Transactions old_transactions(transactions_); | |
| 78 for (Transactions::iterator it = old_transactions.begin(); | |
| 79 it != old_transactions.end(); ++it) { | |
| 80 if (transactions_.find(*it) == transactions_.end()) | |
| 81 continue; | |
| 82 if (!(*it)->request() || (*it)->failed()) | |
| 83 continue; | |
| 84 if (ShouldFail((*it)->request())) | |
| 85 (*it)->Fail(); | |
| 86 } | |
| 87 } | |
| 88 | |
| 89 bool DevToolsNetworkController::ShouldFail( | |
| 90 const net::HttpRequestInfo* request) { | |
| 91 DCHECK(request); | |
| 92 if (clients_.empty()) | |
| 93 return false; | |
| 94 | |
| 95 if (request->extra_headers.HasHeader(kDevToolsRequestInitiator)) | |
| 96 return false; | |
| 97 | |
| 98 // TODO: Add domain blacklist. | |
| 99 | |
| 100 return true; | |
| 101 } | |
| OLD | NEW |