mblsha | 3cfcb7c | 2017-04-20 14:59:39 | [diff] [blame] | 1 | // 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 Stade | 0a86f98 | 2019-09-23 20:52:58 | [diff] [blame] | 13 | #include "ui/compositor/compositor.h" |
mblsha | 3cfcb7c | 2017-04-20 14:59:39 | [diff] [blame] | 14 | #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. |
| 21 | class 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: |
mblsha | 3cfcb7c | 2017-04-20 14:59:39 | [diff] [blame] | 38 | void OnCompositingEnded(ui::Compositor* compositor) override; |
mblsha | 3cfcb7c | 2017-04-20 14:59:39 | [diff] [blame] | 39 | void OnCompositingShuttingDown(ui::Compositor* compositor) override; |
| 40 | |
Evan Stade | 0a86f98 | 2019-09-23 20:52:58 | [diff] [blame] | 41 | ScopedObserver<ui::Compositor, ui::CompositorObserver> scoped_observer_{this}; |
mblsha | 3cfcb7c | 2017-04-20 14:59:39 | [diff] [blame] | 42 | |
| 43 | DISALLOW_COPY_AND_ASSIGN(BrowserWindowHistogramHelper); |
| 44 | }; |
| 45 | |
| 46 | #endif // CHROME_BROWSER_METRICS_BROWSER_WINDOW_HISTOGRAM_HELPER_H_ |