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 DevToolsNetworkController::DevToolsNetworkController() { | |
| 14 } | |
| 15 | |
| 16 DevToolsNetworkController::~DevToolsNetworkController() { | |
| 17 } | |
| 18 | |
| 19 void DevToolsNetworkController::AddTransaction( | |
| 20 DevToolsNetworkTransaction* transaction) { | |
| 21 transactions_.insert(transaction); | |
| 22 } | |
| 23 | |
| 24 void DevToolsNetworkController::RemoveTransaction( | |
| 25 DevToolsNetworkTransaction* transaction) { | |
| 26 DCHECK(transactions_.find(transaction) != transactions_.end()); | |
| 27 transactions_.erase(transaction); | |
| 28 } | |
| 29 | |
| 30 // static | |
| 31 void DevToolsNetworkController::DisableNetwork( | |
| 32 Profile* profile, | |
| 33 const std::string& client_id, | |
| 34 bool disable_network) { | |
| 35 DCHECK(profile); | |
| 36 content::ResourceContext* resource_context = profile->GetResourceContext(); | |
| 37 DCHECK(resource_context); | |
| 38 content::BrowserThread::PostTask( | |
| 39 content::BrowserThread::IO, | |
| 40 FROM_HERE, | |
| 41 base::Bind( | |
| 42 &DevToolsNetworkController::DisableNetworkOnIO, | |
| 43 resource_context, | |
| 44 client_id, | |
| 45 disable_network)); | |
| 46 } | |
| 47 | |
| 48 // static | |
| 49 void DevToolsNetworkController::DisableNetworkOnIO( | |
| 50 content::ResourceContext* resource_context, | |
| 51 const std::string& client_id, | |
| 52 bool disable_network) { | |
| 53 DCHECK(resource_context); | |
| 54 DevToolsNetworkController* controller = ProfileIOData::FromResourceContext( | |
| 55 resource_context)->network_controller(); | |
| 56 DCHECK(controller); | |
| 57 controller->DisableNetwork(client_id, disable_network); | |
| 58 } | |
| 59 | |
| 60 void DevToolsNetworkController::DisableNetwork( | |
| 61 const std::string& client_id, | |
| 62 bool disable_network) { | |
| 63 if (!disable_network) { | |
| 64 clients_.erase(client_id); | |
| 65 return; | |
| 66 } | |
| 67 clients_.insert(client_id); | |
| 68 | |
| 69 // Iterate over a copy of set, because failing of transaction could result in | |
| 70 // creating a new one, or (theoretically) destroying one. | |
| 71 std::vector<DevToolsNetworkTransaction*> transactions(transactions_.size()); | |
|
mmenke
2014/04/21 17:16:51
Suggest calling this old_transactions, for clarity
eustas
2014/04/22 14:23:09
Done.
| |
| 72 std::copy(transactions_.begin(), transactions_.end(), transactions.begin()); | |
|
mmenke
2014/04/21 17:16:51
Is there a reason you're not just using:
std::set
eustas
2014/04/22 14:23:09
No reason, just old java habits =)
Done.
| |
| 73 std::vector<DevToolsNetworkTransaction*>::iterator it = transactions.begin(); | |
| 74 while (it != transactions.end()) { | |
| 75 DevToolsNetworkTransaction* transaction = *it++; | |
|
mmenke
2014/04/21 17:16:51
No need for the extra complexity now - Can just ma
eustas
2014/04/22 14:23:09
Done.
| |
| 76 if (transactions_.find(transaction) == transactions_.end()) | |
| 77 continue; | |
| 78 if (!transaction->started() || transaction->failed()) | |
| 79 continue; | |
| 80 if (ShouldFail(transaction)) | |
| 81 transaction->Fail(); | |
| 82 } | |
| 83 } | |
| 84 | |
| 85 bool DevToolsNetworkController::ShouldFail( | |
| 86 const DevToolsNetworkTransaction* transaction) { | |
| 87 DCHECK(transaction); | |
| 88 if (clients_.empty()) | |
| 89 return false; | |
| 90 | |
| 91 if (transaction->has_devtools_request_header()) | |
| 92 return false; | |
| 93 | |
| 94 // TODO: Add domain blacklist. | |
| 95 | |
| 96 return true; | |
| 97 } | |
| OLD | NEW |