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