Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(281)

Side by Side Diff: chrome/utility/importer/external_process_importer_bridge.cc

Issue 480953002: Implement "Autofill form data" import for Firefox (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added test case Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/utility/importer/external_process_importer_bridge.h" 5 #include "chrome/utility/importer/external_process_importer_bridge.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
11 #include "base/task_runner.h" 11 #include "base/task_runner.h"
12 #include "base/values.h" 12 #include "base/values.h"
13 #include "chrome/common/importer/imported_bookmark_entry.h" 13 #include "chrome/common/importer/imported_bookmark_entry.h"
14 #include "chrome/common/importer/imported_favicon_usage.h" 14 #include "chrome/common/importer/imported_favicon_usage.h"
15 #include "chrome/common/importer/importer_data_types.h" 15 #include "chrome/common/importer/importer_data_types.h"
16 #include "chrome/common/importer/profile_import_process_messages.h" 16 #include "chrome/common/importer/profile_import_process_messages.h"
17 #include "components/autofill/core/common/password_form.h" 17 #include "components/autofill/core/common/password_form.h"
18 #include "ipc/ipc_sender.h" 18 #include "ipc/ipc_sender.h"
19 19
20 namespace { 20 namespace {
21 21
22 // Rather than sending all import items over IPC at once we chunk them into 22 // Rather than sending all import items over IPC at once we chunk them into
23 // separate requests. This avoids the case of a large import causing 23 // separate requests. This avoids the case of a large import causing
24 // oversized IPC messages. 24 // oversized IPC messages.
25 const int kNumBookmarksToSend = 100; 25 const int kNumBookmarksToSend = 100;
26 const int kNumHistoryRowsToSend = 100; 26 const int kNumHistoryRowsToSend = 100;
27 const int kNumFaviconsToSend = 100; 27 const int kNumFaviconsToSend = 100;
28 28 const int kNumAutofillFormDataToSend = 100;
Ilya Sherman 2014/08/20 05:47:42 nit: Perhaps it's appropriate to reduce these four
Ilya Sherman 2014/08/20 05:47:42 nit: Please leave a blank line after this one.
Nikhil 2014/08/20 11:29:18 Done.
Nikhil 2014/08/20 11:29:18 Hmm, they all use different structures and have di
29 } 29 }
30 30
31 ExternalProcessImporterBridge::ExternalProcessImporterBridge( 31 ExternalProcessImporterBridge::ExternalProcessImporterBridge(
32 const base::DictionaryValue& localized_strings, 32 const base::DictionaryValue& localized_strings,
33 IPC::Sender* sender, 33 IPC::Sender* sender,
34 base::TaskRunner* task_runner) 34 base::TaskRunner* task_runner)
35 : sender_(sender), 35 : sender_(sender),
36 task_runner_(task_runner) { 36 task_runner_(task_runner) {
37 // Bridge needs to make its own copy because OS 10.6 autoreleases the 37 // Bridge needs to make its own copy because OS 10.6 autoreleases the
38 // localized_strings value that is passed in (see http://crbug.com/46003 ). 38 // localized_strings value that is passed in (see http://crbug.com/46003 ).
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 const std::vector<std::string>& search_engine_data) { 134 const std::vector<std::string>& search_engine_data) {
135 Send(new ProfileImportProcessHostMsg_NotifyFirefoxSearchEngData( 135 Send(new ProfileImportProcessHostMsg_NotifyFirefoxSearchEngData(
136 search_engine_data)); 136 search_engine_data));
137 } 137 }
138 138
139 void ExternalProcessImporterBridge::SetPasswordForm( 139 void ExternalProcessImporterBridge::SetPasswordForm(
140 const autofill::PasswordForm& form) { 140 const autofill::PasswordForm& form) {
141 Send(new ProfileImportProcessHostMsg_NotifyPasswordFormReady(form)); 141 Send(new ProfileImportProcessHostMsg_NotifyPasswordFormReady(form));
142 } 142 }
143 143
144 void ExternalProcessImporterBridge::SetAutofillFormData(
145 const std::vector<ImporterAutofillFormDataEntry>& entries) {
146 Send(new ProfileImportProcessHostMsg_AutofillFormDataImportStart(
147 entries.size()));
148
149 // |autofill_form_data_entries_left| is required for the checks below as
150 // Windows has a Debug bounds-check which prevents pushing an iterator beyond
151 // its end() (i.e., |it + 2 < s.end()| crashes in debug mode if |i + 1 ==
152 // s.end()|).
153 int autofill_form_data_entries_left = entries.end() - entries.begin();
154 for (std::vector<ImporterAutofillFormDataEntry>::const_iterator it =
155 entries.begin();
156 it < entries.end();) {
157 std::vector<ImporterAutofillFormDataEntry> autofill_form_data_entry_group;
158 std::vector<ImporterAutofillFormDataEntry>::const_iterator end_group =
159 it +
160 std::min(autofill_form_data_entries_left, kNumAutofillFormDataToSend);
161 autofill_form_data_entry_group.assign(it, end_group);
162
163 Send(new ProfileImportProcessHostMsg_AutofillFormDataImportGroup(
164 autofill_form_data_entry_group));
165 autofill_form_data_entries_left -= end_group - it;
166 it = end_group;
167 }
168 DCHECK_EQ(0, autofill_form_data_entries_left);
169 }
170
144 void ExternalProcessImporterBridge::NotifyStarted() { 171 void ExternalProcessImporterBridge::NotifyStarted() {
145 Send(new ProfileImportProcessHostMsg_Import_Started()); 172 Send(new ProfileImportProcessHostMsg_Import_Started());
146 } 173 }
147 174
148 void ExternalProcessImporterBridge::NotifyItemStarted( 175 void ExternalProcessImporterBridge::NotifyItemStarted(
149 importer::ImportItem item) { 176 importer::ImportItem item) {
150 Send(new ProfileImportProcessHostMsg_ImportItem_Started(item)); 177 Send(new ProfileImportProcessHostMsg_ImportItem_Started(item));
151 } 178 }
152 179
153 void ExternalProcessImporterBridge::NotifyItemEnded(importer::ImportItem item) { 180 void ExternalProcessImporterBridge::NotifyItemEnded(importer::ImportItem item) {
(...skipping 17 matching lines...) Expand all
171 task_runner_->PostTask( 198 task_runner_->PostTask(
172 FROM_HERE, 199 FROM_HERE,
173 base::Bind(&ExternalProcessImporterBridge::SendInternal, 200 base::Bind(&ExternalProcessImporterBridge::SendInternal,
174 this, message)); 201 this, message));
175 } 202 }
176 203
177 void ExternalProcessImporterBridge::SendInternal(IPC::Message* message) { 204 void ExternalProcessImporterBridge::SendInternal(IPC::Message* message) {
178 DCHECK(task_runner_->RunsTasksOnCurrentThread()); 205 DCHECK(task_runner_->RunsTasksOnCurrentThread());
179 sender_->Send(message); 206 sender_->Send(message);
180 } 207 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698