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

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

Issue 12662033: Show user data dialog earlier on Windows. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add a browser test as suggested by Scott. Created 7 years, 9 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 | Annotate | Revision Log
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 #if defined(TOOLKIT_GTK) 7 #if defined(TOOLKIT_GTK)
8 #include <gtk/gtk.h> 8 #include <gtk/gtk.h>
9 #endif 9 #endif
10 10
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 347
348 // If we are showing the app list then chrome isn't shown so load the app 348 // If we are showing the app list then chrome isn't shown so load the app
349 // list's profile rather than chrome's. 349 // list's profile rather than chrome's.
350 if (command_line.HasSwitch(switches::kShowAppList)) 350 if (command_line.HasSwitch(switches::kShowAppList))
351 return AppListService::Get()->GetAppListProfilePath(user_data_dir); 351 return AppListService::Get()->GetAppListProfilePath(user_data_dir);
352 352
353 return g_browser_process->profile_manager()->GetLastUsedProfileDir( 353 return g_browser_process->profile_manager()->GetLastUsedProfileDir(
354 user_data_dir); 354 user_data_dir);
355 } 355 }
356 356
357 // Returns the user data dir. Must be called prior to InitializeLocalState().
358 base::FilePath GetUserDataDir(const content::MainFunctionParams& parameters) {
sky 2013/03/22 23:14:27 Move all of this into it its own file, maybe named
hshi1 2013/03/22 23:51:04 Done.
359 base::FilePath user_data_dir;
360 #if defined(OS_WIN)
361 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
362
363 // On Windows, if we fail to get the user data dir, bring up a dialog to
364 // prompt the user to pick a different directory, and restart chrome with
365 // the new dir.
366 // http://code.google.com/p/chromium/issues/detail?id=11510
367 if (!file_util::PathExists(user_data_dir)) {
368 #if defined(USE_AURA)
369 // TODO(beng):
370 NOTIMPLEMENTED();
371 #else
372 base::FilePath new_user_data_dir =
373 chrome::ShowUserDataDirDialog(user_data_dir);
374
375 if (!new_user_data_dir.empty()) {
376 // Because of the way CommandLine parses, it's sufficient to append a new
377 // --user-data-dir switch. The last flag of the same name wins.
378 // TODO(tc): It would be nice to remove the flag we don't want, but that
379 // sounds risky if we parse differently than CommandLineToArgvW.
380 CommandLine new_command_line = parameters.command_line;
381 new_command_line.AppendSwitchPath(switches::kUserDataDir,
382 new_user_data_dir);
383 base::LaunchProcess(new_command_line, base::LaunchOptions(), NULL);
384 }
385 #endif
386 NOTREACHED() << "Failed to get user data directory!";
387 }
388 #else
389 // Getting the user data dir can fail if the directory isn't
390 // creatable, for example; on Windows in code above we bring up a
391 // dialog prompting the user to pick a different directory.
392 // However, ProcessSingleton needs a real user_data_dir on Mac/Linux,
393 // so it's better to fail here than fail mysteriously elsewhere.
394 CHECK(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir))
395 << "Must be able to get user data directory!";
396 #endif
397 return user_data_dir;
398 }
399
357 // Initializes the profile, possibly doing some user prompting to pick a 400 // Initializes the profile, possibly doing some user prompting to pick a
358 // fallback profile. Returns the newly created profile, or NULL if startup 401 // fallback profile. Returns the newly created profile, or NULL if startup
359 // should not continue. 402 // should not continue.
360 Profile* CreateProfile(const content::MainFunctionParams& parameters, 403 Profile* CreateProfile(const content::MainFunctionParams& parameters,
361 const base::FilePath& user_data_dir, 404 const base::FilePath& user_data_dir,
362 const CommandLine& parsed_command_line) { 405 const CommandLine& parsed_command_line) {
363 if (ProfileManager::IsMultipleProfilesEnabled() && 406 if (ProfileManager::IsMultipleProfilesEnabled() &&
364 parsed_command_line.HasSwitch(switches::kProfileDirectory)) { 407 parsed_command_line.HasSwitch(switches::kProfileDirectory)) {
365 g_browser_process->local_state()->SetString(prefs::kProfileLastUsed, 408 g_browser_process->local_state()->SetString(prefs::kProfileLastUsed,
366 parsed_command_line.GetSwitchValueASCII(switches::kProfileDirectory)); 409 parsed_command_line.GetSwitchValueASCII(switches::kProfileDirectory));
(...skipping 12 matching lines...) Expand all
379 user_data_dir); 422 user_data_dir);
380 #else 423 #else
381 base::FilePath profile_path = 424 base::FilePath profile_path =
382 GetStartupProfilePath(user_data_dir, parsed_command_line); 425 GetStartupProfilePath(user_data_dir, parsed_command_line);
383 profile = g_browser_process->profile_manager()->GetProfile( 426 profile = g_browser_process->profile_manager()->GetProfile(
384 profile_path); 427 profile_path);
385 #endif 428 #endif
386 if (profile) 429 if (profile)
387 return profile; 430 return profile;
388 431
389 #if defined(OS_WIN)
390 #if defined(USE_AURA)
391 // TODO(beng):
392 NOTIMPLEMENTED();
393 #else
394 // Ideally, we should be able to run w/o access to disk. For now, we
395 // prompt the user to pick a different user-data-dir and restart chrome
396 // with the new dir.
397 // http://code.google.com/p/chromium/issues/detail?id=11510
398 base::FilePath new_user_data_dir =
399 chrome::ShowUserDataDirDialog(user_data_dir);
400
401 if (!new_user_data_dir.empty()) {
402 // Because of the way CommandLine parses, it's sufficient to append a new
403 // --user-data-dir switch. The last flag of the same name wins.
404 // TODO(tc): It would be nice to remove the flag we don't want, but that
405 // sounds risky if we parse differently than CommandLineToArgvW.
406 CommandLine new_command_line = parameters.command_line;
407 new_command_line.AppendSwitchPath(switches::kUserDataDir,
408 new_user_data_dir);
409 base::LaunchProcess(new_command_line, base::LaunchOptions(), NULL);
410 }
411 #endif
412 #else
413 // TODO(port): fix this. See comments near the definition of 432 // TODO(port): fix this. See comments near the definition of
414 // user_data_dir. It is better to CHECK-fail here than it is to 433 // user_data_dir. It is better to CHECK-fail here than it is to
415 // silently exit because of missing code in the above test. 434 // silently exit because of missing code in the above test.
416 CHECK(profile) << "Cannot get default profile."; 435 CHECK(profile) << "Cannot get default profile.";
417 #endif
418 436
419 return NULL; 437 return NULL;
420 } 438 }
421 439
422 #if defined(OS_MACOSX) 440 #if defined(OS_MACOSX)
423 OSStatus KeychainCallback(SecKeychainEvent keychain_event, 441 OSStatus KeychainCallback(SecKeychainEvent keychain_event,
424 SecKeychainCallbackInfo* info, void* context) { 442 SecKeychainCallbackInfo* info, void* context) {
425 return noErr; 443 return noErr;
426 } 444 }
427 #endif 445 #endif
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
801 // These members must be initialized before returning from this function. 819 // These members must be initialized before returning from this function.
802 DCHECK(master_prefs_.get()); 820 DCHECK(master_prefs_.get());
803 #if !defined(OS_ANDROID) 821 #if !defined(OS_ANDROID)
804 DCHECK(browser_creator_.get()); 822 DCHECK(browser_creator_.get());
805 #endif 823 #endif
806 return result_code_; 824 return result_code_;
807 } 825 }
808 826
809 int ChromeBrowserMainParts::PreCreateThreadsImpl() { 827 int ChromeBrowserMainParts::PreCreateThreadsImpl() {
810 run_message_loop_ = false; 828 run_message_loop_ = false;
811 #if defined(OS_WIN) 829 user_data_dir_ = GetUserDataDir(parameters());
812 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir_);
813 #else
814 // Getting the user data dir can fail if the directory isn't
815 // creatable, for example; on Windows in code below we bring up a
816 // dialog prompting the user to pick a different directory.
817 // However, ProcessSingleton needs a real user_data_dir on Mac/Linux,
818 // so it's better to fail here than fail mysteriously elsewhere.
819 CHECK(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir_))
820 << "Must be able to get user data directory!";
821 #endif
822 830
823 // Whether this is First Run. |do_first_run_tasks_| should be prefered to this 831 // Whether this is First Run. |do_first_run_tasks_| should be prefered to this
824 // unless the desire is actually to know whether this is really First Run 832 // unless the desire is actually to know whether this is really First Run
825 // (i.e., even if --no-first-run is passed). 833 // (i.e., even if --no-first-run is passed).
826 bool is_first_run = false; 834 bool is_first_run = false;
827 // Android's first run is done in Java instead of native. 835 // Android's first run is done in Java instead of native.
828 #if !defined(OS_ANDROID) 836 #if !defined(OS_ANDROID)
829 837
830 process_singleton_.reset(new ProcessSingleton(user_data_dir_)); 838 process_singleton_.reset(new ProcessSingleton(user_data_dir_));
831 // Ensure ProcessSingleton won't process messages too early. It will be 839 // Ensure ProcessSingleton won't process messages too early. It will be
(...skipping 982 matching lines...) Expand 10 before | Expand all | Expand 10 after
1814 if (base::win::GetVersion() <= base::win::VERSION_XP) 1822 if (base::win::GetVersion() <= base::win::VERSION_XP)
1815 uma_name += "_XP"; 1823 uma_name += "_XP";
1816 1824
1817 uma_name += "_PreRead_"; 1825 uma_name += "_PreRead_";
1818 uma_name += pre_read_percentage; 1826 uma_name += pre_read_percentage;
1819 AddPreReadHistogramTime(uma_name.c_str(), time); 1827 AddPreReadHistogramTime(uma_name.c_str(), time);
1820 } 1828 }
1821 #endif 1829 #endif
1822 #endif 1830 #endif
1823 } 1831 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/chrome_main_browsertest.cc » ('j') | chrome/browser/ui/views/user_data_dir_dialog_view.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698