Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(486)

Side by Side Diff: chrome/browser/chromeos/login/login_utils.cc

Issue 344883002: Collect UMA statistics on which chrome://flags lead to chrome restart on ChromeOS. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added test for AreSwitchesIdenticalToCurrentCommandLine(..., difference). Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/chromeos/login/login_utils.h" 5 #include "chrome/browser/chromeos/login/login_utils.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/base_paths.h" 11 #include "base/base_paths.h"
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "base/compiler_specific.h" 14 #include "base/compiler_specific.h"
15 #include "base/file_util.h" 15 #include "base/file_util.h"
16 #include "base/files/file_path.h" 16 #include "base/files/file_path.h"
17 #include "base/location.h" 17 #include "base/location.h"
18 #include "base/memory/ref_counted.h" 18 #include "base/memory/ref_counted.h"
19 #include "base/memory/scoped_ptr.h" 19 #include "base/memory/scoped_ptr.h"
20 #include "base/memory/singleton.h" 20 #include "base/memory/singleton.h"
21 #include "base/memory/weak_ptr.h" 21 #include "base/memory/weak_ptr.h"
22 #include "base/metrics/sparse_histogram.h"
22 #include "base/prefs/pref_member.h" 23 #include "base/prefs/pref_member.h"
23 #include "base/prefs/pref_service.h" 24 #include "base/prefs/pref_service.h"
24 #include "base/strings/string_util.h" 25 #include "base/strings/string_util.h"
25 #include "base/strings/utf_string_conversions.h" 26 #include "base/strings/utf_string_conversions.h"
26 #include "base/synchronization/lock.h" 27 #include "base/synchronization/lock.h"
27 #include "base/sys_info.h" 28 #include "base/sys_info.h"
28 #include "base/task_runner_util.h" 29 #include "base/task_runner_util.h"
29 #include "base/threading/worker_pool.h" 30 #include "base/threading/worker_pool.h"
30 #include "base/time/time.h" 31 #include "base/time/time.h"
31 #include "chrome/browser/about_flags.h" 32 #include "chrome/browser/about_flags.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 #include "components/signin/core/browser/signin_manager.h" 79 #include "components/signin/core/browser/signin_manager.h"
79 #include "content/public/browser/browser_thread.h" 80 #include "content/public/browser/browser_thread.h"
80 #include "content/public/browser/notification_service.h" 81 #include "content/public/browser/notification_service.h"
81 #include "google_apis/gaia/gaia_auth_consumer.h" 82 #include "google_apis/gaia/gaia_auth_consumer.h"
82 #include "net/base/network_change_notifier.h" 83 #include "net/base/network_change_notifier.h"
83 #include "net/url_request/url_request_context.h" 84 #include "net/url_request/url_request_context.h"
84 #include "net/url_request/url_request_context_getter.h" 85 #include "net/url_request/url_request_context_getter.h"
85 #include "url/gurl.h" 86 #include "url/gurl.h"
86 87
87 using content::BrowserThread; 88 using content::BrowserThread;
88
89 namespace chromeos { 89 namespace chromeos {
90 90
91 struct DoBrowserLaunchOnLocaleLoadedData; 91 struct DoBrowserLaunchOnLocaleLoadedData;
92 92
93 namespace {
94
95 void ReportCustomFlags(const std::set<std::string>& command_line_difference) {
96 const std::map<std::string, int>& switch_histogram_id =
Lei Zhang 2014/06/26 20:03:14 |switch_histogram_id| -> switch_histogram_ids or s
Alexander Alekseev 2014/06/27 19:28:37 Done.
97 about_flags::GetSwitchesHistogramId();
98 for (std::set<std::string>::const_iterator i =
Lei Zhang 2014/06/26 20:03:14 in general: i -> it for iterators
Alexander Alekseev 2014/06/27 19:28:37 Done.
99 command_line_difference.begin();
100 i != command_line_difference.end();
101 ++i) {
102 int uma_id = about_flags::UMA_HISTOGRAM_ID_UNKNOWN_FLAG;
103 if (i->size() > 2) {
104 // skip '--' before switch name
105 const std::string switch_name(&((*i)[2]));
Lei Zhang 2014/06/26 20:03:14 i->substring(2) is a bit more readable than &((*i)
Alexander Alekseev 2014/06/27 19:28:37 Done.
106 const std::map<std::string, int>::const_iterator pos =
107 switch_histogram_id.find(switch_name);
108 if (pos != switch_histogram_id.end()) {
109 uma_id = pos->second;
110 } else {
111 uma_id = about_flags::UMA_HISTOGRAM_ID_UNKNOWN_FLAG;
112 LOG(ERROR) << "ReportCustomFlags(): flag '" << *i << "' ('"
113 << switch_name << "') is unknown.";
114 }
115 } else {
116 uma_id = about_flags::UMA_HISTOGRAM_ID_BAD_FLAG_FORMAT;
117 LOG(ERROR) << "ReportCustomFlags(): flag '" << *i
118 << "' has incorrect format.";
119 }
120 LOG(ERROR) << "ReportCustomFlags(): '" << *i << "', uma_id=" << uma_id;
121 VLOG(1) << "ReportCustomFlags(): '" << *i << "', uma_id=" << uma_id;
122 UMA_HISTOGRAM_SPARSE_SLOWLY("Login.CustomFlags", uma_id);
123 }
124 }
125
126 } // anonymous namespace
Lei Zhang 2014/06/26 20:03:14 just // namespace
Alexander Alekseev 2014/06/27 19:28:37 Done.
127
93 class LoginUtilsImpl 128 class LoginUtilsImpl
94 : public LoginUtils, 129 : public LoginUtils,
95 public base::SupportsWeakPtr<LoginUtilsImpl>, 130 public base::SupportsWeakPtr<LoginUtilsImpl>,
96 public SessionManager::Delegate { 131 public SessionManager::Delegate {
97 public: 132 public:
98 LoginUtilsImpl() 133 LoginUtilsImpl()
99 : delegate_(NULL) { 134 : delegate_(NULL) {
100 } 135 }
101 136
102 virtual ~LoginUtilsImpl() { 137 virtual ~LoginUtilsImpl() {
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 LoginDisplayHost* login_host) { 244 LoginDisplayHost* login_host) {
210 if (!UserManager::Get()->GetCurrentUserFlow()->ShouldLaunchBrowser()) { 245 if (!UserManager::Get()->GetCurrentUserFlow()->ShouldLaunchBrowser()) {
211 UserManager::Get()->GetCurrentUserFlow()->LaunchExtraSteps(profile); 246 UserManager::Get()->GetCurrentUserFlow()->LaunchExtraSteps(profile);
212 return; 247 return;
213 } 248 }
214 249
215 CommandLine user_flags(CommandLine::NO_PROGRAM); 250 CommandLine user_flags(CommandLine::NO_PROGRAM);
216 about_flags::PrefServiceFlagsStorage flags_storage_(profile->GetPrefs()); 251 about_flags::PrefServiceFlagsStorage flags_storage_(profile->GetPrefs());
217 about_flags::ConvertFlagsToSwitches(&flags_storage_, &user_flags, 252 about_flags::ConvertFlagsToSwitches(&flags_storage_, &user_flags,
218 about_flags::kAddSentinels); 253 about_flags::kAddSentinels);
254
255 // about_flags::AreSwitchesIdenticalToCurrentCommandLine() requires
Lei Zhang 2014/06/26 20:03:14 You're in CrOS-only code, you don't need this comm
Alexander Alekseev 2014/06/27 19:28:37 Done.
256 // output argument to be std::set<CommandLine::StringType>* .
257 // To report the difference, we need std::set<std::string> .
258 // So here we are silently using the fact, that CommandLine::StringType
259 // is std::string on ChromeOS. Otherwise we would have to decode strings here.
260 std::set<std::string> command_line_difference;
261
219 // Only restart if needed and if not going into managed mode. 262 // Only restart if needed and if not going into managed mode.
220 // Don't restart browser if it is not first profile in session. 263 // Don't restart browser if it is not first profile in session.
221 if (UserManager::Get()->GetLoggedInUsers().size() == 1 && 264 if (UserManager::Get()->GetLoggedInUsers().size() == 1 &&
222 !UserManager::Get()->IsLoggedInAsLocallyManagedUser() && 265 !UserManager::Get()->IsLoggedInAsLocallyManagedUser() &&
223 !about_flags::AreSwitchesIdenticalToCurrentCommandLine( 266 !about_flags::AreSwitchesIdenticalToCurrentCommandLine(
224 user_flags, *CommandLine::ForCurrentProcess())) { 267 user_flags,
268 *CommandLine::ForCurrentProcess(),
269 &command_line_difference)) {
225 CommandLine::StringVector flags; 270 CommandLine::StringVector flags;
226 // argv[0] is the program name |CommandLine::NO_PROGRAM|. 271 // argv[0] is the program name |CommandLine::NO_PROGRAM|.
227 flags.assign(user_flags.argv().begin() + 1, user_flags.argv().end()); 272 flags.assign(user_flags.argv().begin() + 1, user_flags.argv().end());
228 VLOG(1) << "Restarting to apply per-session flags..."; 273 VLOG(1) << "Restarting to apply per-session flags...";
274
275 ReportCustomFlags(command_line_difference);
276
229 DBusThreadManager::Get()->GetSessionManagerClient()->SetFlagsForUser( 277 DBusThreadManager::Get()->GetSessionManagerClient()->SetFlagsForUser(
230 UserManager::Get()->GetActiveUser()->email(), flags); 278 UserManager::Get()->GetActiveUser()->email(), flags);
231 AttemptRestart(profile); 279 AttemptRestart(profile);
232 return; 280 return;
233 } 281 }
234 282
235 if (login_host) { 283 if (login_host) {
236 login_host->SetStatusAreaVisible(true); 284 login_host->SetStatusAreaVisible(true);
237 login_host->BeforeSessionStart(); 285 login_host->BeforeSessionStart();
238 } 286 }
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 CrosSettings* cros_settings = CrosSettings::Get(); 448 CrosSettings* cros_settings = CrosSettings::Get();
401 bool allow_new_user = false; 449 bool allow_new_user = false;
402 cros_settings->GetBoolean(kAccountsPrefAllowNewUser, &allow_new_user); 450 cros_settings->GetBoolean(kAccountsPrefAllowNewUser, &allow_new_user);
403 if (allow_new_user) 451 if (allow_new_user)
404 return true; 452 return true;
405 return cros_settings->FindEmailInList( 453 return cros_settings->FindEmailInList(
406 kAccountsPrefUsers, username, wildcard_match); 454 kAccountsPrefUsers, username, wildcard_match);
407 } 455 }
408 456
409 } // namespace chromeos 457 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698