Index: chrome/browser/net/network_controller.cc |
diff --git a/chrome/browser/net/network_controller.cc b/chrome/browser/net/network_controller.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..6aac487c421f2780f8669382f191ef4a1903f2cd |
--- /dev/null |
+++ b/chrome/browser/net/network_controller.cc |
@@ -0,0 +1,133 @@ |
+// Copyright (c) 2014 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 file. |
+ |
+#include "chrome/browser/net/network_controller.h" |
+ |
+#include "chrome/browser/net/network_transaction.h" |
+#include "chrome/browser/profiles/profile.h" |
+#include "chrome/browser/profiles/profile_io_data.h" |
+#include "content/public/browser/browser_thread.h" |
+#include "net/base/request_priority.h" |
+#include "net/http/http_network_layer.h" |
+#include "net/http/http_network_session.h" |
+#include "net/http/http_network_transaction.h" |
+ |
+NetworkController::NetworkController( |
+ net::HttpNetworkSession* session) |
+ : network_layer_(new net::HttpNetworkLayer(session)) { |
+} |
+ |
+NetworkController::~NetworkController() { |
+} |
+ |
+void NetworkController::AddTransaction( |
+ uint64 transaction_id, |
+ NetworkTransaction* transaction) { |
+ transactions_[transaction_id] = transaction; |
+} |
+ |
+void NetworkController::RemoveTransaction(uint64 transaction_id) { |
+ transactions_.erase(transaction_id); |
+} |
+ |
+ |
mmenke
2014/03/12 15:59:27
nit: Remove extra blank line.
eustas
2014/03/13 13:11:09
Done.
|
+// static |
+void NetworkController::SetBlockedDomains( |
+ Profile* profile, |
+ const std::string& client_id, |
+ const std::vector<std::string>& blocked_domains) { |
+ content::BrowserThread::PostTask( |
+ content::BrowserThread::IO, |
+ FROM_HERE, |
+ base::Bind( |
+ &NetworkController::SetBlockedDomainsOnIO, |
+ profile, |
mmenke
2014/03/12 15:59:27
Actually, should do profile->GetResourceContext()
eustas
2014/03/13 13:11:09
Done.
|
+ client_id, |
+ blocked_domains)); |
+} |
+ |
+// static |
+void NetworkController::SetBlockedDomainsOnIO( |
+ Profile* profile, |
+ const std::string& client_id, |
+ const std::vector<std::string>& blocked_domains) { |
+ CHECK(profile); |
+ NetworkController* controller = ProfileIOData::FromResourceContext( |
+ profile->GetResourceContext())->network_controller(); |
+ CHECK(controller); |
+ controller->SetBlockedDomains(client_id, blocked_domains); |
+} |
+ |
+void NetworkController::SetBlockedDomains( |
+ const std::string& client_id, |
+ const std::vector<std::string>& blocked_domains) { |
+ BlockedDomains* items = NULL; |
+ BlockedDomainsMap::iterator client = blocked_domains_map_.find(client_id); |
+ if (client != blocked_domains_map_.end()) |
+ items = client->second; |
+ size_t size = blocked_domains.size(); |
+ if (!size) { |
+ if (items) { |
+ delete items; |
+ blocked_domains_map_.erase(client); |
+ } |
+ } else { |
+ if (items) { |
+ items->clear(); |
+ } else { |
+ items = new BlockedDomains(); |
+ blocked_domains_map_[client_id] = items; |
+ } |
+ for (size_t i = 0; i < size; ++i) { |
+ items->push_back(blocked_domains[i]); |
+ } |
+ } |
+ |
+ Transactions::iterator it = transactions_.begin(); |
+ while (it != transactions_.end()) { |
+ Transactions::iterator current = it++; |
+ NetworkTransaction* transaction = current->second; |
+ const GURL& url = transaction->GetURL(); |
+ for (size_t i = 0; i < size; ++i) { |
+ if (url.DomainIs(blocked_domains[i].data())) { |
+ transactions_.erase(current); |
+ transaction->Stop(); |
+ break; |
+ } |
+ } |
+ } |
+} |
+ |
+bool NetworkController::IsBlockedURL(const GURL& url) { |
+ BlockedDomainsMap::const_iterator client = blocked_domains_map_.begin(); |
+ for (; client != blocked_domains_map_.end(); ++client) { |
+ BlockedDomains* items = client->second; |
+ BlockedDomains::const_iterator domain = items->begin(); |
+ for (; domain != items->end(); ++domain) { |
+ if (url.DomainIs(domain->data())) |
+ return true; |
+ } |
+ } |
+ return false; |
+} |
+ |
+int NetworkController::CreateTransaction( |
+ net::RequestPriority priority, |
+ scoped_ptr<net::HttpTransaction>* trans) { |
+ scoped_ptr<net::HttpTransaction> network_transaction; |
+ int rv = network_layer_->CreateTransaction(priority, &network_transaction); |
+ if (rv != net::OK) { |
+ return rv; |
+ } |
+ trans->reset(new NetworkTransaction(this, network_transaction)); |
+ return net::OK; |
+} |
+ |
+net::HttpCache* NetworkController::GetCache() { |
+ return network_layer_->GetCache(); |
+} |
+ |
+net::HttpNetworkSession* NetworkController::GetSession() { |
+ return network_layer_->GetSession(); |
+} |