blob: f8b6c0d98c9ca8e0ed96b33172abb03157909c02 [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"
Julie Jeongeun Kim924acc82019-09-28 01:26:1011#include "mojo/public/cpp/bindings/pending_receiver.h"
dvallet233f57ab2016-12-21 03:17:1012
Alexandr Ilin4909ec82018-06-06 10:22:4813namespace predictors {
14class LoadingPredictor;
15}
16
17// This class handles Chrome-specific benchmarking IPC messages for the renderer
18// process.
19// All methods of this class should be called on the IO thread unless the
20// contrary is explicitly specified.
dvallet233f57ab2016-12-21 03:17:1021class NetBenchmarking : public chrome::mojom::NetBenchmarking {
22 public:
Alexandr Ilin4909ec82018-06-06 10:22:4823 NetBenchmarking(base::WeakPtr<predictors::LoadingPredictor> loading_predictor,
Robbie McElrathb0f248c2018-07-24 19:44:1624 int render_process_id);
dvallet233f57ab2016-12-21 03:17:1025 ~NetBenchmarking() override;
26
Alexandr Ilin4909ec82018-06-06 10:22:4827 // Creates a NetBenchmarking instance and connects it strongly to a mojo pipe.
28 // Callers should prefer this over using the constructor directly.
29 static void Create(
30 base::WeakPtr<predictors::LoadingPredictor> loading_predictor,
Robbie McElrathb0f248c2018-07-24 19:44:1631 int render_process_id,
Julie Jeongeun Kim924acc82019-09-28 01:26:1032 mojo::PendingReceiver<chrome::mojom::NetBenchmarking> receiver);
Alexandr Ilin4909ec82018-06-06 10:22:4833
34 // This method is thread-safe.
dvallet233f57ab2016-12-21 03:17:1035 static bool CheckBenchmarkingEnabled();
36
37 private:
38 // chrome:mojom:NetBenchmarking.
39 void CloseCurrentConnections(
tzikcd02d3b2018-08-09 21:32:4740 CloseCurrentConnectionsCallback callback) override;
41 void ClearCache(ClearCacheCallback callback) override;
42 void ClearHostResolverCache(ClearHostResolverCacheCallback callback) override;
43 void ClearPredictorCache(ClearPredictorCacheCallback callback) override;
dvallet233f57ab2016-12-21 03:17:1044
Alexandr Ilin4909ec82018-06-06 10:22:4845 // These weak pointers should be dereferenced only on the UI thread.
46 base::WeakPtr<predictors::LoadingPredictor> loading_predictor_;
Robbie McElrathb0f248c2018-07-24 19:44:1647 const int render_process_id_;
dvallet233f57ab2016-12-21 03:17:1048
49 DISALLOW_COPY_AND_ASSIGN(NetBenchmarking);
50};
51
52#endif // CHROME_BROWSER_NET_BENCHMARKING_H_