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

Side by Side Diff: chrome/browser/chrome_browser_main.cc

Issue 895933005: Cleanup: Only do a Local State file lookup when needed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/chrome_browser_main.h" 5 #include "chrome/browser/chrome_browser_main.h"
6 6
7 #include <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 } 242 }
243 } 243 }
244 #endif // !defined(OS_ANDROID) && !defined(OS_CHROMEOS) 244 #endif // !defined(OS_ANDROID) && !defined(OS_CHROMEOS)
245 245
246 // Returns the new local state object, guaranteed non-NULL. 246 // Returns the new local state object, guaranteed non-NULL.
247 // |local_state_task_runner| must be a shutdown-blocking task runner. 247 // |local_state_task_runner| must be a shutdown-blocking task runner.
248 PrefService* InitializeLocalState( 248 PrefService* InitializeLocalState(
249 base::SequencedTaskRunner* local_state_task_runner, 249 base::SequencedTaskRunner* local_state_task_runner,
250 const base::CommandLine& parsed_command_line) { 250 const base::CommandLine& parsed_command_line) {
251 TRACE_EVENT0("startup", "ChromeBrowserMainParts::InitializeLocalState") 251 TRACE_EVENT0("startup", "ChromeBrowserMainParts::InitializeLocalState")
252 base::FilePath local_state_path;
253 PathService::Get(chrome::FILE_LOCAL_STATE, &local_state_path);
254 bool local_state_file_exists = base::PathExists(local_state_path);
255 252
256 // Load local state. This includes the application locale so we know which 253 // Load local state. This includes the application locale so we know which
257 // locale dll to load. This also causes local state prefs to be registered. 254 // locale dll to load. This also causes local state prefs to be registered.
258 PrefService* local_state = g_browser_process->local_state(); 255 PrefService* local_state = g_browser_process->local_state();
259 DCHECK(local_state); 256 DCHECK(local_state);
260 257
261 #if defined(OS_WIN) 258 #if defined(OS_WIN)
262 if (first_run::IsChromeFirstRun()) { 259 if (first_run::IsChromeFirstRun()) {
263 // During first run we read the google_update registry key to find what 260 // During first run we read the google_update registry key to find what
264 // language the user selected when downloading the installer. This 261 // language the user selected when downloading the installer. This
(...skipping 13 matching lines...) Expand all
278 // Checking that the local state file for the current profile doesn't exist 275 // Checking that the local state file for the current profile doesn't exist
279 // is the most robust way to determine whether we need to inherit or not 276 // is the most robust way to determine whether we need to inherit or not
280 // since the parent profile command line flag can be present even when the 277 // since the parent profile command line flag can be present even when the
281 // current profile is not a new one, and in that case we do not want to 278 // current profile is not a new one, and in that case we do not want to
282 // inherit and reset the user's setting. 279 // inherit and reset the user's setting.
283 // 280 //
284 // TODO(mnissler): We should probably just instantiate a 281 // TODO(mnissler): We should probably just instantiate a
285 // JSONPrefStore here instead of an entire PrefService. Once this is 282 // JSONPrefStore here instead of an entire PrefService. Once this is
286 // addressed, the call to browser_prefs::RegisterLocalState can move 283 // addressed, the call to browser_prefs::RegisterLocalState can move
287 // to chrome_prefs::CreateLocalState. 284 // to chrome_prefs::CreateLocalState.
288 if (!local_state_file_exists && 285 if (parsed_command_line.HasSwitch(switches::kParentProfile)) {
289 parsed_command_line.HasSwitch(switches::kParentProfile)) { 286 base::FilePath local_state_path;
290 base::FilePath parent_profile = 287 PathService::Get(chrome::FILE_LOCAL_STATE, &local_state_path);
291 parsed_command_line.GetSwitchValuePath(switches::kParentProfile); 288 bool local_state_file_exists = base::PathExists(local_state_path);
292 scoped_refptr<PrefRegistrySimple> registry = new PrefRegistrySimple(); 289 if (!local_state_file_exists) {
293 scoped_ptr<PrefService> parent_local_state( 290 base::FilePath parent_profile =
294 chrome_prefs::CreateLocalState( 291 parsed_command_line.GetSwitchValuePath(switches::kParentProfile);
295 parent_profile, 292 scoped_refptr<PrefRegistrySimple> registry = new PrefRegistrySimple();
296 local_state_task_runner, 293 scoped_ptr<PrefService> parent_local_state(
297 g_browser_process->policy_service(), 294 chrome_prefs::CreateLocalState(
298 registry, 295 parent_profile,
299 false)); 296 local_state_task_runner,
300 registry->RegisterStringPref(prefs::kApplicationLocale, std::string()); 297 g_browser_process->policy_service(),
301 // Right now, we only inherit the locale setting from the parent profile. 298 registry,
302 local_state->SetString( 299 false));
303 prefs::kApplicationLocale, 300 registry->RegisterStringPref(prefs::kApplicationLocale, std::string());
304 parent_local_state->GetString(prefs::kApplicationLocale)); 301 // Right now, we only inherit the locale setting from the parent profile.
302 local_state->SetString(
303 prefs::kApplicationLocale,
304 parent_local_state->GetString(prefs::kApplicationLocale));
305 }
305 } 306 }
306 307
307 #if defined(OS_CHROMEOS) 308 #if defined(OS_CHROMEOS)
308 if (parsed_command_line.HasSwitch(chromeos::switches::kLoginManager)) { 309 if (parsed_command_line.HasSwitch(chromeos::switches::kLoginManager)) {
309 std::string owner_locale = local_state->GetString(prefs::kOwnerLocale); 310 std::string owner_locale = local_state->GetString(prefs::kOwnerLocale);
310 // Ensure that we start with owner's locale. 311 // Ensure that we start with owner's locale.
311 if (!owner_locale.empty() && 312 if (!owner_locale.empty() &&
312 local_state->GetString(prefs::kApplicationLocale) != owner_locale && 313 local_state->GetString(prefs::kApplicationLocale) != owner_locale &&
313 !local_state->IsManagedPreference(prefs::kApplicationLocale)) { 314 !local_state->IsManagedPreference(prefs::kApplicationLocale)) {
314 local_state->SetString(prefs::kApplicationLocale, owner_locale); 315 local_state->SetString(prefs::kApplicationLocale, owner_locale);
(...skipping 1393 matching lines...) Expand 10 before | Expand all | Expand 10 after
1708 chromeos::CrosSettings::Shutdown(); 1709 chromeos::CrosSettings::Shutdown();
1709 #endif 1710 #endif
1710 #endif 1711 #endif
1711 } 1712 }
1712 1713
1713 // Public members: 1714 // Public members:
1714 1715
1715 void ChromeBrowserMainParts::AddParts(ChromeBrowserMainExtraParts* parts) { 1716 void ChromeBrowserMainParts::AddParts(ChromeBrowserMainExtraParts* parts) {
1716 chrome_extra_parts_.push_back(parts); 1717 chrome_extra_parts_.push_back(parts);
1717 } 1718 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698