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
|
// 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/browser/importer/external_process_importer_bridge.h"
#include "base/bind.h"
#include "base/logging.h"
#include "base/string_number_conversions.h"
#include "base/task_runner.h"
#include "base/utf_string_conversions.h"
#include "base/values.h"
#include "chrome/browser/history/history_types.h"
#include "chrome/browser/importer/profile_import_process_messages.h"
#include "webkit/forms/password_form.h"
#if defined(OS_WIN)
#include "chrome/browser/password_manager/ie7_password.h"
#endif
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 DictionaryValue& localized_strings,
IPC::Message::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<ProfileWriter::BookmarkEntry>& bookmarks,
const string16& first_folder_name) {
Send(new ProfileImportProcessHostMsg_NotifyBookmarksImportStart(
first_folder_name, bookmarks.size()));
std::vector<ProfileWriter::BookmarkEntry>::const_iterator it;
for (it = bookmarks.begin(); it < bookmarks.end();
it = it + kNumBookmarksToSend) {
std::vector<ProfileWriter::BookmarkEntry> bookmark_group;
std::vector<ProfileWriter::BookmarkEntry>::const_iterator end_group =
it + kNumBookmarksToSend < bookmarks.end() ?
it + kNumBookmarksToSend : bookmarks.end();
bookmark_group.assign(it, end_group);
Send(new ProfileImportProcessHostMsg_NotifyBookmarksImportGroup(
bookmark_group));
}
}
void ExternalProcessImporterBridge::AddHomePage(const GURL& home_page) {
NOTIMPLEMENTED();
}
#if defined(OS_WIN)
void ExternalProcessImporterBridge::AddIE7PasswordInfo(
const IE7PasswordInfo& password_info) {
NOTIMPLEMENTED();
}
#endif
void ExternalProcessImporterBridge::SetFavicons(
const std::vector<history::ImportedFaviconUsage>& favicons) {
Send(new ProfileImportProcessHostMsg_NotifyFaviconsImportStart(
favicons.size()));
std::vector<history::ImportedFaviconUsage>::const_iterator it;
for (it = favicons.begin(); it < favicons.end();
it = it + kNumFaviconsToSend) {
std::vector<history::ImportedFaviconUsage> favicons_group;
std::vector<history::ImportedFaviconUsage>::const_iterator end_group =
std::min(it + kNumFaviconsToSend, favicons.end());
favicons_group.assign(it, end_group);
Send(new ProfileImportProcessHostMsg_NotifyFaviconsImportGroup(
favicons_group));
}
}
void ExternalProcessImporterBridge::SetHistoryItems(
const history::URLRows& rows,
history::VisitSource visit_source) {
Send(new ProfileImportProcessHostMsg_NotifyHistoryImportStart(rows.size()));
history::URLRows::const_iterator it;
for (it = rows.begin(); it < rows.end();
it = it + kNumHistoryRowsToSend) {
history::URLRows row_group;
history::URLRows::const_iterator end_group =
it + kNumHistoryRowsToSend < rows.end() ?
it + kNumHistoryRowsToSend : rows.end();
row_group.assign(it, end_group);
Send(new ProfileImportProcessHostMsg_NotifyHistoryImportGroup(row_group,
visit_source));
}
}
void ExternalProcessImporterBridge::SetKeywords(
const std::vector<TemplateURL*>& template_urls,
bool unique_on_host_and_path) {
Send(new ProfileImportProcessHostMsg_NotifyKeywordsReady(template_urls,
unique_on_host_and_path));
STLDeleteContainerPointers(template_urls.begin(), template_urls.end());
}
void ExternalProcessImporterBridge::SetPasswordForm(
const webkit::forms::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.
}
string16 ExternalProcessImporterBridge::GetLocalizedString(int message_id) {
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);
}
|