| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/metrics/signin_status_metrics_provider.h" | 5 #include "chrome/browser/metrics/signin_status_metrics_provider.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 if (signin_status_ == MIXED_SIGNIN_STATUS) | 85 if (signin_status_ == MIXED_SIGNIN_STATUS) |
| 86 return; | 86 return; |
| 87 | 87 |
| 88 SigninManager* manager = SigninManagerFactory::GetForProfile( | 88 SigninManager* manager = SigninManagerFactory::GetForProfile( |
| 89 browser->profile()); | 89 browser->profile()); |
| 90 | 90 |
| 91 // Nothing will change if the opened browser is in incognito mode. | 91 // Nothing will change if the opened browser is in incognito mode. |
| 92 if (!manager) | 92 if (!manager) |
| 93 return; | 93 return; |
| 94 | 94 |
| 95 const bool signed_in = !manager->GetAuthenticatedUsername().empty(); | 95 const bool signed_in = manager->IsAuthenticated(); |
| 96 UpdateStatusWhenBrowserAdded(signed_in); | 96 UpdateStatusWhenBrowserAdded(signed_in); |
| 97 } | 97 } |
| 98 | 98 |
| 99 void SigninStatusMetricsProvider::SigninManagerCreated( | 99 void SigninStatusMetricsProvider::SigninManagerCreated( |
| 100 SigninManagerBase* manager) { | 100 SigninManagerBase* manager) { |
| 101 // Whenever a new profile is created, a new SigninManagerBase will be created | 101 // Whenever a new profile is created, a new SigninManagerBase will be created |
| 102 // for it. This ensures that all sign-in or sign-out actions of all opened | 102 // for it. This ensures that all sign-in or sign-out actions of all opened |
| 103 // profiles are being monitored. | 103 // profiles are being monitored. |
| 104 scoped_observer_.Add(manager); | 104 scoped_observer_.Add(manager); |
| 105 | 105 |
| 106 // If the status is unknown, it means this is the first created | 106 // If the status is unknown, it means this is the first created |
| 107 // SigninManagerBase and the corresponding profile should be the only opened | 107 // SigninManagerBase and the corresponding profile should be the only opened |
| 108 // profile. | 108 // profile. |
| 109 if (signin_status_ == UNKNOWN_SIGNIN_STATUS) { | 109 if (signin_status_ == UNKNOWN_SIGNIN_STATUS) { |
| 110 size_t signed_in_count = | 110 size_t signed_in_count = |
| 111 manager->GetAuthenticatedUsername().empty() ? 0 : 1; | 111 manager->IsAuthenticated() ? 1 : 0; |
| 112 UpdateInitialSigninStatus(1, signed_in_count); | 112 UpdateInitialSigninStatus(1, signed_in_count); |
| 113 } | 113 } |
| 114 } | 114 } |
| 115 | 115 |
| 116 void SigninStatusMetricsProvider::SigninManagerShutdown( | 116 void SigninStatusMetricsProvider::SigninManagerShutdown( |
| 117 SigninManagerBase* manager) { | 117 SigninManagerBase* manager) { |
| 118 if (scoped_observer_.IsObserving(manager)) | 118 if (scoped_observer_.IsObserving(manager)) |
| 119 scoped_observer_.Remove(manager); | 119 scoped_observer_.Remove(manager); |
| 120 } | 120 } |
| 121 | 121 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 for (size_t i = 0; i < profile_list.size(); ++i) { | 203 for (size_t i = 0; i < profile_list.size(); ++i) { |
| 204 #if !defined(OS_ANDROID) | 204 #if !defined(OS_ANDROID) |
| 205 if (chrome::GetTotalBrowserCountForProfile(profile_list[i]) == 0) { | 205 if (chrome::GetTotalBrowserCountForProfile(profile_list[i]) == 0) { |
| 206 // The profile is loaded, but there's no opened browser for this profile. | 206 // The profile is loaded, but there's no opened browser for this profile. |
| 207 continue; | 207 continue; |
| 208 } | 208 } |
| 209 #endif | 209 #endif |
| 210 opened_profiles_count++; | 210 opened_profiles_count++; |
| 211 SigninManager* manager = SigninManagerFactory::GetForProfile( | 211 SigninManager* manager = SigninManagerFactory::GetForProfile( |
| 212 profile_list[i]->GetOriginalProfile()); | 212 profile_list[i]->GetOriginalProfile()); |
| 213 if (manager && !manager->GetAuthenticatedUsername().empty()) | 213 if (manager && manager->IsAuthenticated()) |
| 214 signed_in_profiles_count++; | 214 signed_in_profiles_count++; |
| 215 } | 215 } |
| 216 UpdateInitialSigninStatus(opened_profiles_count, signed_in_profiles_count); | 216 UpdateInitialSigninStatus(opened_profiles_count, signed_in_profiles_count); |
| 217 } | 217 } |
| 218 | 218 |
| 219 SigninStatusMetricsProvider::ProfilesSigninStatus | 219 SigninStatusMetricsProvider::ProfilesSigninStatus |
| 220 SigninStatusMetricsProvider::GetSigninStatusForTesting() { | 220 SigninStatusMetricsProvider::GetSigninStatusForTesting() { |
| 221 return signin_status_; | 221 return signin_status_; |
| 222 } | 222 } |
| OLD | NEW |