importer_bridge.h revision 21d179b334e59e9a3bfcaed4c4430bef1bc5759d
1// Copyright (c) 2010 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#ifndef CHROME_BROWSER_IMPORTER_IMPORTER_BRIDGE_H_ 6#define CHROME_BROWSER_IMPORTER_IMPORTER_BRIDGE_H_ 7#pragma once 8 9#include <vector> 10 11#include "base/basictypes.h" 12#include "base/ref_counted.h" 13#include "base/scoped_ptr.h" 14#include "chrome/browser/importer/importer_data_types.h" 15// TODO: remove this, see friend declaration in ImporterBridge. 16#include "chrome/browser/importer/toolbar_importer.h" 17 18class ProfileImportThread; 19class DictionaryValue; 20class ImporterHost; 21 22class ImporterBridge : public base::RefCountedThreadSafe<ImporterBridge> { 23 public: 24 ImporterBridge(); 25 26 virtual void AddBookmarkEntries( 27 const std::vector<ProfileWriter::BookmarkEntry>& bookmarks, 28 const std::wstring& first_folder_name, 29 int options) = 0; 30 virtual void AddHomePage(const GURL &home_page) = 0; 31 32#if defined(OS_WIN) 33 virtual void AddIE7PasswordInfo(const IE7PasswordInfo password_info) = 0; 34#endif 35 36 virtual void SetFavIcons( 37 const std::vector<history::ImportedFavIconUsage>& fav_icons) = 0; 38 virtual void SetHistoryItems(const std::vector<history::URLRow> &rows, 39 history::VisitSource visit_source) = 0; 40 virtual void SetKeywords(const std::vector<TemplateURL*> &template_urls, 41 int default_keyword_index, 42 bool unique_on_host_and_path) = 0; 43 virtual void SetPasswordForm(const webkit_glue::PasswordForm& form) = 0; 44 45 // Notifies the coordinator that the collection of data for the specified 46 // item has begun. 47 virtual void NotifyItemStarted(importer::ImportItem item) = 0; 48 49 // Notifies the coordinator that the collection of data for the specified 50 // item has completed. 51 virtual void NotifyItemEnded(importer::ImportItem item) = 0; 52 53 // Notifies the coordinator that the import operation has begun. 54 virtual void NotifyStarted() = 0; 55 56 // Notifies the coordinator that the entire import operation has completed. 57 virtual void NotifyEnded() = 0; 58 59 // For InProcessImporters this calls l10n_util. For ExternalProcessImporters 60 // this calls the set of strings we've ported over to the external process. 61 // It's good to avoid having to create a separate ResourceBundle for the 62 // external import process, since the importer only needs a few strings. 63 virtual std::wstring GetLocalizedString(int message_id) = 0; 64 65 protected: 66 friend class base::RefCountedThreadSafe<ImporterBridge>; 67 // TODO: In order to run Toolbar5Importer OOP we need to cut this 68 // connection, but as an interim step we allow Toolbar5Import to break 69 // the abstraction here and assume import is in-process. 70 friend class Toolbar5Importer; 71 72 virtual ~ImporterBridge(); 73 74 DISALLOW_COPY_AND_ASSIGN(ImporterBridge); 75}; 76 77class InProcessImporterBridge : public ImporterBridge { 78 public: 79 InProcessImporterBridge(ProfileWriter* writer, 80 ImporterHost* host); 81 82 // Methods inherited from ImporterBridge. On the internal side, these 83 // methods launch tasks to write the data to the profile with the |writer_|. 84 virtual void AddBookmarkEntries( 85 const std::vector<ProfileWriter::BookmarkEntry>& bookmarks, 86 const std::wstring& first_folder_name, 87 int options); 88 virtual void AddHomePage(const GURL &home_page); 89 90#if defined(OS_WIN) 91 virtual void AddIE7PasswordInfo(const IE7PasswordInfo password_info); 92#endif 93 94 virtual void SetFavIcons( 95 const std::vector<history::ImportedFavIconUsage>& fav_icons); 96 virtual void SetHistoryItems(const std::vector<history::URLRow> &rows, 97 history::VisitSource visit_source); 98 virtual void SetKeywords(const std::vector<TemplateURL*>& template_urls, 99 int default_keyword_index, 100 bool unique_on_host_and_path); 101 virtual void SetPasswordForm(const webkit_glue::PasswordForm& form); 102 103 virtual void NotifyItemStarted(importer::ImportItem item); 104 virtual void NotifyItemEnded(importer::ImportItem item); 105 virtual void NotifyStarted(); 106 virtual void NotifyEnded(); 107 virtual std::wstring GetLocalizedString(int message_id); 108 109 private: 110 virtual ~InProcessImporterBridge(); 111 112 ProfileWriter* const writer_; // weak 113 ImporterHost* const host_; // weak 114 115 DISALLOW_COPY_AND_ASSIGN(InProcessImporterBridge); 116}; 117 118// When the importer is run in an external process, the bridge is effectively 119// split in half by the IPC infrastructure. The external bridge receives data 120// and notifications from the importer, and sends it across IPC. The 121// internal bridge gathers the data from the IPC host and writes it to the 122// profile. 123class ExternalProcessImporterBridge : public ImporterBridge { 124 public: 125 ExternalProcessImporterBridge(ProfileImportThread* profile_import_thread, 126 const DictionaryValue& localized_strings); 127 128 // Methods inherited from ImporterBridge. On the external side, these 129 // methods gather data and give it to a ProfileImportThread to pass back 130 // to the browser process. 131 virtual void AddBookmarkEntries( 132 const std::vector<ProfileWriter::BookmarkEntry>& bookmarks, 133 const std::wstring& first_folder_name, int options); 134 virtual void AddHomePage(const GURL &home_page); 135 136#if defined(OS_WIN) 137 virtual void AddIE7PasswordInfo(const IE7PasswordInfo password_info); 138#endif 139 140 virtual void SetFavIcons( 141 const std::vector<history::ImportedFavIconUsage>& fav_icons); 142 virtual void SetHistoryItems(const std::vector<history::URLRow> &rows, 143 history::VisitSource visit_source); 144 virtual void SetKeywords(const std::vector<TemplateURL*>& template_urls, 145 int default_keyword_index, 146 bool unique_on_host_and_path); 147 virtual void SetPasswordForm(const webkit_glue::PasswordForm& form); 148 149 virtual void NotifyItemStarted(importer::ImportItem item); 150 virtual void NotifyItemEnded(importer::ImportItem item); 151 virtual void NotifyStarted(); 152 virtual void NotifyEnded(); 153 virtual std::wstring GetLocalizedString(int message_id); 154 155 private: 156 ~ExternalProcessImporterBridge(); 157 158 // Call back to send data and messages across IPC. 159 ProfileImportThread* const profile_import_thread_; 160 161 // Holds strings needed by the external importer because the resource 162 // bundle isn't available to the external process. 163 scoped_ptr<DictionaryValue> localized_strings_; 164 165 DISALLOW_COPY_AND_ASSIGN(ExternalProcessImporterBridge); 166}; 167 168#endif // CHROME_BROWSER_IMPORTER_IMPORTER_BRIDGE_H_ 169