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

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

Issue 14575004: Extract BookmarksFileImporter from Firefox2Importer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: test cleanup Created 7 years, 7 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 | Annotate | Revision Log
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/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/bookmarks/imported_bookmark_entry.h"
14 #include "chrome/browser/favicon/imported_favicon_usage.h"
14 #include "chrome/browser/importer/profile_import_process_messages.h" 15 #include "chrome/browser/importer/profile_import_process_messages.h"
15 #include "content/public/common/password_form.h" 16 #include "content/public/common/password_form.h"
16 #include "ipc/ipc_sender.h" 17 #include "ipc/ipc_sender.h"
17 18
18 #if defined(OS_WIN) 19 #if defined(OS_WIN)
19 #include "components/webdata/encryptor/ie7_password.h" 20 #include "components/webdata/encryptor/ie7_password.h"
20 #endif 21 #endif
21 22
22 namespace { 23 namespace {
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;
29 } 30 }
30 31
31 ExternalProcessImporterBridge::ExternalProcessImporterBridge( 32 ExternalProcessImporterBridge::ExternalProcessImporterBridge(
32 const DictionaryValue& localized_strings, 33 const DictionaryValue& localized_strings,
33 IPC::Sender* sender, 34 IPC::Sender* sender,
34 base::TaskRunner* task_runner) 35 base::TaskRunner* task_runner)
35 : sender_(sender), 36 : sender_(sender),
36 task_runner_(task_runner) { 37 task_runner_(task_runner) {
37 // 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
38 // 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 ).
39 localized_strings_.reset(localized_strings.DeepCopy()); 40 localized_strings_.reset(localized_strings.DeepCopy());
40 } 41 }
41 42
42 void ExternalProcessImporterBridge::AddBookmarks( 43 void ExternalProcessImporterBridge::AddBookmarks(
43 const std::vector<ProfileWriter::BookmarkEntry>& bookmarks, 44 const std::vector<ImportedBookmarkEntry>& bookmarks,
44 const string16& first_folder_name) { 45 const string16& first_folder_name) {
45 Send(new ProfileImportProcessHostMsg_NotifyBookmarksImportStart( 46 Send(new ProfileImportProcessHostMsg_NotifyBookmarksImportStart(
46 first_folder_name, bookmarks.size())); 47 first_folder_name, bookmarks.size()));
47 48
48 std::vector<ProfileWriter::BookmarkEntry>::const_iterator it; 49 std::vector<ImportedBookmarkEntry>::const_iterator it;
49 for (it = bookmarks.begin(); it < bookmarks.end(); 50 for (it = bookmarks.begin(); it < bookmarks.end();
50 it = it + kNumBookmarksToSend) { 51 it = it + kNumBookmarksToSend) {
51 std::vector<ProfileWriter::BookmarkEntry> bookmark_group; 52 std::vector<ImportedBookmarkEntry> bookmark_group;
52 std::vector<ProfileWriter::BookmarkEntry>::const_iterator end_group = 53 std::vector<ImportedBookmarkEntry>::const_iterator end_group =
53 it + kNumBookmarksToSend < bookmarks.end() ? 54 it + kNumBookmarksToSend < bookmarks.end() ?
54 it + kNumBookmarksToSend : bookmarks.end(); 55 it + kNumBookmarksToSend : bookmarks.end();
55 bookmark_group.assign(it, end_group); 56 bookmark_group.assign(it, end_group);
56 57
57 Send(new ProfileImportProcessHostMsg_NotifyBookmarksImportGroup( 58 Send(new ProfileImportProcessHostMsg_NotifyBookmarksImportGroup(
58 bookmark_group)); 59 bookmark_group));
59 } 60 }
60 } 61 }
61 62
62 void ExternalProcessImporterBridge::AddHomePage(const GURL& home_page) { 63 void ExternalProcessImporterBridge::AddHomePage(const GURL& home_page) {
63 NOTIMPLEMENTED(); 64 NOTIMPLEMENTED();
64 } 65 }
65 66
66 #if defined(OS_WIN) 67 #if defined(OS_WIN)
67 void ExternalProcessImporterBridge::AddIE7PasswordInfo( 68 void ExternalProcessImporterBridge::AddIE7PasswordInfo(
68 const IE7PasswordInfo& password_info) { 69 const IE7PasswordInfo& password_info) {
69 NOTIMPLEMENTED(); 70 NOTIMPLEMENTED();
70 } 71 }
71 #endif 72 #endif
72 73
73 void ExternalProcessImporterBridge::SetFavicons( 74 void ExternalProcessImporterBridge::SetFavicons(
74 const std::vector<history::ImportedFaviconUsage>& favicons) { 75 const std::vector<ImportedFaviconUsage>& favicons) {
75 Send(new ProfileImportProcessHostMsg_NotifyFaviconsImportStart( 76 Send(new ProfileImportProcessHostMsg_NotifyFaviconsImportStart(
76 favicons.size())); 77 favicons.size()));
77 78
78 std::vector<history::ImportedFaviconUsage>::const_iterator it; 79 std::vector<ImportedFaviconUsage>::const_iterator it;
79 for (it = favicons.begin(); it < favicons.end(); 80 for (it = favicons.begin(); it < favicons.end();
80 it = it + kNumFaviconsToSend) { 81 it = it + kNumFaviconsToSend) {
81 std::vector<history::ImportedFaviconUsage> favicons_group; 82 std::vector<ImportedFaviconUsage> favicons_group;
82 std::vector<history::ImportedFaviconUsage>::const_iterator end_group = 83 std::vector<ImportedFaviconUsage>::const_iterator end_group =
83 std::min(it + kNumFaviconsToSend, favicons.end()); 84 std::min(it + kNumFaviconsToSend, favicons.end());
84 favicons_group.assign(it, end_group); 85 favicons_group.assign(it, end_group);
85 86
86 Send(new ProfileImportProcessHostMsg_NotifyFaviconsImportGroup( 87 Send(new ProfileImportProcessHostMsg_NotifyFaviconsImportGroup(
87 favicons_group)); 88 favicons_group));
88 } 89 }
89 } 90 }
90 91
91 void ExternalProcessImporterBridge::SetHistoryItems( 92 void ExternalProcessImporterBridge::SetHistoryItems(
92 const history::URLRows& rows, 93 const history::URLRows& rows,
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 task_runner_->PostTask( 150 task_runner_->PostTask(
150 FROM_HERE, 151 FROM_HERE,
151 base::Bind(&ExternalProcessImporterBridge::SendInternal, 152 base::Bind(&ExternalProcessImporterBridge::SendInternal,
152 this, message)); 153 this, message));
153 } 154 }
154 155
155 void ExternalProcessImporterBridge::SendInternal(IPC::Message* message) { 156 void ExternalProcessImporterBridge::SendInternal(IPC::Message* message) {
156 DCHECK(task_runner_->RunsTasksOnCurrentThread()); 157 DCHECK(task_runner_->RunsTasksOnCurrentThread());
157 sender_->Send(message); 158 sender_->Send(message);
158 } 159 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698