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

Unified Diff: chrome/browser/net_benchmarking.cc

Issue 2521823008: Migrate chrome_net_benchmarking_message_filter to mojo (Closed)
Patch Set: Do not add NetBenchmaring interface if benchmarking is disabled Created 4 years 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
« no previous file with comments | « chrome/browser/net_benchmarking.h ('k') | chrome/common/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/net_benchmarking.cc
diff --git a/chrome/browser/net_benchmarking.cc b/chrome/browser/net_benchmarking.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b6792c61cc46e1b5f6ae5404fba22e41778a940a
--- /dev/null
+++ b/chrome/browser/net_benchmarking.cc
@@ -0,0 +1,105 @@
+// Copyright (c) 2012 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_benchmarking.h"
+
+#include <memory>
+#include <utility>
+
+#include "base/bind.h"
+#include "base/bind_helpers.h"
+#include "base/command_line.h"
+#include "base/macros.h"
+#include "chrome/browser/net/predictor.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/common/chrome_switches.h"
+#include "chrome/common/net_benchmarking.mojom.h"
+#include "content/public/browser/browser_thread.h"
+#include "mojo/public/cpp/bindings/strong_binding.h"
+#include "net/base/net_errors.h"
+#include "net/disk_cache/disk_cache.h"
+#include "net/dns/host_cache.h"
+#include "net/dns/host_resolver.h"
+#include "net/http/http_cache.h"
+#include "net/url_request/url_request_context.h"
+#include "net/url_request/url_request_context_getter.h"
+
+using content::BrowserThread;
+
+namespace {
+
+void ClearPredictorCacheOnUIThread(Profile* profile) {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+ // TODO(623967): Ensure that the profile or predictor are not accessed after
+ // they have been shut down.
+ chrome_browser_net::Predictor* predictor = profile->GetNetworkPredictor();
+ if (predictor)
+ predictor->DiscardAllResultsAndClearPrefsOnUIThread();
+}
+
+} // namespace
+
+NetBenchmarking::NetBenchmarking(Profile* profile,
+ net::URLRequestContextGetter* request_context)
+ : profile_(profile), request_context_(request_context) {}
+
+NetBenchmarking::~NetBenchmarking() {}
+
+// static
+void NetBenchmarking::Create(Profile* profile,
+ net::URLRequestContextGetter* request_context,
+ chrome::mojom::NetBenchmarkingRequest request) {
+ mojo::MakeStrongBinding(
+ base::MakeUnique<NetBenchmarking>(profile, request_context),
+ std::move(request));
+}
+
+// static
+bool NetBenchmarking::CheckBenchmarkingEnabled() {
+ const base::CommandLine& command_line =
+ *base::CommandLine::ForCurrentProcess();
+ return command_line.HasSwitch(switches::kEnableNetBenchmarking);
+}
+
+void NetBenchmarking::ClearCache(const ClearCacheCallback& callback) {
+ int rv = -1;
+
+ disk_cache::Backend* backend = request_context_->GetURLRequestContext()
+ ->http_transaction_factory()
+ ->GetCache()
+ ->GetCurrentBackend();
+ if (backend) {
+ rv = backend->DoomAllEntries(callback);
+ if (rv == net::ERR_IO_PENDING) {
+ // Callback is handled by backend.
+ return;
+ }
+ }
+ callback.Run(rv);
+}
+
+void NetBenchmarking::ClearHostResolverCache(
+ const ClearHostResolverCacheCallback& callback) {
+ net::HostCache* cache =
+ request_context_->GetURLRequestContext()->host_resolver()->GetHostCache();
+ if (cache)
+ cache->clear();
+ callback.Run();
+}
+
+void NetBenchmarking::CloseCurrentConnections(
+ const CloseCurrentConnectionsCallback& callback) {
+ request_context_->GetURLRequestContext()
+ ->http_transaction_factory()
+ ->GetCache()
+ ->CloseAllConnections();
+ callback.Run();
+}
+
+void NetBenchmarking::ClearPredictorCache(
+ const ClearPredictorCacheCallback& callback) {
+ BrowserThread::PostTaskAndReply(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(&ClearPredictorCacheOnUIThread, profile_), callback);
+}
« no previous file with comments | « chrome/browser/net_benchmarking.h ('k') | chrome/common/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698