1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
// Copyright (c) 2012 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/utility/importer/external_process_importer_bridge.h"
#include "base/bind.h"
#include "base/logging.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task_runner.h"
#include "base/values.h"
#include "chrome/common/importer/imported_bookmark_entry.h"
#include "chrome/common/importer/imported_favicon_usage.h"
#include "chrome/common/importer/importer_data_types.h"
#include "chrome/common/importer/profile_import_process_messages.h"
#include "components/autofill/core/common/password_form.h"
#include "ipc/ipc_sender.h"
namespace {
// Rather than sending all import items over IPC at once we chunk them into
// separate requests. This avoids the case of a large import causing
// oversized IPC messages.
const int kNumBookmarksToSend = 100;
const int kNumHistoryRowsToSend = 100;
const int kNumFaviconsToSend = 100;
}
ExternalProcessImporterBridge::ExternalProcessImporterBridge(
const base::DictionaryValue& localized_strings,
IPC::Sender* sender,
base::TaskRunner* task_runner)
: sender_(sender),
task_runner_(task_runner) {
// 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::AddBookmarks(
const std::vector<ImportedBookmarkEntry>& bookmarks,
const base::string16& first_folder_name) {
Send(new ProfileImportProcessHostMsg_NotifyBookmarksImportStart(
first_folder_name, bookmarks.size()));
// |bookmarks_left| is required for the checks below as Windows has a
// Debug bounds-check which prevents pushing an iterator beyond its end()
// (i.e., |it + 2 < s.end()| crashes in debug mode if |i + 1 == s.end()|).
int bookmarks_left = bookmarks.end() - bookmarks.begin();
for (std::vector<ImportedBookmarkEntry>::const_iterator it =
bookmarks.begin(); it < bookmarks.end();) {
std::vector<ImportedBookmarkEntry> bookmark_group;
std::vector<ImportedBookmarkEntry>::const_iterator end_group =
it + std::min(bookmarks_left, kNumBookmarksToSend);
bookmark_group.assign(it, end_group);
Send(new ProfileImportProcessHostMsg_NotifyBookmarksImportGroup(
bookmark_group));
bookmarks_left -= end_group - it;
it = end_group;
}
DCHECK_EQ(0, bookmarks_left);
}
void ExternalProcessImporterBridge::AddHomePage(const GURL& home_page) {
Send(new ProfileImportProcessHostMsg_NotifyHomePageImportReady(home_page));
}
#if defined(OS_WIN)
void ExternalProcessImporterBridge::AddIE7PasswordInfo(
const importer::ImporterIE7PasswordInfo& password_info) {
Send(new ProfileImportProcessHostMsg_NotifyIE7PasswordInfo(password_info));
}
#endif
void ExternalProcessImporterBridge::SetFavicons(
const std::vector<ImportedFaviconUsage>& favicons) {
Send(new ProfileImportProcessHostMsg_NotifyFaviconsImportStart(
favicons.size()));
// |favicons_left| is required for the checks below as Windows has a
// Debug bounds-check which prevents pushing an iterator beyond its end()
// (i.e., |it + 2 < s.end()| crashes in debug mode if |i + 1 == s.end()|).
int favicons_left = favicons.end() - favicons.begin();
for (std::vector<ImportedFaviconUsage>::const_iterator it =
favicons.begin(); it < favicons.end();) {
std::vector<ImportedFaviconUsage> favicons_group;
std::vector<ImportedFaviconUsage>::const_iterator end_group =
it + std::min(favicons_left, kNumFaviconsToSend);
favicons_group.assign(it, end_group);
Send(new ProfileImportProcessHostMsg_NotifyFaviconsImportGroup(
favicons_group));
favicons_left -= end_group - it;
it = end_group;
}
DCHECK_EQ(0, favicons_left);
}
void ExternalProcessImporterBridge::SetHistoryItems(
const std::vector<ImporterURLRow>& rows,
importer::VisitSource visit_source) {
Send(new ProfileImportProcessHostMsg_NotifyHistoryImportStart(rows.size()));
// |rows_left| is required for the checks below as Windows has a
// Debug bounds-check which prevents pushing an iterator beyond its end()
// (i.e., |it + 2 < s.end()| crashes in debug mode if |i + 1 == s.end()|).
int rows_left = rows.end() - rows.begin();
for (std::vector<ImporterURLRow>::const_iterator it = rows.begin();
it < rows.end();) {
std::vector<ImporterURLRow> row_group;
std::vector<ImporterURLRow>::const_iterator end_group =
it + std::min(rows_left, kNumHistoryRowsToSend);
row_group.assign(it, end_group);
Send(new ProfileImportProcessHostMsg_NotifyHistoryImportGroup(
row_group, visit_source));
rows_left -= end_group - it;
it = end_group;
}
DCHECK_EQ(0, rows_left);
}
void ExternalProcessImporterBridge::SetKeywords(
const std::vector<importer::URLKeywordInfo>& url_keywords,
bool unique_on_host_and_path) {
Send(new ProfileImportProcessHostMsg_NotifyKeywordsReady(
url_keywords, unique_on_host_and_path));
}
void ExternalProcessImporterBridge::SetFirefoxSearchEnginesXMLData(
const std::vector<std::string>& search_engine_data) {
Send(new ProfileImportProcessHostMsg_NotifyFirefoxSearchEngData(
search_engine_data));
}
void ExternalProcessImporterBridge::SetPasswordForm(
const autofill::PasswordForm& form) {
Send(new ProfileImportProcessHostMsg_NotifyPasswordFormReady(form));
}
void ExternalProcessImporterBridge::NotifyStarted() {
Send(new ProfileImportProcessHostMsg_Import_Started());
}
void ExternalProcessImporterBridge::NotifyItemStarted(
importer::ImportItem item) {
Send(new ProfileImportProcessHostMsg_ImportItem_Started(item));
}
void ExternalProcessImporterBridge::NotifyItemEnded(importer::ImportItem item) {
Send(new ProfileImportProcessHostMsg_ImportItem_Finished(item));
}
void ExternalProcessImporterBridge::NotifyEnded() {
// The internal process detects import end when all items have been received.
}
base::string16 ExternalProcessImporterBridge::GetLocalizedString(
int message_id) {
base::string16 message;
localized_strings_->GetString(base::IntToString(message_id), &message);
return message;
}
ExternalProcessImporterBridge::~ExternalProcessImporterBridge() {}
void ExternalProcessImporterBridge::Send(IPC::Message* message) {
task_runner_->PostTask(
FROM_HERE,
base::Bind(&ExternalProcessImporterBridge::SendInternal,
this, message));
}
void ExternalProcessImporterBridge::SendInternal(IPC::Message* message) {
DCHECK(task_runner_->RunsTasksOnCurrentThread());
sender_->Send(message);
}
|