Refactor SharedMemory::Create and fix a rare file leak.
[chromium-blink-merge.git] / chrome / browser / metrics / signin_status_metrics_provider.h
blob90b6b286f6f1dce248ba15d581b99c3c52f860dd
1 // Copyright 2014 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.
5 #ifndef CHROME_BROWSER_METRICS_SIGNIN_STATUS_METRICS_PROVIDER_H_
6 #define CHROME_BROWSER_METRICS_SIGNIN_STATUS_METRICS_PROVIDER_H_
8 #include <string>
10 #include "base/gtest_prod_util.h"
11 #include "base/memory/weak_ptr.h"
12 #include "base/scoped_observer.h"
13 #include "chrome/browser/metrics/signin_status_metrics_provider_base.h"
14 #include "chrome/browser/signin/signin_manager_factory.h"
15 #include "chrome/browser/ui/browser_list_observer.h"
16 #include "components/signin/core/browser/signin_manager_base.h"
18 class Browser;
20 namespace metrics {
21 class ChromeUserMetricsExtension;
24 // Collect login status of all opened profiles during one UMA session and
25 // record the value into a histogram before UMA log is uploaded on platform
26 // Windows, Linux, Mac and Android.
27 class SigninStatusMetricsProvider : public SigninStatusMetricsProviderBase,
28 public chrome::BrowserListObserver,
29 public SigninManagerBase::Observer,
30 public SigninManagerFactory::Observer {
31 public:
32 ~SigninStatusMetricsProvider() override;
34 // SigninStatusMetricsProviderBase:
35 void ProvideGeneralMetrics(
36 metrics::ChromeUserMetricsExtension* uma_proto) override;
38 // Factory method, creates a new instance of this class.
39 static SigninStatusMetricsProvider* CreateInstance();
41 private:
42 // The boolean |is_test| indicates whether or not this is an instance for
43 // testing purpose. If so, skip the initialization. Except for testing
44 // purpose, this class's instance should be created through the static
45 // CreateInstance() method.
46 explicit SigninStatusMetricsProvider(bool is_test);
48 FRIEND_TEST_ALL_PREFIXES(SigninStatusMetricsProvider,
49 UpdateInitialSigninStatus);
50 FRIEND_TEST_ALL_PREFIXES(SigninStatusMetricsProvider,
51 UpdateStatusWhenBrowserAdded);
52 FRIEND_TEST_ALL_PREFIXES(SigninStatusMetricsProvider, GoogleSigninSucceeded);
53 FRIEND_TEST_ALL_PREFIXES(SigninStatusMetricsProvider, GoogleSignedOut);
55 // chrome::BrowserListObserver:
56 // This will never be called on Android.
57 void OnBrowserAdded(Browser* browser) override;
59 // SigninManagerFactory::Observer:
60 void SigninManagerCreated(SigninManagerBase* manager) override;
61 void SigninManagerShutdown(SigninManagerBase* manager) override;
63 // SigninManagerBase::Observer:
64 void GoogleSigninSucceeded(const std::string& account_id,
65 const std::string& username,
66 const std::string& password) override;
67 void GoogleSignedOut(const std::string& account_id,
68 const std::string& username) override;
70 // Obtain sign-in status and add observers.
71 void Initialize();
73 // Update the sign-in status based on all currently opened profiles. Called by
74 // ComputeCurrentSigninStatus at class construction and right after each UMA
75 // log upload. |total_count| is the number of opened profiles and
76 // |signed_in_count| represents the number of signed-in profiles among those
77 // |total_count| profiles.
78 void UpdateInitialSigninStatus(size_t total_count, size_t signed_in_count);
80 // Update the sign-in status right after a new browser is opened.
81 void UpdateStatusWhenBrowserAdded(bool signed_in);
83 // Compute current sign-in status of all opened profiles.
84 void ComputeCurrentSigninStatus();
86 // Get the current recorded sign-in status. For testing purpose only.
87 SigninStatus GetSigninStatusForTesting();
89 // Used to track the SigninManagers that this instance is observing so that
90 // this instance can be removed as an observer on its destruction.
91 ScopedObserver<SigninManagerBase, SigninStatusMetricsProvider>
92 scoped_observer_;
94 // Whether the instance is for testing or not.
95 bool is_test_;
97 base::WeakPtrFactory<SigninStatusMetricsProvider> weak_ptr_factory_;
99 DISALLOW_COPY_AND_ASSIGN(SigninStatusMetricsProvider);
102 #endif // CHROME_BROWSER_METRICS_SIGNIN_STATUS_METRICS_PROVIDER_H_