1// Copyright (c) 2012 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_UTILITY_IMPORTER_EXTERNAL_PROCESS_IMPORTER_BRIDGE_H_
6#define CHROME_UTILITY_IMPORTER_EXTERNAL_PROCESS_IMPORTER_BRIDGE_H_
7
8#include <string>
9#include <vector>
10
11#include "base/basictypes.h"
12#include "base/compiler_specific.h"
13#include "base/memory/scoped_ptr.h"
14#include "chrome/common/importer/importer_bridge.h"
15
16class GURL;
17struct ImportedBookmarkEntry;
18
19namespace base {
20class DictionaryValue;
21class TaskRunner;
22}
23
24namespace importer {
25#if defined(OS_WIN)
26struct ImporterIE7PasswordInfo;
27#endif
28struct ImporterURLRow;
29struct URLKeywordInfo;
30}
31
32namespace IPC {
33class Message;
34class Sender;
35}
36
37// When the importer is run in an external process, the bridge is effectively
38// split in half by the IPC infrastructure.  The external bridge receives data
39// and notifications from the importer, and sends it across IPC.  The
40// internal bridge gathers the data from the IPC host and writes it to the
41// profile.
42class ExternalProcessImporterBridge : public ImporterBridge {
43 public:
44  ExternalProcessImporterBridge(
45      const base::DictionaryValue& localized_strings,
46      IPC::Sender* sender,
47      base::TaskRunner* task_runner);
48
49  // Begin ImporterBridge implementation:
50  virtual void AddBookmarks(const std::vector<ImportedBookmarkEntry>& bookmarks,
51                            const base::string16& first_folder_name) OVERRIDE;
52
53  virtual void AddHomePage(const GURL& home_page) OVERRIDE;
54
55#if defined(OS_WIN)
56  virtual void AddIE7PasswordInfo(
57      const importer::ImporterIE7PasswordInfo& password_info) OVERRIDE;
58#endif
59
60  virtual void SetFavicons(
61      const std::vector<ImportedFaviconUsage>& favicons) OVERRIDE;
62
63  virtual void SetHistoryItems(const std::vector<ImporterURLRow>& rows,
64                               importer::VisitSource visit_source) OVERRIDE;
65
66  virtual void SetKeywords(
67      const std::vector<importer::URLKeywordInfo>& url_keywords,
68      bool unique_on_host_and_path) OVERRIDE;
69
70  virtual void SetFirefoxSearchEnginesXMLData(
71      const std::vector<std::string>& seach_engine_data) OVERRIDE;
72
73  virtual void SetPasswordForm(
74      const autofill::PasswordForm& form) OVERRIDE;
75
76  virtual void SetAutofillFormData(
77      const std::vector<ImporterAutofillFormDataEntry>& entries) OVERRIDE;
78
79  virtual void NotifyStarted() OVERRIDE;
80  virtual void NotifyItemStarted(importer::ImportItem item) OVERRIDE;
81  virtual void NotifyItemEnded(importer::ImportItem item) OVERRIDE;
82  virtual void NotifyEnded() OVERRIDE;
83
84  virtual base::string16 GetLocalizedString(int message_id) OVERRIDE;
85  // End ImporterBridge implementation.
86
87 private:
88  virtual ~ExternalProcessImporterBridge();
89
90  void Send(IPC::Message* message);
91  void SendInternal(IPC::Message* message);
92
93  // Holds strings needed by the external importer because the resource
94  // bundle isn't available to the external process.
95  scoped_ptr<base::DictionaryValue> localized_strings_;
96
97  IPC::Sender* sender_;
98  scoped_refptr<base::TaskRunner> task_runner_;
99
100  DISALLOW_COPY_AND_ASSIGN(ExternalProcessImporterBridge);
101};
102
103#endif  // CHROME_UTILITY_IMPORTER_EXTERNAL_PROCESS_IMPORTER_BRIDGE_H_
104