1 // Copyright 2011 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_NET_BENCHMARKING_H_
6 #define CHROME_BROWSER_NET_BENCHMARKING_H_
8 #include "base/memory/weak_ptr.h"
9 #include "chrome/common/net_benchmarking.mojom.h"
10 #include "mojo/public/cpp/bindings/pending_receiver.h"
12 namespace predictors {
13 class LoadingPredictor;
16 // This class handles Chrome-specific benchmarking IPC messages for the renderer
18 // All methods of this class should be called on the IO thread unless the
19 // contrary is explicitly specified.
20 class NetBenchmarking : public chrome::mojom::NetBenchmarking {
22 NetBenchmarking(base::WeakPtr<predictors::LoadingPredictor> loading_predictor,
23 int render_process_id);
25 NetBenchmarking(const NetBenchmarking&) = delete;
26 NetBenchmarking& operator=(const NetBenchmarking&) = delete;
28 ~NetBenchmarking() override;
30 // Creates a NetBenchmarking instance and connects it strongly to a mojo pipe.
31 // Callers should prefer this over using the constructor directly.
33 base::WeakPtr<predictors::LoadingPredictor> loading_predictor,
34 int render_process_id,
35 mojo::PendingReceiver<chrome::mojom::NetBenchmarking> receiver);
37 // This method is thread-safe.
38 static bool CheckBenchmarkingEnabled();
41 // chrome:mojom:NetBenchmarking.
42 void CloseCurrentConnections(
43 CloseCurrentConnectionsCallback callback) override;
44 void ClearCache(ClearCacheCallback callback) override;
45 void ClearHostResolverCache(ClearHostResolverCacheCallback callback) override;
46 void ClearPredictorCache(ClearPredictorCacheCallback callback) override;
48 // These weak pointers should be dereferenced only on the UI thread.
49 base::WeakPtr<predictors::LoadingPredictor> loading_predictor_;
50 const int render_process_id_;
53 #endif // CHROME_BROWSER_NET_BENCHMARKING_H_