diff options
author | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-20 18:27:33 +0000 |
---|---|---|
committer | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-20 18:27:33 +0000 |
commit | 734fc97bcd0d885de8739c4d611cedf0e2f4ec4c (patch) | |
tree | d5651ea1a3bbd85d11c828598ca91f96f7b90e57 | |
parent | 804ab2fb72ea94d6d9beaac75ecae6bc6a6b8611 (diff) | |
download | chromium_src-734fc97bcd0d885de8739c4d611cedf0e2f4ec4c.zip chromium_src-734fc97bcd0d885de8739c4d611cedf0e2f4ec4c.tar.gz chromium_src-734fc97bcd0d885de8739c4d611cedf0e2f4ec4c.tar.bz2 |
importer: Move ExternalProcessImporterBridge to its own header file.
BUG=None
TEST=None
R=avi@chromium.org
Review URL: http://codereview.chromium.org/6714038
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@78855 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/importer/external_process_importer_bridge.cc | 97 | ||||
-rw-r--r-- | chrome/browser/importer/external_process_importer_bridge.h | 74 | ||||
-rw-r--r-- | chrome/browser/importer/importer_bridge.cc | 93 | ||||
-rw-r--r-- | chrome/browser/importer/importer_bridge.h | 64 | ||||
-rw-r--r-- | chrome/chrome_browser.gypi | 2 | ||||
-rw-r--r-- | chrome/profile_import/profile_import_thread.cc | 3 |
6 files changed, 179 insertions, 154 deletions
diff --git a/chrome/browser/importer/external_process_importer_bridge.cc b/chrome/browser/importer/external_process_importer_bridge.cc new file mode 100644 index 0000000..6b324d9 --- /dev/null +++ b/chrome/browser/importer/external_process_importer_bridge.cc @@ -0,0 +1,97 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/importer/external_process_importer_bridge.h" + +#include "base/logging.h" +#include "base/string_number_conversions.h" +#include "base/utf_string_conversions.h" +#include "base/values.h" +#include "chrome/browser/history/history_types.h" +#include "chrome/profile_import/profile_import_thread.h" +#include "webkit/glue/password_form.h" + +#if defined(OS_WIN) +#include "chrome/browser/password_manager/ie7_password.h" +#endif + +ExternalProcessImporterBridge::ExternalProcessImporterBridge( + ProfileImportThread* profile_import_thread, + const DictionaryValue& localized_strings) + : profile_import_thread_(profile_import_thread) { + // Bridge needs to make its own copy because OS 10.6 autoreleases the + // localized_strings value that is passed in (see http://crbug.com/46003 ). + localized_strings_.reset(localized_strings.DeepCopy()); +} + +void ExternalProcessImporterBridge::AddBookmarkEntries( + const std::vector<ProfileWriter::BookmarkEntry>& bookmarks, + const std::wstring& first_folder_name, + int options) { + profile_import_thread_->NotifyBookmarksImportReady( + bookmarks, first_folder_name, options); +} + +void ExternalProcessImporterBridge::AddHomePage(const GURL &home_page) { + // TODO(mirandac): remove home page import from code base. + // http://crbug.com/45678 :-) + NOTIMPLEMENTED(); +} + +#if defined(OS_WIN) +void ExternalProcessImporterBridge::AddIE7PasswordInfo( + const IE7PasswordInfo password_info) { + NOTIMPLEMENTED(); +} +#endif + +void ExternalProcessImporterBridge::SetFavicons( + const std::vector<history::ImportedFaviconUsage>& favicons) { + profile_import_thread_->NotifyFaviconsImportReady(favicons); +} + +void ExternalProcessImporterBridge::SetHistoryItems( + const std::vector<history::URLRow>& rows, + history::VisitSource visit_source) { + profile_import_thread_->NotifyHistoryImportReady(rows, visit_source); +} + +void ExternalProcessImporterBridge::SetKeywords( + const std::vector<TemplateURL*>& template_urls, + int default_keyword_index, + bool unique_on_host_and_path) { + profile_import_thread_->NotifyKeywordsReady( + template_urls, default_keyword_index, unique_on_host_and_path); +} + +void ExternalProcessImporterBridge::SetPasswordForm( + const webkit_glue::PasswordForm& form) { + profile_import_thread_->NotifyPasswordFormReady(form); +} + +void ExternalProcessImporterBridge::NotifyStarted() { + profile_import_thread_->NotifyStarted(); +} + +void ExternalProcessImporterBridge::NotifyItemStarted( + importer::ImportItem item) { + profile_import_thread_->NotifyItemStarted(item); +} + +void ExternalProcessImporterBridge::NotifyItemEnded(importer::ImportItem item) { + profile_import_thread_->NotifyItemEnded(item); +} + +void ExternalProcessImporterBridge::NotifyEnded() { + // The internal process detects import end when all items have been received. +} + +// TODO(viettrungluu): convert to string16. +std::wstring ExternalProcessImporterBridge::GetLocalizedString(int message_id) { + string16 message; + localized_strings_->GetString(base::IntToString(message_id), &message); + return UTF16ToWideHack(message); +} + +ExternalProcessImporterBridge::~ExternalProcessImporterBridge() {} diff --git a/chrome/browser/importer/external_process_importer_bridge.h b/chrome/browser/importer/external_process_importer_bridge.h new file mode 100644 index 0000000..61a48de --- /dev/null +++ b/chrome/browser/importer/external_process_importer_bridge.h @@ -0,0 +1,74 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_IMPORTER_EXTERNAL_PROCESS_IMPORTER_BRIDGE_H_ +#define CHROME_BROWSER_IMPORTER_EXTERNAL_PROCESS_IMPORTER_BRIDGE_H_ +#pragma once + +#include <string> +#include <vector> + +#include "base/basictypes.h" +#include "base/compiler_specific.h" +#include "base/scoped_ptr.h" +#include "build/build_config.h" +#include "chrome/browser/importer/importer_bridge.h" +#include "chrome/browser/importer/profile_writer.h" + +class DictionaryValue; +class GURL; +class ProfileImportThread; + +// When the importer is run in an external process, the bridge is effectively +// split in half by the IPC infrastructure. The external bridge receives data +// and notifications from the importer, and sends it across IPC. The +// internal bridge gathers the data from the IPC host and writes it to the +// profile. +class ExternalProcessImporterBridge : public ImporterBridge { + public: + ExternalProcessImporterBridge(ProfileImportThread* profile_import_thread, + const DictionaryValue& localized_strings); + + // Begin ImporterBridge implementation: + virtual void AddBookmarkEntries( + const std::vector<ProfileWriter::BookmarkEntry>& bookmarks, + const std::wstring& first_folder_name, + int options) OVERRIDE; + virtual void AddHomePage(const GURL& home_page) OVERRIDE; + +#if defined(OS_WIN) + virtual void AddIE7PasswordInfo(const IE7PasswordInfo password_info) OVERRIDE; +#endif + + virtual void SetFavicons( + const std::vector<history::ImportedFaviconUsage>& favicons) OVERRIDE; + virtual void SetHistoryItems(const std::vector<history::URLRow>& rows, + history::VisitSource visit_source) OVERRIDE; + virtual void SetKeywords(const std::vector<TemplateURL*>& template_urls, + int default_keyword_index, + bool unique_on_host_and_path) OVERRIDE; + virtual void SetPasswordForm(const webkit_glue::PasswordForm& form) OVERRIDE; + + virtual void NotifyStarted() OVERRIDE; + virtual void NotifyItemStarted(importer::ImportItem item) OVERRIDE; + virtual void NotifyItemEnded(importer::ImportItem item) OVERRIDE; + virtual void NotifyEnded() OVERRIDE; + + virtual std::wstring GetLocalizedString(int message_id) OVERRIDE; + // End ImporterBridge implementation. + + private: + virtual ~ExternalProcessImporterBridge(); + + // Call back to send data and messages across IPC. + ProfileImportThread* const profile_import_thread_; + + // Holds strings needed by the external importer because the resource + // bundle isn't available to the external process. + scoped_ptr<DictionaryValue> localized_strings_; + + DISALLOW_COPY_AND_ASSIGN(ExternalProcessImporterBridge); +}; + +#endif // CHROME_BROWSER_IMPORTER_EXTERNAL_PROCESS_IMPORTER_BRIDGE_H_ diff --git a/chrome/browser/importer/importer_bridge.cc b/chrome/browser/importer/importer_bridge.cc index 5e56885..7910c6a 100644 --- a/chrome/browser/importer/importer_bridge.cc +++ b/chrome/browser/importer/importer_bridge.cc @@ -4,99 +4,6 @@ #include "chrome/browser/importer/importer_bridge.h" -#include "base/string16.h" -#include "base/string_number_conversions.h" -#include "base/utf_string_conversions.h" -#include "base/values.h" -#include "chrome/browser/history/history_types.h" -#include "chrome/browser/importer/importer_host.h" -#include "chrome/profile_import/profile_import_thread.h" -#include "webkit/glue/password_form.h" - -#if defined(OS_WIN) -#include "chrome/browser/password_manager/ie7_password.h" -#endif - ImporterBridge::ImporterBridge() {} ImporterBridge::~ImporterBridge() {} - -ExternalProcessImporterBridge::ExternalProcessImporterBridge( - ProfileImportThread* profile_import_thread, - const DictionaryValue& localized_strings) - : profile_import_thread_(profile_import_thread) { - // Bridge needs to make its own copy because OS 10.6 autoreleases the - // localized_strings value that is passed in (see http://crbug.com/46003 ). - localized_strings_.reset(localized_strings.DeepCopy()); -} - -void ExternalProcessImporterBridge::AddBookmarkEntries( - const std::vector<ProfileWriter::BookmarkEntry>& bookmarks, - const std::wstring& first_folder_name, int options) { - profile_import_thread_->NotifyBookmarksImportReady(bookmarks, - first_folder_name, options); -} - -void ExternalProcessImporterBridge::AddHomePage(const GURL &home_page) { - // TODO(mirandac): remove home page import from code base. - // http://crbug.com/45678 :-) - NOTIMPLEMENTED(); -} - -#if defined(OS_WIN) -void ExternalProcessImporterBridge::AddIE7PasswordInfo( - const IE7PasswordInfo password_info) { - NOTIMPLEMENTED(); -} -#endif - -void ExternalProcessImporterBridge::SetFavicons( - const std::vector<history::ImportedFaviconUsage>& favicons) { - profile_import_thread_->NotifyFaviconsImportReady(favicons); -} - -void ExternalProcessImporterBridge::SetHistoryItems( - const std::vector<history::URLRow> &rows, - history::VisitSource visit_source) { - profile_import_thread_->NotifyHistoryImportReady(rows, visit_source); -} - -void ExternalProcessImporterBridge::SetKeywords( - const std::vector<TemplateURL*>& template_urls, - int default_keyword_index, - bool unique_on_host_and_path) { - profile_import_thread_->NotifyKeywordsReady(template_urls, - default_keyword_index, unique_on_host_and_path); -} - -void ExternalProcessImporterBridge::SetPasswordForm( - const webkit_glue::PasswordForm& form) { - profile_import_thread_->NotifyPasswordFormReady(form); -} - -void ExternalProcessImporterBridge::NotifyItemStarted( - importer::ImportItem item) { - profile_import_thread_->NotifyItemStarted(item); -} - -void ExternalProcessImporterBridge::NotifyItemEnded(importer::ImportItem item) { - profile_import_thread_->NotifyItemEnded(item); -} - -void ExternalProcessImporterBridge::NotifyStarted() { - profile_import_thread_->NotifyStarted(); -} - -void ExternalProcessImporterBridge::NotifyEnded() { - // The internal process detects import end when all items have been received. -} - -// TODO(viettrungluu): convert to string16. -std::wstring ExternalProcessImporterBridge::GetLocalizedString( - int message_id) { - string16 message; - localized_strings_->GetString(base::IntToString(message_id), &message); - return UTF16ToWideHack(message); -} - -ExternalProcessImporterBridge::~ExternalProcessImporterBridge() {} diff --git a/chrome/browser/importer/importer_bridge.h b/chrome/browser/importer/importer_bridge.h index 5da7f11..5a16bfd 100644 --- a/chrome/browser/importer/importer_bridge.h +++ b/chrome/browser/importer/importer_bridge.h @@ -6,19 +6,16 @@ #define CHROME_BROWSER_IMPORTER_IMPORTER_BRIDGE_H_ #pragma once +#include <string> #include <vector> #include "base/basictypes.h" #include "base/ref_counted.h" -#include "base/scoped_ptr.h" +#include "build/build_config.h" #include "chrome/browser/importer/importer_data_types.h" // TODO: remove this, see friend declaration in ImporterBridge. #include "chrome/browser/importer/toolbar_importer.h" -class ProfileImportThread; -class DictionaryValue; -class ImporterHost; - class ImporterBridge : public base::RefCountedThreadSafe<ImporterBridge> { public: ImporterBridge(); @@ -27,7 +24,7 @@ class ImporterBridge : public base::RefCountedThreadSafe<ImporterBridge> { const std::vector<ProfileWriter::BookmarkEntry>& bookmarks, const std::wstring& first_folder_name, int options) = 0; - virtual void AddHomePage(const GURL &home_page) = 0; + virtual void AddHomePage(const GURL& home_page) = 0; #if defined(OS_WIN) virtual void AddIE7PasswordInfo(const IE7PasswordInfo password_info) = 0; @@ -35,9 +32,9 @@ class ImporterBridge : public base::RefCountedThreadSafe<ImporterBridge> { virtual void SetFavicons( const std::vector<history::ImportedFaviconUsage>& favicons) = 0; - virtual void SetHistoryItems(const std::vector<history::URLRow> &rows, + virtual void SetHistoryItems(const std::vector<history::URLRow>& rows, history::VisitSource visit_source) = 0; - virtual void SetKeywords(const std::vector<TemplateURL*> &template_urls, + virtual void SetKeywords(const std::vector<TemplateURL*>& template_urls, int default_keyword_index, bool unique_on_host_and_path) = 0; virtual void SetPasswordForm(const webkit_glue::PasswordForm& form) = 0; @@ -74,55 +71,4 @@ class ImporterBridge : public base::RefCountedThreadSafe<ImporterBridge> { DISALLOW_COPY_AND_ASSIGN(ImporterBridge); }; -// When the importer is run in an external process, the bridge is effectively -// split in half by the IPC infrastructure. The external bridge receives data -// and notifications from the importer, and sends it across IPC. The -// internal bridge gathers the data from the IPC host and writes it to the -// profile. -class ExternalProcessImporterBridge : public ImporterBridge { - public: - ExternalProcessImporterBridge(ProfileImportThread* profile_import_thread, - const DictionaryValue& localized_strings); - - // Methods inherited from ImporterBridge. On the external side, these - // methods gather data and give it to a ProfileImportThread to pass back - // to the browser process. - virtual void AddBookmarkEntries( - const std::vector<ProfileWriter::BookmarkEntry>& bookmarks, - const std::wstring& first_folder_name, int options); - virtual void AddHomePage(const GURL &home_page); - -#if defined(OS_WIN) - virtual void AddIE7PasswordInfo(const IE7PasswordInfo password_info); -#endif - - virtual void SetFavicons( - const std::vector<history::ImportedFaviconUsage>& favicons); - virtual void SetHistoryItems(const std::vector<history::URLRow> &rows, - history::VisitSource visit_source); - virtual void SetKeywords(const std::vector<TemplateURL*>& template_urls, - int default_keyword_index, - bool unique_on_host_and_path); - virtual void SetPasswordForm(const webkit_glue::PasswordForm& form); - - virtual void NotifyStarted(); - virtual void NotifyItemStarted(importer::ImportItem item); - virtual void NotifyItemEnded(importer::ImportItem item); - virtual void NotifyEnded(); - - virtual std::wstring GetLocalizedString(int message_id); - - private: - ~ExternalProcessImporterBridge(); - - // Call back to send data and messages across IPC. - ProfileImportThread* const profile_import_thread_; - - // Holds strings needed by the external importer because the resource - // bundle isn't available to the external process. - scoped_ptr<DictionaryValue> localized_strings_; - - DISALLOW_COPY_AND_ASSIGN(ExternalProcessImporterBridge); -}; - #endif // CHROME_BROWSER_IMPORTER_IMPORTER_BRIDGE_H_ diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 9b7c472..2717024 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -1182,6 +1182,8 @@ 'browser/idle_win.cc', 'browser/ime_input.cc', 'browser/ime_input.h', + 'browser/importer/external_process_importer_bridge.cc', + 'browser/importer/external_process_importer_bridge.h', 'browser/importer/external_process_importer_client.cc', 'browser/importer/external_process_importer_client.h', 'browser/importer/external_process_importer_host.cc', diff --git a/chrome/profile_import/profile_import_thread.cc b/chrome/profile_import/profile_import_thread.cc index 4a3003c..9240a93 100644 --- a/chrome/profile_import/profile_import_thread.cc +++ b/chrome/profile_import/profile_import_thread.cc @@ -7,9 +7,8 @@ #include <algorithm> #include "base/values.h" -#include "chrome/browser/importer/importer_bridge.h" +#include "chrome/browser/importer/external_process_importer_bridge.h" #include "chrome/browser/importer/importer_data_types.h" -#include "chrome/browser/importer/importer_host.h" #include "chrome/browser/importer/importer_list.h" #include "chrome/browser/importer/importer_messages.h" #include "chrome/browser/search_engines/template_url.h" |