blob: 648f38230ecb60d8ee7776e154d0a171860a8045 [file] [log] [blame]
mblsha3cfcb7c2017-04-20 14:59:391// Copyright 2017 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_METRICS_BROWSER_WINDOW_HISTOGRAM_HELPER_H_
6#define CHROME_BROWSER_METRICS_BROWSER_WINDOW_HISTOGRAM_HELPER_H_
7
8#include <memory>
9
10#include "base/macros.h"
11#include "base/scoped_observer.h"
12#include "base/time/time.h"
Evan Stade0a86f982019-09-23 20:52:5813#include "ui/compositor/compositor.h"
mblsha3cfcb7c2017-04-20 14:59:3914#include "ui/compositor/compositor_observer.h"
15
16// Class that encapsulates logic of recording
17// Startup.BrowserWindow.FirstPaint* histograms.
18//
19// There's a dependency on ui/compositor therefore it can't be moved to
20// components/startup_metrics_utils.
21class BrowserWindowHistogramHelper : public ui::CompositorObserver {
22 public:
23 ~BrowserWindowHistogramHelper() override;
24
25 // Call this when the Browser finishes painting its UI, and the user will see
26 // it after next Compositor frame swap.
27 // |compositor| is the compositor that composites the just-painted Browser
28 // widget, or nullptr in Cocoa (we're using CoreAnimation's compositor there).
29 // Returned object should stay alive until next |OnCompositingStarted|
30 // callback.
31 static std::unique_ptr<BrowserWindowHistogramHelper>
32 MaybeRecordValueAndCreateInstanceOnBrowserPaint(ui::Compositor* compositor);
33
34 private:
35 explicit BrowserWindowHistogramHelper(ui::Compositor* compositor);
36
37 // ui::CompositorObserver:
mblsha3cfcb7c2017-04-20 14:59:3938 void OnCompositingEnded(ui::Compositor* compositor) override;
mblsha3cfcb7c2017-04-20 14:59:3939 void OnCompositingShuttingDown(ui::Compositor* compositor) override;
40
Evan Stade0a86f982019-09-23 20:52:5841 ScopedObserver<ui::Compositor, ui::CompositorObserver> scoped_observer_{this};
mblsha3cfcb7c2017-04-20 14:59:3942
43 DISALLOW_COPY_AND_ASSIGN(BrowserWindowHistogramHelper);
44};
45
46#endif // CHROME_BROWSER_METRICS_BROWSER_WINDOW_HISTOGRAM_HELPER_H_