blob: 48218e23cd14ca92d9d183d13e5ae89a22416c02 [file] [log] [blame]
dvallet233f57ab2016-12-21 03:17:101// Copyright (c) 2011 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#ifndef CHROME_BROWSER_NET_BENCHMARKING_H_
6#define CHROME_BROWSER_NET_BENCHMARKING_H_
7
8#include "base/macros.h"
Alexandr Ilin4909ec82018-06-06 10:22:489#include "base/memory/weak_ptr.h"
dvallet233f57ab2016-12-21 03:17:1010#include "chrome/common/net_benchmarking.mojom.h"
11
Alexandr Ilin4909ec82018-06-06 10:22:4812namespace chrome_browser_net {
13class Predictor;
14}
dvallet233f57ab2016-12-21 03:17:1015
Alexandr Ilin4909ec82018-06-06 10:22:4816namespace predictors {
17class LoadingPredictor;
18}
19
20// This class handles Chrome-specific benchmarking IPC messages for the renderer
21// process.
22// All methods of this class should be called on the IO thread unless the
23// contrary is explicitly specified.
dvallet233f57ab2016-12-21 03:17:1024class NetBenchmarking : public chrome::mojom::NetBenchmarking {
25 public:
Alexandr Ilin4909ec82018-06-06 10:22:4826 NetBenchmarking(base::WeakPtr<predictors::LoadingPredictor> loading_predictor,
27 base::WeakPtr<chrome_browser_net::Predictor> predictor,
Robbie McElrathb0f248c2018-07-24 19:44:1628 int render_process_id);
dvallet233f57ab2016-12-21 03:17:1029 ~NetBenchmarking() override;
30
Alexandr Ilin4909ec82018-06-06 10:22:4831 // Creates a NetBenchmarking instance and connects it strongly to a mojo pipe.
32 // Callers should prefer this over using the constructor directly.
33 static void Create(
34 base::WeakPtr<predictors::LoadingPredictor> loading_predictor,
35 base::WeakPtr<chrome_browser_net::Predictor> predictor,
Robbie McElrathb0f248c2018-07-24 19:44:1636 int render_process_id,
Alexandr Ilin4909ec82018-06-06 10:22:4837 chrome::mojom::NetBenchmarkingRequest request);
38
39 // This method is thread-safe.
dvallet233f57ab2016-12-21 03:17:1040 static bool CheckBenchmarkingEnabled();
41
42 private:
43 // chrome:mojom:NetBenchmarking.
44 void CloseCurrentConnections(
tzikcd02d3b2018-08-09 21:32:4745 CloseCurrentConnectionsCallback callback) override;
46 void ClearCache(ClearCacheCallback callback) override;
47 void ClearHostResolverCache(ClearHostResolverCacheCallback callback) override;
48 void ClearPredictorCache(ClearPredictorCacheCallback callback) override;
dvallet233f57ab2016-12-21 03:17:1049
Alexandr Ilin4909ec82018-06-06 10:22:4850 // These weak pointers should be dereferenced only on the UI thread.
51 base::WeakPtr<predictors::LoadingPredictor> loading_predictor_;
52 base::WeakPtr<chrome_browser_net::Predictor> predictor_;
Robbie McElrathb0f248c2018-07-24 19:44:1653 const int render_process_id_;
dvallet233f57ab2016-12-21 03:17:1054
55 DISALLOW_COPY_AND_ASSIGN(NetBenchmarking);
56};
57
58#endif // CHROME_BROWSER_NET_BENCHMARKING_H_