OLD | NEW |
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/browser/importer/external_process_importer_bridge.h" | 5 #include "chrome/browser/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/task_runner.h" | 10 #include "base/task_runner.h" |
11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "chrome/browser/history/history_types.h" | 13 #include "chrome/browser/history/history_types.h" |
14 #include "chrome/browser/importer/profile_import_process_messages.h" | 14 #include "chrome/browser/importer/profile_import_process_messages.h" |
15 #include "content/public/common/password_form.h" | 15 #include "content/public/common/password_form.h" |
16 #include "ipc/ipc_sender.h" | 16 #include "ipc/ipc_sender.h" |
17 | 17 |
18 #if defined(OS_WIN) | 18 #if defined(OS_WIN) |
19 #include "components/webdata/encryptor/ie7_password.h" | 19 #include "components/webdata/encryptor/ie7_password.h" |
20 #endif | 20 #endif |
21 | 21 |
22 namespace { | 22 namespace { |
| 23 |
23 // Rather than sending all import items over IPC at once we chunk them into | 24 // Rather than sending all import items over IPC at once we chunk them into |
24 // separate requests. This avoids the case of a large import causing | 25 // separate requests. This avoids the case of a large import causing |
25 // oversized IPC messages. | 26 // oversized IPC messages. |
26 const int kNumBookmarksToSend = 100; | 27 const int kNumBookmarksToSend = 100; |
27 const int kNumHistoryRowsToSend = 100; | 28 const int kNumHistoryRowsToSend = 100; |
28 const int kNumFaviconsToSend = 100; | 29 const int kNumFaviconsToSend = 100; |
| 30 |
29 } | 31 } |
30 | 32 |
31 ExternalProcessImporterBridge::ExternalProcessImporterBridge( | 33 ExternalProcessImporterBridge::ExternalProcessImporterBridge( |
32 const DictionaryValue& localized_strings, | 34 const DictionaryValue& localized_strings, |
33 IPC::Sender* sender, | 35 IPC::Sender* sender, |
34 base::TaskRunner* task_runner) | 36 base::TaskRunner* task_runner) |
35 : sender_(sender), | 37 : sender_(sender), |
36 task_runner_(task_runner) { | 38 task_runner_(task_runner) { |
37 // Bridge needs to make its own copy because OS 10.6 autoreleases the | 39 // 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 ). | 40 // localized_strings value that is passed in (see http://crbug.com/46003 ). |
39 localized_strings_.reset(localized_strings.DeepCopy()); | 41 localized_strings_.reset(localized_strings.DeepCopy()); |
40 } | 42 } |
41 | 43 |
42 void ExternalProcessImporterBridge::AddBookmarks( | 44 void ExternalProcessImporterBridge::AddBookmarks( |
43 const std::vector<ProfileWriter::BookmarkEntry>& bookmarks, | 45 const std::vector<ProfileWriter::BookmarkEntry>& bookmarks, |
44 const string16& first_folder_name) { | 46 const string16& first_folder_name) { |
45 Send(new ProfileImportProcessHostMsg_NotifyBookmarksImportStart( | 47 Send(new ProfileImportProcessHostMsg_NotifyBookmarksImportStart( |
46 first_folder_name, bookmarks.size())); | 48 first_folder_name, bookmarks.size())); |
47 | 49 |
48 std::vector<ProfileWriter::BookmarkEntry>::const_iterator it; | 50 // |bookmarks_left| is required for the checks below as Windows has a |
49 for (it = bookmarks.begin(); it < bookmarks.end(); | 51 // Debug bounds-check which prevents pushing an iterator beyond its end() |
50 it = it + kNumBookmarksToSend) { | 52 // (i.e., |it + 2 < s.end()| crashes in debug mode if |i + 1 == s.end()|). |
| 53 int bookmarks_left = bookmarks.end() - bookmarks.begin(); |
| 54 for (std::vector<ProfileWriter::BookmarkEntry>::const_iterator it = |
| 55 bookmarks.begin(); it < bookmarks.end();) { |
51 std::vector<ProfileWriter::BookmarkEntry> bookmark_group; | 56 std::vector<ProfileWriter::BookmarkEntry> bookmark_group; |
52 std::vector<ProfileWriter::BookmarkEntry>::const_iterator end_group = | 57 std::vector<ProfileWriter::BookmarkEntry>::const_iterator end_group = |
53 it + kNumBookmarksToSend < bookmarks.end() ? | 58 it + std::min(bookmarks_left, kNumBookmarksToSend); |
54 it + kNumBookmarksToSend : bookmarks.end(); | |
55 bookmark_group.assign(it, end_group); | 59 bookmark_group.assign(it, end_group); |
56 | 60 |
57 Send(new ProfileImportProcessHostMsg_NotifyBookmarksImportGroup( | 61 Send(new ProfileImportProcessHostMsg_NotifyBookmarksImportGroup( |
58 bookmark_group)); | 62 bookmark_group)); |
| 63 bookmarks_left -= end_group - it; |
| 64 it = end_group; |
59 } | 65 } |
| 66 DCHECK_EQ(0, bookmarks_left); |
60 } | 67 } |
61 | 68 |
62 void ExternalProcessImporterBridge::AddHomePage(const GURL& home_page) { | 69 void ExternalProcessImporterBridge::AddHomePage(const GURL& home_page) { |
63 NOTIMPLEMENTED(); | 70 NOTIMPLEMENTED(); |
64 } | 71 } |
65 | 72 |
66 #if defined(OS_WIN) | 73 #if defined(OS_WIN) |
67 void ExternalProcessImporterBridge::AddIE7PasswordInfo( | 74 void ExternalProcessImporterBridge::AddIE7PasswordInfo( |
68 const IE7PasswordInfo& password_info) { | 75 const IE7PasswordInfo& password_info) { |
69 NOTIMPLEMENTED(); | 76 NOTIMPLEMENTED(); |
70 } | 77 } |
71 #endif | 78 #endif |
72 | 79 |
73 void ExternalProcessImporterBridge::SetFavicons( | 80 void ExternalProcessImporterBridge::SetFavicons( |
74 const std::vector<history::ImportedFaviconUsage>& favicons) { | 81 const std::vector<history::ImportedFaviconUsage>& favicons) { |
75 Send(new ProfileImportProcessHostMsg_NotifyFaviconsImportStart( | 82 Send(new ProfileImportProcessHostMsg_NotifyFaviconsImportStart( |
76 favicons.size())); | 83 favicons.size())); |
77 | 84 |
78 std::vector<history::ImportedFaviconUsage>::const_iterator it; | 85 // |favicons_left| is required for the checks below as Windows has a |
79 for (it = favicons.begin(); it < favicons.end(); | 86 // Debug bounds-check which prevents pushing an iterator beyond its end() |
80 it = it + kNumFaviconsToSend) { | 87 // (i.e., |it + 2 < s.end()| crashes in debug mode if |i + 1 == s.end()|). |
| 88 int favicons_left = favicons.end() - favicons.begin(); |
| 89 for (std::vector<history::ImportedFaviconUsage>::const_iterator it = |
| 90 favicons.begin(); it < favicons.end();) { |
81 std::vector<history::ImportedFaviconUsage> favicons_group; | 91 std::vector<history::ImportedFaviconUsage> favicons_group; |
82 std::vector<history::ImportedFaviconUsage>::const_iterator end_group = | 92 std::vector<history::ImportedFaviconUsage>::const_iterator end_group = |
83 std::min(it + kNumFaviconsToSend, favicons.end()); | 93 it + std::min(favicons_left, kNumFaviconsToSend); |
84 favicons_group.assign(it, end_group); | 94 favicons_group.assign(it, end_group); |
85 | 95 |
86 Send(new ProfileImportProcessHostMsg_NotifyFaviconsImportGroup( | 96 Send(new ProfileImportProcessHostMsg_NotifyFaviconsImportGroup( |
87 favicons_group)); | 97 favicons_group)); |
| 98 favicons_left -= end_group - it; |
| 99 it = end_group; |
88 } | 100 } |
| 101 DCHECK_EQ(0, favicons_left); |
89 } | 102 } |
90 | 103 |
91 void ExternalProcessImporterBridge::SetHistoryItems( | 104 void ExternalProcessImporterBridge::SetHistoryItems( |
92 const history::URLRows& rows, | 105 const history::URLRows& rows, |
93 history::VisitSource visit_source) { | 106 history::VisitSource visit_source) { |
94 Send(new ProfileImportProcessHostMsg_NotifyHistoryImportStart(rows.size())); | 107 Send(new ProfileImportProcessHostMsg_NotifyHistoryImportStart(rows.size())); |
95 | 108 |
96 history::URLRows::const_iterator it; | 109 // |rows_left| is required for the checks below as Windows has a |
97 for (it = rows.begin(); it < rows.end(); | 110 // Debug bounds-check which prevents pushing an iterator beyond its end() |
98 it = it + kNumHistoryRowsToSend) { | 111 // (i.e., |it + 2 < s.end()| crashes in debug mode if |i + 1 == s.end()|). |
| 112 int rows_left = rows.end() - rows.begin(); |
| 113 for (history::URLRows::const_iterator it = rows.begin(); it < rows.end();) { |
99 history::URLRows row_group; | 114 history::URLRows row_group; |
100 history::URLRows::const_iterator end_group = | 115 history::URLRows::const_iterator end_group = |
101 it + kNumHistoryRowsToSend < rows.end() ? | 116 it + std::min(rows_left, kNumHistoryRowsToSend); |
102 it + kNumHistoryRowsToSend : rows.end(); | |
103 row_group.assign(it, end_group); | 117 row_group.assign(it, end_group); |
104 | 118 |
105 Send(new ProfileImportProcessHostMsg_NotifyHistoryImportGroup(row_group, | 119 Send(new ProfileImportProcessHostMsg_NotifyHistoryImportGroup( |
106 visit_source)); | 120 row_group, visit_source)); |
| 121 rows_left -= end_group - it; |
| 122 it = end_group; |
107 } | 123 } |
| 124 DCHECK_EQ(0, rows_left); |
108 } | 125 } |
109 | 126 |
110 void ExternalProcessImporterBridge::SetKeywords( | 127 void ExternalProcessImporterBridge::SetKeywords( |
111 const std::vector<TemplateURL*>& template_urls, | 128 const std::vector<TemplateURL*>& template_urls, |
112 bool unique_on_host_and_path) { | 129 bool unique_on_host_and_path) { |
113 Send(new ProfileImportProcessHostMsg_NotifyKeywordsReady(template_urls, | 130 Send(new ProfileImportProcessHostMsg_NotifyKeywordsReady(template_urls, |
114 unique_on_host_and_path)); | 131 unique_on_host_and_path)); |
115 STLDeleteContainerPointers(template_urls.begin(), template_urls.end()); | 132 STLDeleteContainerPointers(template_urls.begin(), template_urls.end()); |
116 } | 133 } |
117 | 134 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 task_runner_->PostTask( | 166 task_runner_->PostTask( |
150 FROM_HERE, | 167 FROM_HERE, |
151 base::Bind(&ExternalProcessImporterBridge::SendInternal, | 168 base::Bind(&ExternalProcessImporterBridge::SendInternal, |
152 this, message)); | 169 this, message)); |
153 } | 170 } |
154 | 171 |
155 void ExternalProcessImporterBridge::SendInternal(IPC::Message* message) { | 172 void ExternalProcessImporterBridge::SendInternal(IPC::Message* message) { |
156 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 173 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
157 sender_->Send(message); | 174 sender_->Send(message); |
158 } | 175 } |
OLD | NEW |