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