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

Unified Diff: chrome/browser/importer/external_process_importer_bridge.cc

Issue 12670013: Out-of-process import on Windows. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: extract some more CLs Created 7 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/importer/external_process_importer_bridge.cc
diff --git a/chrome/browser/importer/external_process_importer_bridge.cc b/chrome/browser/importer/external_process_importer_bridge.cc
index 92d2857397dc195707db1ebd6c53c875692e632d..376da7e1bb10027bb2c52a779a9f5da406028175 100644
--- a/chrome/browser/importer/external_process_importer_bridge.cc
+++ b/chrome/browser/importer/external_process_importer_bridge.cc
@@ -20,12 +20,14 @@
#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(
@@ -45,18 +47,23 @@ void ExternalProcessImporterBridge::AddBookmarks(
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) {
+ // |bookmars_left| is required for the checks below as Windows has a
tapted 2013/04/24 08:08:35 typo: bookmars -> bookmarks
gab 2013/04/24 20:24:59 Done.
+ // 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<ProfileWriter::BookmarkEntry>::const_iterator it =
+ bookmarks.begin(); it < bookmarks.end();) {
std::vector<ProfileWriter::BookmarkEntry> bookmark_group;
std::vector<ProfileWriter::BookmarkEntry>::const_iterator end_group =
- it + kNumBookmarksToSend < bookmarks.end() ?
- it + kNumBookmarksToSend : bookmarks.end();
+ 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) {
@@ -75,17 +82,23 @@ void ExternalProcessImporterBridge::SetFavicons(
Send(new ProfileImportProcessHostMsg_NotifyFaviconsImportStart(
favicons.size()));
- std::vector<history::ImportedFaviconUsage>::const_iterator it;
- for (it = favicons.begin(); it < favicons.end();
- it = it + kNumFaviconsToSend) {
+ // |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<history::ImportedFaviconUsage>::const_iterator it =
+ favicons.begin(); it < favicons.end();) {
std::vector<history::ImportedFaviconUsage> favicons_group;
std::vector<history::ImportedFaviconUsage>::const_iterator end_group =
- std::min(it + kNumFaviconsToSend, favicons.end());
+ it + std::min(favicons_left, kNumFaviconsToSend);
favicons_group.assign(it, end_group);
- Send(new ProfileImportProcessHostMsg_NotifyFaviconsImportGroup(
- favicons_group));
+ Send(new ProfileImportProcessHostMsg_NotifyFaviconsImportGroup(
+ favicons_group));
+ favicons_left -= end_group - it;
+ it = end_group;
}
+ DCHECK_EQ(0, favicons_left);
}
void ExternalProcessImporterBridge::SetHistoryItems(
@@ -93,18 +106,22 @@ void ExternalProcessImporterBridge::SetHistoryItems(
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) {
+ // |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 (history::URLRows::const_iterator it = rows.begin(); it < rows.end();) {
history::URLRows row_group;
history::URLRows::const_iterator end_group =
- it + kNumHistoryRowsToSend < rows.end() ?
- it + kNumHistoryRowsToSend : rows.end();
+ it + std::min(rows_left, kNumHistoryRowsToSend);
row_group.assign(it, end_group);
- Send(new ProfileImportProcessHostMsg_NotifyHistoryImportGroup(row_group,
- visit_source));
+ Send(new ProfileImportProcessHostMsg_NotifyHistoryImportGroup(
+ row_group, visit_source));
+ rows_left -= end_group - it;
+ it = end_group;
}
+ DCHECK_EQ(0, rows_left);
}
void ExternalProcessImporterBridge::SetKeywords(

Powered by Google App Engine
This is Rietveld 408576698