1 // Copyright 2019 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_CACHED_METRICS_PROFILE_H_
6 #define CHROME_BROWSER_METRICS_CACHED_METRICS_PROFILE_H_
7 
8 #include "base/macros.h"
9 
10 class Profile;
11 
12 namespace metrics {
13 
14 // Caches a user profile to use in metrics providers if needed. Uses the first
15 // signed-in profile, and sticks with it until that profile becomes invalid.
16 class CachedMetricsProfile {
17  public:
18   CachedMetricsProfile();
19   ~CachedMetricsProfile();
20 
21   // Returns the profile for which metrics will be gathered. Once a suitable
22   // profile has been found, future calls will continue to return the same
23   // value so that reported metrics are consistent.
24   Profile* GetMetricsProfile();
25 
26  private:
27   // The profile for which metrics can be gathered. Once a profile is found,
28   // its value is cached here so that GetMetricsProfile() can return a
29   // consistent value.
30   Profile* cached_profile_ = nullptr;
31 
32   DISALLOW_COPY_AND_ASSIGN(CachedMetricsProfile);
33 };
34 
35 }  // namespace metrics
36 
37 #endif  // CHROME_BROWSER_METRICS_CACHED_METRICS_PROFILE_H_
38