Commit 37b89cac authored by sail@chromium.org's avatar sail@chromium.org

Honor profile directory when creating new window in existing browser

Using the "-profile-directory" switch didn't work if the browser was already running.

The problem was that we were ignoring the switch and just using the last used profile.

BUG=100461
TEST=Ran Chrome with the first profile open. Launched a 2nd instance with "-profile-directory" and verified that the correct profile window opened.


Review URL: http://codereview.chromium.org/8854001

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@113534 0039d316-1c4b-4281-b951-d872f2087c98
parent 28d71e39
...@@ -641,15 +641,6 @@ void ProcessSingleton::LinuxWatcher::HandleMessage( ...@@ -641,15 +641,6 @@ void ProcessSingleton::LinuxWatcher::HandleMessage(
PrefService* prefs = g_browser_process->local_state(); PrefService* prefs = g_browser_process->local_state();
DCHECK(prefs); DCHECK(prefs);
Profile* profile = ProfileManager::GetLastUsedProfile();
if (!profile) {
// We should only be able to get here if the profile already exists and
// has been created.
NOTREACHED();
return;
}
// Ignore the request if the process was passed the --product-version flag. // Ignore the request if the process was passed the --product-version flag.
// Normally we wouldn't get here if that flag had been passed, but it can // Normally we wouldn't get here if that flag had been passed, but it can
// happen if it is passed to an older version of chrome. Since newer versions // happen if it is passed to an older version of chrome. Since newer versions
...@@ -661,10 +652,8 @@ void ProcessSingleton::LinuxWatcher::HandleMessage( ...@@ -661,10 +652,8 @@ void ProcessSingleton::LinuxWatcher::HandleMessage(
} else { } else {
// Run the browser startup sequence again, with the command line of the // Run the browser startup sequence again, with the command line of the
// signalling process. // signalling process.
FilePath current_dir_file_path(current_dir); BrowserInit::ProcessCommandLineAlreadyRunning(
BrowserInit::ProcessCommandLine(parsed_command_line, current_dir_file_path, parsed_command_line, FilePath(current_dir));
false /* not process startup */, profile,
NULL);
} }
// Send back "ACK" message to prevent the client process from starting up. // Send back "ACK" message to prevent the client process from starting up.
......
...@@ -311,18 +311,22 @@ LRESULT ProcessSingleton::OnCopyData(HWND hwnd, const COPYDATASTRUCT* cds) { ...@@ -311,18 +311,22 @@ LRESULT ProcessSingleton::OnCopyData(HWND hwnd, const COPYDATASTRUCT* cds) {
PrefService* prefs = g_browser_process->local_state(); PrefService* prefs = g_browser_process->local_state();
DCHECK(prefs); DCHECK(prefs);
Profile* profile = ProfileManager::GetLastUsedProfile();
if (!profile) {
// We should only be able to get here if the profile already exists and
// has been created.
NOTREACHED();
return TRUE;
}
// Handle the --uninstall-extension startup action. This needs to done here // Handle the --uninstall-extension startup action. This needs to done here
// in the process that is running with the target profile, otherwise the // in the process that is running with the target profile, otherwise the
// uninstall will fail to unload and remove all components. // uninstall will fail to unload and remove all components.
if (parsed_command_line.HasSwitch(switches::kUninstallExtension)) { if (parsed_command_line.HasSwitch(switches::kUninstallExtension)) {
// The uninstall extension switch can't be combined with the profile
// directory switch.
DCHECK(!parsed_command_line.HasSwitch(switches::kProfileDirectory));
Profile* profile = ProfileManager::GetLastUsedProfile();
if (!profile) {
// We should only be able to get here if the profile already exists and
// has been created.
NOTREACHED();
return TRUE;
}
ExtensionsStartupUtil ext_startup_util; ExtensionsStartupUtil ext_startup_util;
ext_startup_util.UninstallExtension(parsed_command_line, profile); ext_startup_util.UninstallExtension(parsed_command_line, profile);
return TRUE; return TRUE;
...@@ -330,8 +334,7 @@ LRESULT ProcessSingleton::OnCopyData(HWND hwnd, const COPYDATASTRUCT* cds) { ...@@ -330,8 +334,7 @@ LRESULT ProcessSingleton::OnCopyData(HWND hwnd, const COPYDATASTRUCT* cds) {
// Run the browser startup sequence again, with the command line of the // Run the browser startup sequence again, with the command line of the
// signalling process. // signalling process.
BrowserInit::ProcessCommandLine(parsed_command_line, cur_dir, false, BrowserInit::ProcessCommandLineAlreadyRunning(parsed_command_line, cur_dir);
profile, NULL);
return TRUE; return TRUE;
} }
return TRUE; return TRUE;
......
...@@ -47,6 +47,7 @@ ...@@ -47,6 +47,7 @@
#include "chrome/browser/printing/print_dialog_cloud.h" #include "chrome/browser/printing/print_dialog_cloud.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_io_data.h" #include "chrome/browser/profiles/profile_io_data.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/search_engines/template_url.h" #include "chrome/browser/search_engines/template_url.h"
#include "chrome/browser/search_engines/template_url_service.h" #include "chrome/browser/search_engines/template_url_service.h"
#include "chrome/browser/search_engines/template_url_service_factory.h" #include "chrome/browser/search_engines/template_url_service_factory.h"
...@@ -1497,3 +1498,36 @@ bool BrowserInit::CreateAutomationProvider(const std::string& channel_id, ...@@ -1497,3 +1498,36 @@ bool BrowserInit::CreateAutomationProvider(const std::string& channel_id,
return true; return true;
} }
// static
void BrowserInit::ProcessCommandLineOnProfileCreated(
const CommandLine& cmd_line,
const FilePath& cur_dir,
Profile* profile,
Profile::CreateStatus status) {
if (status == Profile::CREATE_STATUS_INITIALIZED)
ProcessCmdLineImpl(cmd_line, cur_dir, false, profile, NULL, NULL);
}
// static
void BrowserInit::ProcessCommandLineAlreadyRunning(const CommandLine& cmd_line,
const FilePath& cur_dir) {
if (cmd_line.HasSwitch(switches::kProfileDirectory)) {
ProfileManager* profile_manager = g_browser_process->profile_manager();
FilePath path = cmd_line.GetSwitchValuePath(switches::kProfileDirectory);
path = profile_manager->user_data_dir().Append(path);
profile_manager->CreateProfileAsync(path,
base::Bind(&BrowserInit::ProcessCommandLineOnProfileCreated,
cmd_line, cur_dir));
return;
}
Profile* profile = ProfileManager::GetLastUsedProfile();
if (!profile) {
// We should only be able to get here if the profile already exists and
// has been created.
NOTREACHED();
return;
}
ProcessCmdLineImpl(cmd_line, cur_dir, false, profile, NULL, NULL);
}
...@@ -12,12 +12,12 @@ ...@@ -12,12 +12,12 @@
#include "base/basictypes.h" #include "base/basictypes.h"
#include "base/file_path.h" #include "base/file_path.h"
#include "base/gtest_prod_util.h" #include "base/gtest_prod_util.h"
#include "chrome/browser/profiles/profile.h"
#include "googleurl/src/gurl.h" #include "googleurl/src/gurl.h"
class Browser; class Browser;
class CommandLine; class CommandLine;
class GURL; class GURL;
class Profile;
class TabContentsWrapper; class TabContentsWrapper;
// class containing helpers for BrowserMain to spin up a new instance and // class containing helpers for BrowserMain to spin up a new instance and
...@@ -48,18 +48,11 @@ class BrowserInit { ...@@ -48,18 +48,11 @@ class BrowserInit {
this); this);
} }
// This function performs command-line handling and is invoked when process // This function performs command-line handling and is invoked only after
// starts as well as when we get a start request from another process (via the // start up (for example when we get a start request for another process).
// WM_COPYDATA message). |command_line| holds the command line we need to // |command_line| holds the command line we need to process
// process - either from this process or from some other one (if static void ProcessCommandLineAlreadyRunning(const CommandLine& cmd_line,
// |process_startup| is true and we are being called from const FilePath& cur_dir);
// ProcessSingleton::OnCopyData).
static bool ProcessCommandLine(const CommandLine& cmd_line,
const FilePath& cur_dir, bool process_startup,
Profile* profile, int* return_code) {
return ProcessCmdLineImpl(cmd_line, cur_dir, process_startup, profile,
return_code, NULL);
}
template <class AutomationProviderClass> template <class AutomationProviderClass>
static bool CreateAutomationProvider(const std::string& channel_id, static bool CreateAutomationProvider(const std::string& channel_id,
...@@ -247,6 +240,13 @@ class BrowserInit { ...@@ -247,6 +240,13 @@ class BrowserInit {
Profile* profile, int* return_code, Profile* profile, int* return_code,
BrowserInit* browser_init); BrowserInit* browser_init);
// Callback after a profile has been created.
static void ProcessCommandLineOnProfileCreated(
const CommandLine& cmd_line,
const FilePath& cur_dir,
Profile* profile,
Profile::CreateStatus status);
// Additional tabs to open during first run. // Additional tabs to open during first run.
std::vector<GURL> first_run_tabs_; std::vector<GURL> first_run_tabs_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment