Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(603)

Side by Side Diff: chrome/browser/net/network_controller.cc

Issue 182993003: Add the ability for DevTools to wrap network transactions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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/net/network_controller.h"
6
7 #include "chrome/browser/net/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 NetworkController::NetworkController(
17 net::HttpNetworkSession* session)
18 : network_layer_(new net::HttpNetworkLayer(session)) {
19 }
20
21 NetworkController::~NetworkController() {
22 }
23
24 void NetworkController::AddTransaction(
25 uint64 transaction_id,
26 NetworkTransaction* transaction) {
27 transactions_[transaction_id] = transaction;
28 }
29
30 void NetworkController::RemoveTransaction(uint64 transaction_id) {
31 transactions_.erase(transaction_id);
32 }
33
34
mmenke 2014/03/12 15:59:27 nit: Remove extra blank line.
eustas 2014/03/13 13:11:09 Done.
35 // static
36 void NetworkController::SetBlockedDomains(
37 Profile* profile,
38 const std::string& client_id,
39 const std::vector<std::string>& blocked_domains) {
40 content::BrowserThread::PostTask(
41 content::BrowserThread::IO,
42 FROM_HERE,
43 base::Bind(
44 &NetworkController::SetBlockedDomainsOnIO,
45 profile,
mmenke 2014/03/12 15:59:27 Actually, should do profile->GetResourceContext()
eustas 2014/03/13 13:11:09 Done.
46 client_id,
47 blocked_domains));
48 }
49
50 // static
51 void NetworkController::SetBlockedDomainsOnIO(
52 Profile* profile,
53 const std::string& client_id,
54 const std::vector<std::string>& blocked_domains) {
55 CHECK(profile);
56 NetworkController* controller = ProfileIOData::FromResourceContext(
57 profile->GetResourceContext())->network_controller();
58 CHECK(controller);
59 controller->SetBlockedDomains(client_id, blocked_domains);
60 }
61
62 void NetworkController::SetBlockedDomains(
63 const std::string& client_id,
64 const std::vector<std::string>& blocked_domains) {
65 BlockedDomains* items = NULL;
66 BlockedDomainsMap::iterator client = blocked_domains_map_.find(client_id);
67 if (client != blocked_domains_map_.end())
68 items = client->second;
69 size_t size = blocked_domains.size();
70 if (!size) {
71 if (items) {
72 delete items;
73 blocked_domains_map_.erase(client);
74 }
75 } else {
76 if (items) {
77 items->clear();
78 } else {
79 items = new BlockedDomains();
80 blocked_domains_map_[client_id] = items;
81 }
82 for (size_t i = 0; i < size; ++i) {
83 items->push_back(blocked_domains[i]);
84 }
85 }
86
87 Transactions::iterator it = transactions_.begin();
88 while (it != transactions_.end()) {
89 Transactions::iterator current = it++;
90 NetworkTransaction* transaction = current->second;
91 const GURL& url = transaction->GetURL();
92 for (size_t i = 0; i < size; ++i) {
93 if (url.DomainIs(blocked_domains[i].data())) {
94 transactions_.erase(current);
95 transaction->Stop();
96 break;
97 }
98 }
99 }
100 }
101
102 bool NetworkController::IsBlockedURL(const GURL& url) {
103 BlockedDomainsMap::const_iterator client = blocked_domains_map_.begin();
104 for (; client != blocked_domains_map_.end(); ++client) {
105 BlockedDomains* items = client->second;
106 BlockedDomains::const_iterator domain = items->begin();
107 for (; domain != items->end(); ++domain) {
108 if (url.DomainIs(domain->data()))
109 return true;
110 }
111 }
112 return false;
113 }
114
115 int NetworkController::CreateTransaction(
116 net::RequestPriority priority,
117 scoped_ptr<net::HttpTransaction>* trans) {
118 scoped_ptr<net::HttpTransaction> network_transaction;
119 int rv = network_layer_->CreateTransaction(priority, &network_transaction);
120 if (rv != net::OK) {
121 return rv;
122 }
123 trans->reset(new NetworkTransaction(this, network_transaction));
124 return net::OK;
125 }
126
127 net::HttpCache* NetworkController::GetCache() {
128 return network_layer_->GetCache();
129 }
130
131 net::HttpNetworkSession* NetworkController::GetSession() {
132 return network_layer_->GetSession();
133 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698