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

Unified 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: Split controller and factory 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 side-by-side diff with in-line comments
Download patch
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..a857691ba357e1d5696bd21523fc5dddac910dd9
--- /dev/null
+++ b/chrome/browser/net/network_controller.cc
@@ -0,0 +1,95 @@
+// Copyright 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 "content/public/browser/resource_context.h"
+
+NetworkController::NetworkController() {
+}
+
+NetworkController::~NetworkController() {
+}
+
+void NetworkController::AddTransaction(
+ uint64 transaction_id,
+ NetworkTransaction* transaction) {
+ transactions_[transaction_id] = transaction;
+}
+
+void NetworkController::RemoveTransaction(uint64 transaction_id) {
+ transactions_.erase(transaction_id);
+}
+
+// static
+void NetworkController::DisableNetwork(
+ Profile* profile,
+ const std::string& client_id,
+ bool disable_network) {
+ CHECK(profile);
+ content::ResourceContext* resourceContext = profile->GetResourceContext();
+ CHECK(resourceContext);
+ content::BrowserThread::PostTask(
+ content::BrowserThread::IO,
+ FROM_HERE,
+ base::Bind(
+ &NetworkController::DisableNetworkOnIO,
+ resourceContext,
+ client_id,
+ disable_network));
+}
+
+// static
+void NetworkController::DisableNetworkOnIO(
+ content::ResourceContext* resourceContext,
+ const std::string& client_id,
+ bool disable_network) {
+ CHECK(resourceContext);
+ NetworkController* controller = ProfileIOData::FromResourceContext(
+ resourceContext)->network_controller();
+ CHECK(controller);
+ controller->DisableNetwork(client_id, disable_network);
+}
+
+void NetworkController::DisableNetwork(
+ const std::string& client_id,
+ bool disable_network) {
+ ClientsSet::iterator client = clients_set_.find(client_id);
+ if (client != clients_set_.end()) {
+ if (!disable_network)
+ clients_set_.erase(client);
+ return;
+ }
+
+ if (!disable_network)
+ return;
+
+ bool first_client = clients_set_.size() == 0;
+ clients_set_.insert(client_id);
+ if (!first_client)
+ return;
+
+ Transactions::iterator it = transactions_.begin();
+ while (it != transactions_.end()) {
+ Transactions::iterator current = it++;
+ NetworkTransaction* transaction = current->second;
+ if (IsBlockedURL(transaction->GetURL())) {
+ transactions_.erase(current);
+ transaction->Stop();
+ }
+ }
+}
+
+bool NetworkController::IsBlockedURL(const GURL& url) {
+ if (clients_set_.size() == 0)
+ return false;
+
+ // TODO: Add whitelist.
+
+ return true;
+}

Powered by Google App Engine
This is Rietveld 408576698