diff options
author | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-07 22:55:30 +0000 |
---|---|---|
committer | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-07 22:55:30 +0000 |
commit | 111ca63cacf4cedb65be41fd4cabfa5ad7bb6b86 (patch) | |
tree | 19bfebe83f96b4db5b78bb86f989667a11d04554 /chrome/browser/automation | |
parent | e8d82c6124232e1678eb242e5c7369bd20ac949d (diff) | |
download | chromium_src-111ca63cacf4cedb65be41fd4cabfa5ad7bb6b86.zip chromium_src-111ca63cacf4cedb65be41fd4cabfa5ad7bb6b86.tar.gz chromium_src-111ca63cacf4cedb65be41fd4cabfa5ad7bb6b86.tar.bz2 |
Importer: Fix ImporterList::DetectSourceProfiles to run on the FILE thread, as
it access the file system. Fix up a few call sites.
BUG=60825
TEST=none
Review URL: http://codereview.chromium.org/5566003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@68533 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/automation')
-rw-r--r-- | chrome/browser/automation/testing_automation_provider.cc | 95 | ||||
-rw-r--r-- | chrome/browser/automation/testing_automation_provider.h | 34 |
2 files changed, 82 insertions, 47 deletions
diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc index 6b13f28..9098cf6 100644 --- a/chrome/browser/automation/testing_automation_provider.cc +++ b/chrome/browser/automation/testing_automation_provider.cc @@ -39,6 +39,7 @@ #include "chrome/browser/extensions/extension_host.h" #include "chrome/browser/extensions/extensions_service.h" #include "chrome/browser/history/top_sites.h" +#include "chrome/browser/importer/importer.h" #include "chrome/browser/notifications/balloon.h" #include "chrome/browser/notifications/balloon_collection.h" #include "chrome/browser/notifications/balloon_host.h" @@ -242,6 +243,49 @@ TestingAutomationProvider::~TestingAutomationProvider() { BrowserList::RemoveObserver(this); } +void TestingAutomationProvider::SourceProfilesLoaded() { + DCHECK_NE(static_cast<ImporterHost*>(NULL), importer_host_.get()); + + // Get the correct ProfileInfo based on the browser the user provided. + importer::ProfileInfo profile_info; + int num_browsers = importer_host_->GetAvailableProfileCount(); + int i = 0; + for ( ; i < num_browsers; i++) { + string16 name = WideToUTF16Hack(importer_host_->GetSourceProfileNameAt(i)); + if (name == import_settings_data_.browser_name) { + profile_info = importer_host_->GetSourceProfileInfoAt(i); + break; + } + } + // If we made it to the end of the loop, then the input was bad. + if (i == num_browsers) { + AutomationJSONReply(this, import_settings_data_.reply_message).SendError( + "Invalid browser name string found."); + return; + } + + importer_host_->SetObserver( + new AutomationProviderImportSettingsObserver( + this, import_settings_data_.reply_message)); + + Profile* profile = import_settings_data_.browser->profile(); + importer_host_->StartImportSettings(profile_info, + profile, + import_settings_data_.import_items, + new ProfileWriter(profile), + import_settings_data_.first_run); +} + +void TestingAutomationProvider::Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details) { + DCHECK(type == NotificationType::SESSION_END); + // OnBrowserRemoved does a ReleaseLater. When session end is received we exit + // before the task runs resulting in this object not being deleted. This + // Release balance out the Release scheduled by OnBrowserRemoved. + Release(); +} + void TestingAutomationProvider::OnMessageReceived( const IPC::Message& message) { IPC_BEGIN_MESSAGE_MAP(TestingAutomationProvider, message) @@ -3149,19 +3193,16 @@ void TestingAutomationProvider::ImportSettings(Browser* browser, string_to_import_item["HOME_PAGE"] = importer::HOME_PAGE; string_to_import_item["ALL"] = importer::ALL; - string16 browser_name; - int import_items = 0; ListValue* import_items_list = NULL; - bool first_run; - - if (!args->GetString("import_from", &browser_name) || - !args->GetBoolean("first_run", &first_run) || + if (!args->GetString("import_from", &import_settings_data_.browser_name) || + !args->GetBoolean("first_run", &import_settings_data_.first_run) || !args->GetList("import_items", &import_items_list)) { AutomationJSONReply(this, reply_message).SendError( "Incorrect type for one or more of the arguments."); return; } + import_settings_data_.import_items = 0; int num_items = import_items_list->GetSize(); for (int i = 0; i < num_items; i++) { std::string item; @@ -3172,34 +3213,16 @@ void TestingAutomationProvider::ImportSettings(Browser* browser, "Invalid item string found in import_items."); return; } - import_items |= string_to_import_item[item]; + import_settings_data_.import_items |= string_to_import_item[item]; } - ImporterHost* importer_host = new ImporterHost(); - // Get the correct ProfileInfo based on the browser they user provided. - importer::ProfileInfo profile_info; - int num_browsers = importer_host->GetAvailableProfileCount(); - int i = 0; - for ( ; i < num_browsers; i++) { - string16 name = WideToUTF16Hack(importer_host->GetSourceProfileNameAt(i)); - if (name == browser_name) { - profile_info = importer_host->GetSourceProfileInfoAt(i); - break; - } - } - // If we made it to the end of the loop, then the input was bad. - if (i == num_browsers) { - AutomationJSONReply(this, reply_message).SendError( - "Invalid browser name string found."); - return; - } + import_settings_data_.browser = browser; + import_settings_data_.reply_message = reply_message; - Profile* profile = browser->profile(); - - importer_host->SetObserver( - new AutomationProviderImportSettingsObserver(this, reply_message)); - importer_host->StartImportSettings(profile_info, profile, import_items, - new ProfileWriter(profile), first_run); + // The remaining functionality of importing settings is in + // SourceProfilesLoaded(), which is called by |importer_host_| once the source + // profiles are loaded. + importer_host_ = new ImporterHost(this); } namespace { @@ -4562,16 +4585,6 @@ void TestingAutomationProvider::OnBrowserRemoved(const Browser* browser) { } } -void TestingAutomationProvider::Observe(NotificationType type, - const NotificationSource& source, - const NotificationDetails& details) { - DCHECK(type == NotificationType::SESSION_END); - // OnBrowserRemoved does a ReleaseLater. When session end is received we exit - // before the task runs resulting in this object not being deleted. This - // Release balance out the Release scheduled by OnBrowserRemoved. - Release(); -} - void TestingAutomationProvider::OnRemoveProvider() { AutomationProviderList::GetInstance()->RemoveProvider(this); } diff --git a/chrome/browser/automation/testing_automation_provider.h b/chrome/browser/automation/testing_automation_provider.h index ac3ad58..b1af561 100644 --- a/chrome/browser/automation/testing_automation_provider.h +++ b/chrome/browser/automation/testing_automation_provider.h @@ -11,33 +11,53 @@ #include "chrome/browser/automation/automation_provider.h" #include "chrome/browser/browser_list.h" #include "chrome/browser/history/history.h" +#include "chrome/browser/importer/importer_list.h" #include "chrome/browser/sync/profile_sync_service_harness.h" #include "chrome/common/notification_registrar.h" #include "chrome/common/page_type.h" class DictionaryValue; +class ImporterHost; class TemplateURLModel; // This is an automation provider containing testing calls. class TestingAutomationProvider : public AutomationProvider, public BrowserList::Observer, + public ImporterList::Observer, public NotificationObserver { public: explicit TestingAutomationProvider(Profile* profile); - // BrowserList::Observer implementation + // BrowserList::Observer implementation. virtual void OnBrowserAdded(const Browser* browser); virtual void OnBrowserRemoved(const Browser* browser); - // IPC implementations + // IPC::Channel::Listener implementation. virtual void OnMessageReceived(const IPC::Message& msg); virtual void OnChannelError(); private: class PopupMenuWaiter; + // Storage for ImportSettings() to resume operations after a callback. + struct ImportSettingsData { + string16 browser_name; + int import_items; + bool first_run; + Browser* browser; + IPC::Message* reply_message; + }; + virtual ~TestingAutomationProvider(); + // ImporterList::Observer implementation. + virtual void SourceProfilesLoaded(); + + // NotificationObserver implementation. + virtual void Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details); + // IPC Message callbacks. void CloseBrowser(int handle, IPC::Message* reply_message); void CloseBrowserAsync(int browser_handle); @@ -756,10 +776,6 @@ class TestingAutomationProvider : public AutomationProvider, bool success, history::RedirectList* redirects); - virtual void Observe(NotificationType type, - const NotificationSource& source, - const NotificationDetails& details); - void OnRemoveProvider(); // Called via PostTask #if defined(TOOLKIT_VIEWS) @@ -782,6 +798,12 @@ class TestingAutomationProvider : public AutomationProvider, NotificationRegistrar registrar_; + // Used to import settings from browser profiles. + scoped_refptr<ImporterHost> importer_host_; + + // The stored data for the ImportSettings operation. + ImportSettingsData import_settings_data_; + DISALLOW_COPY_AND_ASSIGN(TestingAutomationProvider); }; |