Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 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 "net/base/request_priority.h" | |
| 12 #include "net/http/http_network_layer.h" | |
| 13 #include "net/http/http_network_session.h" | |
| 14 #include "net/http/http_network_transaction.h" | |
| 15 | |
| 16 DevToolsNetworkController::DevToolsNetworkController( | |
| 17 net::HttpNetworkSession* session) | |
| 18 : network_layer_(new net::HttpNetworkLayer(session)) | |
| 19 , weak_factory_(this) { | |
|
mmenke
2014/03/11 21:16:53
nit: Comma goes on previous line
eustas
2014/03/12 15:38:33
Done.
| |
| 20 } | |
| 21 | |
| 22 DevToolsNetworkController::~DevToolsNetworkController() { | |
| 23 } | |
| 24 | |
| 25 void DevToolsNetworkController::SetBlockedDomains( | |
|
mmenke
2014/03/11 21:16:53
nit: "// static"
eustas
2014/03/12 15:38:33
Done.
| |
| 26 Profile* profile, | |
| 27 const std::string& id, | |
| 28 const std::vector<std::string>& blocked_domains) { | |
| 29 CHECK(profile); | |
| 30 DevToolsNetworkController* controller = ProfileIOData::FromResourceContext( | |
| 31 profile->GetResourceContext())->devtools_network_controller(); | |
|
mmenke
2014/03/11 21:16:53
We really shouldn't be dereferencing IO thread obj
eustas
2014/03/12 15:38:33
Done.
| |
| 32 CHECK(controller); | |
| 33 content::BrowserThread::PostTask( | |
| 34 content::BrowserThread::IO, | |
| 35 FROM_HERE, | |
| 36 base::Bind( | |
| 37 &DevToolsNetworkController::SetBlockedDomainsOnIO, | |
| 38 base::Unretained(controller), | |
| 39 id, | |
| 40 blocked_domains)); | |
| 41 } | |
| 42 | |
| 43 void DevToolsNetworkController::RemoveTransaction(const std::string& id) { | |
|
mmenke
2014/03/11 21:16:53
I think using "id" for both transactions and block
eustas
2014/03/12 15:38:33
Done.
| |
| 44 transactions_.erase(id); | |
| 45 } | |
| 46 | |
| 47 void DevToolsNetworkController::SetBlockedDomainsOnIO( | |
| 48 const std::string& id, | |
| 49 const std::vector<std::string>& blocked_domains) { | |
| 50 BlockedDomains* items = NULL; | |
| 51 BlockedDomainsMap::iterator client = blocked_domains_map_.find(id); | |
| 52 if (client != blocked_domains_map_.end()) | |
| 53 items = client->second; | |
| 54 size_t size = blocked_domains.size(); | |
| 55 if (!size) { | |
| 56 if (items) { | |
| 57 delete items; | |
| 58 blocked_domains_map_.erase(client); | |
| 59 } | |
| 60 } else { | |
| 61 if (items) { | |
| 62 items->clear(); | |
| 63 } else { | |
| 64 items = new BlockedDomains(); | |
| 65 blocked_domains_map_[id] = items; | |
| 66 } | |
| 67 for (size_t i = 0; i < size; ++i) { | |
| 68 items->push_back(blocked_domains[i]); | |
| 69 } | |
| 70 } | |
| 71 | |
| 72 Transactions::iterator it = transactions_.begin(); | |
| 73 while (it != transactions_.end()) { | |
| 74 Transactions::iterator current = it++; | |
| 75 DevToolsNetworkTransaction* transaction = current->second; | |
| 76 const GURL& url = transaction->GetURL(); | |
| 77 for (size_t i = 0; i < size; ++i) { | |
| 78 if (url.DomainIs(blocked_domains[i].data())) { | |
| 79 transactions_.erase(current); | |
| 80 transaction->Stop(); | |
| 81 break; | |
| 82 } | |
| 83 } | |
| 84 } | |
| 85 } | |
| 86 | |
| 87 bool DevToolsNetworkController::IsBlockedURL(const GURL& url) { | |
| 88 BlockedDomainsMap::const_iterator client = blocked_domains_map_.begin(); | |
| 89 for (; client != blocked_domains_map_.end(); ++client) { | |
| 90 BlockedDomains* items = client->second; | |
| 91 BlockedDomains::const_iterator domain = items->begin(); | |
| 92 for (; domain != items->end(); ++domain) { | |
| 93 if (url.DomainIs(domain->data())) | |
| 94 return true; | |
| 95 } | |
| 96 } | |
| 97 return false; | |
|
mmenke
2014/03/11 21:16:53
Use two space indent.
eustas
2014/03/12 15:38:33
ooops. fixed.
| |
| 98 } | |
| 99 | |
| 100 int DevToolsNetworkController::CreateTransaction( | |
| 101 net::RequestPriority priority, | |
| 102 scoped_ptr<net::HttpTransaction>* trans) { | |
| 103 scoped_ptr<net::HttpTransaction> network_transaction; | |
| 104 int rv = network_layer_->CreateTransaction(priority, &network_transaction); | |
| 105 if (rv != net::OK) { | |
| 106 return rv; | |
| 107 } | |
| 108 DevToolsNetworkTransaction* transaction = new DevToolsNetworkTransaction( | |
| 109 weak_factory_.GetWeakPtr(), network_transaction); | |
| 110 transactions_[transaction->GetId()] = transaction; | |
| 111 trans->reset(transaction); | |
| 112 return net::OK; | |
| 113 } | |
| 114 | |
| 115 net::HttpCache* DevToolsNetworkController::GetCache() { | |
| 116 return network_layer_->GetCache(); | |
| 117 } | |
| 118 | |
| 119 net::HttpNetworkSession* DevToolsNetworkController::GetSession() { | |
| 120 return network_layer_->GetSession(); | |
| 121 } | |
| OLD | NEW |