Componentize component_updater: Copy over test data with executable bit.
[chromium-blink-merge.git] / chrome / browser / metrics / signin_status_metrics_provider.h
blob71caef8d31dcce3e5d2a940fb0434a114f6ad358
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/signin/signin_manager_factory.h"
14 #include "chrome/browser/ui/browser_list_observer.h"
15 #include "components/metrics/metrics_provider.h"
16 #include "components/signin/core/browser/signin_manager_base.h"
18 class Browser;
20 namespace base {
21 class FilePath;
24 // Collect login status of all opened profiles during one UMA session and record
25 // the value into a histogram before UMA log is uploaded. It's currently not
26 // supported on platform chromeos, Android or iOS.
27 class SigninStatusMetricsProvider : public metrics::MetricsProvider,
28 public chrome::BrowserListObserver,
29 public SigninManagerBase::Observer,
30 public SigninManagerFactory::Observer {
31 public:
32 virtual ~SigninStatusMetricsProvider();
34 // Record the collected sign-in status into a histogram and re-check current
35 // sign-in status to get prepared for the next UMA session. Called by
36 // MetricsServiceClient when it is collecting final metrics.
37 void RecordSigninStatusHistogram();
39 // Factory method, creates a new instance of this class.
40 static SigninStatusMetricsProvider* CreateInstance();
42 private:
43 // The boolean |is_test| indicates whether or not this is an instance for
44 // testing purpose. If so, skip the initialization. Except for testing
45 // purpose, this class's instance should be created through the static
46 // CreateInstance() method.
47 explicit SigninStatusMetricsProvider(bool is_test);
49 FRIEND_TEST_ALL_PREFIXES(SigninStatusMetricsProvider,
50 UpdateInitialSigninStatus);
51 FRIEND_TEST_ALL_PREFIXES(SigninStatusMetricsProvider,
52 UpdateStatusWhenBrowserAdded);
53 FRIEND_TEST_ALL_PREFIXES(SigninStatusMetricsProvider, GoogleSigninSucceeded);
54 FRIEND_TEST_ALL_PREFIXES(SigninStatusMetricsProvider, GoogleSignedOut);
56 // Possible sign-in status of all opened profiles during one UMA session. For
57 // MIXED_SIGNIN_STATUS, at least one signed-in profile and at least one
58 // unsigned-in profile were opened between two UMA log uploads.
59 enum ProfilesSigninStatus {
60 ALL_PROFILES_SIGNED_IN,
61 ALL_PROFILES_NOT_SIGNED_IN,
62 MIXED_SIGNIN_STATUS,
63 UNKNOWN_SIGNIN_STATUS,
64 SIGNIN_STATUS_MAX,
67 // chrome::BrowserListObserver:
68 // This will never be called on Android.
69 virtual void OnBrowserAdded(Browser* browser) OVERRIDE;
71 // SigninManagerFactory::Observer:
72 virtual void SigninManagerCreated(SigninManagerBase* manager) OVERRIDE;
73 virtual void SigninManagerShutdown(SigninManagerBase* manager) OVERRIDE;
75 // SigninManagerBase::Observer:
76 virtual void GoogleSigninSucceeded(const std::string& username,
77 const std::string& password) OVERRIDE;
78 virtual void GoogleSignedOut(const std::string& username) OVERRIDE;
80 // Obtain sign-in status and add observers.
81 void Initialize();
83 // Update the sign-in status based on all currently opened profiles. Called by
84 // ComputeCurrentSigninStatus at class construction and right after each UMA
85 // log upload. |total_count| is the number of opened profiles and
86 // |signed_in_count| represents the number of signed-in profiles among those
87 // |total_count| profiles.
88 void UpdateInitialSigninStatus(size_t total_count, size_t signed_in_count);
90 // Update the sign-in status right after a new browser is opened.
91 void UpdateStatusWhenBrowserAdded(bool signed_in);
93 // Compute current sign-in status of all opened profiles.
94 void ComputeCurrentSigninStatus();
96 // Get the current recorded sign-in status. For testing purpose only.
97 ProfilesSigninStatus GetSigninStatusForTesting();
99 // Sign-in status of all profiles seen so far.
100 ProfilesSigninStatus signin_status_;
102 // Used to track the SigninManagers that this instance is observing so that
103 // this instance can be removed as an observer on its destruction.
104 ScopedObserver<SigninManagerBase, SigninStatusMetricsProvider>
105 scoped_observer_;
107 // Whether the instance is for testing or not.
108 bool is_test_;
110 base::WeakPtrFactory<SigninStatusMetricsProvider> weak_ptr_factory_;
112 DISALLOW_COPY_AND_ASSIGN(SigninStatusMetricsProvider);
115 #endif // CHROME_BROWSER_METRICS_SIGNIN_STATUS_METRICS_PROVIDER_H_