Skip to content
Snippets Groups Projects
Commit 02aae3fa authored by huanr@chromium.org's avatar huanr@chromium.org
Browse files

Add the option of importing bookmarks from file to first run.

BUG=32728
TEST=run with --import-from-file

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@42266 0039d316-1c4b-4281-b951-d872f2087c98
parent 8341583b
No related merge requests found
......@@ -495,7 +495,8 @@ int BrowserMain(const MainFunctionParams& parameters) {
parsed_command_line.HasSwitch(switches::kFirstRun);
scoped_ptr<BrowserProcessImpl> browser_process;
if (parsed_command_line.HasSwitch(switches::kImport)) {
if (parsed_command_line.HasSwitch(switches::kImport) ||
parsed_command_line.HasSwitch(switches::kImportFromFile)) {
// We use different BrowserProcess when importing so no GoogleURLTracker is
// instantiated (as it makes a URLRequest and we don't have an IO thread,
// see bug #1292702).
......@@ -817,7 +818,8 @@ int BrowserMain(const MainFunctionParams& parameters) {
// Importing other browser settings is done in a browser-like process
// that exits when this task has finished.
#if defined(OS_WIN)
if (parsed_command_line.HasSwitch(switches::kImport))
if (parsed_command_line.HasSwitch(switches::kImport) ||
parsed_command_line.HasSwitch(switches::kImportFromFile))
return FirstRun::ImportNow(profile, parsed_command_line);
#endif
......
......@@ -45,10 +45,9 @@ class FirstRun {
// Creates the quick launch shortcut to chrome for the current user. Returns
// false if it fails. It will overwrite the shortcut if it exists.
static bool CreateChromeQuickLaunchShortcut();
// Import browser items in this process. The browser and the items to
// import are encoded int the command line. This function is paired with
// FirstRun::ImportSettings(). This function might or might not show
// a visible UI depending on the cmdline parameters.
// Import bookmarks and browser items in this process. This function is
// paired with FirstRun::ImportSettings(). This function might or might not
// show a visible UI depending on the cmdline parameters.
static int ImportNow(Profile* profile, const CommandLine& cmdline);
#endif // OS_WIN
......@@ -100,6 +99,14 @@ class FirstRun {
static bool SetShowWelcomePagePref();
private:
#if defined(OS_WIN)
// Import bookmarks from an html file. The path to the file is provided in
// the command line.
static int ImportFromFile(Profile* profile, const CommandLine& cmdline);
// Import browser items in this process. The browser and the items to
// import are encoded int the command line.
static int ImportFromBrowser(Profile* profile, const CommandLine& cmdline);
#endif // OS_WIN
// This class is for scoping purposes.
DISALLOW_IMPLICIT_CONSTRUCTORS(FirstRun);
};
......
......@@ -672,7 +672,36 @@ bool FirstRun::ImportSettings(Profile* profile, int browser_type,
return (import_runner.exit_code() == ResultCodes::NORMAL_EXIT);
}
int FirstRun::ImportNow(Profile* profile, const CommandLine& cmdline) {
int FirstRun::ImportFromFile(Profile* profile, const CommandLine& cmdline) {
std::wstring file_path = cmdline.GetSwitchValue(switches::kImportFromFile);
if (file_path.empty()) {
NOTREACHED();
return false;
}
scoped_refptr<ImporterHost> importer_host = new ImporterHost();
FirstRunImportObserver observer;
importer_host->set_headless();
ProfileInfo profile_info;
profile_info.browser_type = importer::BOOKMARKS_HTML;
profile_info.source_path = file_path;
StartImportingWithUI(
NULL,
importer::FAVORITES,
importer_host,
profile_info,
profile,
&observer,
true);
observer.RunLoop();
return observer.import_result();
}
int FirstRun::ImportFromBrowser(Profile* profile,
const CommandLine& cmdline) {
std::wstring import_info = cmdline.GetSwitchValue(switches::kImport);
if (import_info.empty()) {
NOTREACHED();
......@@ -707,6 +736,19 @@ int FirstRun::ImportNow(Profile* profile, const CommandLine& cmdline) {
return observer.import_result();
}
int FirstRun::ImportNow(Profile* profile, const CommandLine& cmdline) {
int return_code = true;
if (cmdline.HasSwitch(switches::kImportFromFile)) {
// Silently import preset bookmarks from file.
// This is an OEM scenario.
return_code = ImportFromFile(profile, cmdline);
}
if (cmdline.HasSwitch(switches::kImport)) {
return_code = ImportFromBrowser(profile, cmdline);
}
return return_code;
}
//////////////////////////////////////////////////////////////////////////
namespace {
......
......@@ -398,6 +398,10 @@ const char kHostResolverRules[] = "host-resolver-rules";
// setting encodes the target browser and what items to import.
const char kImport[] = "import";
// Perform bookmark importing from an HTML file. The value associated with this
// setting encodes the file path. It may be used jointly with kImport.
const char kImportFromFile[] = "import-from-file";
// Runs plugins inside the renderer process
const char kInProcessPlugins[] = "in-process-plugins";
......
......@@ -120,6 +120,7 @@ extern const char kHideIcons[];
extern const char kHomePage[];
extern const char kHostResolverRules[];
extern const char kImport[];
extern const char kImportFromFile[];
extern const char kInProcessPlugins[];
extern const char kIncognito[];
extern const char kInternalNaCl[];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment