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