• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "chrome/browser/importer/in_process_importer_bridge.h"
6 
7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/importer/importer_host.h"
9 #include "content/browser/browser_thread.h"
10 #include "ui/base/l10n/l10n_util.h"
11 #include "webkit/glue/password_form.h"
12 
13 #if defined(OS_WIN)
14 #include "chrome/browser/password_manager/ie7_password.h"
15 #endif
16 
InProcessImporterBridge(ProfileWriter * writer,ImporterHost * host)17 InProcessImporterBridge::InProcessImporterBridge(ProfileWriter* writer,
18                                                  ImporterHost* host)
19     : writer_(writer),
20       host_(host) {
21 }
22 
AddBookmarkEntries(const std::vector<ProfileWriter::BookmarkEntry> & bookmarks,const string16 & first_folder_name,int options)23 void InProcessImporterBridge::AddBookmarkEntries(
24     const std::vector<ProfileWriter::BookmarkEntry>& bookmarks,
25     const string16& first_folder_name,
26     int options) {
27   BrowserThread::PostTask(
28       BrowserThread::UI, FROM_HERE,
29       NewRunnableMethod(
30           writer_, &ProfileWriter::AddBookmarkEntry, bookmarks,
31           first_folder_name, options));
32 }
33 
AddHomePage(const GURL & home_page)34 void InProcessImporterBridge::AddHomePage(const GURL &home_page) {
35   BrowserThread::PostTask(
36       BrowserThread::UI, FROM_HERE,
37       NewRunnableMethod(writer_, &ProfileWriter::AddHomepage, home_page));
38 }
39 
40 #if defined(OS_WIN)
AddIE7PasswordInfo(const IE7PasswordInfo & password_info)41 void InProcessImporterBridge::AddIE7PasswordInfo(
42     const IE7PasswordInfo& password_info) {
43   BrowserThread::PostTask(
44       BrowserThread::UI, FROM_HERE,
45       NewRunnableMethod(writer_, &ProfileWriter::AddIE7PasswordInfo,
46       password_info));
47 }
48 #endif  // OS_WIN
49 
SetFavicons(const std::vector<history::ImportedFaviconUsage> & favicons)50 void InProcessImporterBridge::SetFavicons(
51     const std::vector<history::ImportedFaviconUsage>& favicons) {
52   BrowserThread::PostTask(
53       BrowserThread::UI, FROM_HERE,
54       NewRunnableMethod(writer_, &ProfileWriter::AddFavicons, favicons));
55 }
56 
SetHistoryItems(const std::vector<history::URLRow> & rows,history::VisitSource visit_source)57 void InProcessImporterBridge::SetHistoryItems(
58     const std::vector<history::URLRow> &rows,
59     history::VisitSource visit_source) {
60   BrowserThread::PostTask(
61       BrowserThread::UI, FROM_HERE,
62       NewRunnableMethod(writer_, &ProfileWriter::AddHistoryPage,
63                         rows, visit_source));
64 }
65 
SetKeywords(const std::vector<TemplateURL * > & template_urls,int default_keyword_index,bool unique_on_host_and_path)66 void InProcessImporterBridge::SetKeywords(
67     const std::vector<TemplateURL*>& template_urls,
68     int default_keyword_index,
69     bool unique_on_host_and_path) {
70   BrowserThread::PostTask(
71       BrowserThread::UI, FROM_HERE,
72       NewRunnableMethod(
73           writer_, &ProfileWriter::AddKeywords, template_urls,
74           default_keyword_index, unique_on_host_and_path));
75 }
76 
SetPasswordForm(const webkit_glue::PasswordForm & form)77 void InProcessImporterBridge::SetPasswordForm(
78     const webkit_glue::PasswordForm& form) {
79   LOG(ERROR) << "InProcessImporterBridge::SetPasswordForm";
80   BrowserThread::PostTask(
81       BrowserThread::UI, FROM_HERE,
82       NewRunnableMethod(writer_, &ProfileWriter::AddPasswordForm, form));
83 }
84 
NotifyStarted()85 void InProcessImporterBridge::NotifyStarted() {
86   BrowserThread::PostTask(
87       BrowserThread::UI, FROM_HERE,
88       NewRunnableMethod(host_, &ImporterHost::NotifyImportStarted));
89 }
90 
NotifyItemStarted(importer::ImportItem item)91 void InProcessImporterBridge::NotifyItemStarted(importer::ImportItem item) {
92   BrowserThread::PostTask(
93       BrowserThread::UI, FROM_HERE,
94       NewRunnableMethod(host_, &ImporterHost::NotifyImportItemStarted, item));
95 }
96 
NotifyItemEnded(importer::ImportItem item)97 void InProcessImporterBridge::NotifyItemEnded(importer::ImportItem item) {
98   BrowserThread::PostTask(
99       BrowserThread::UI, FROM_HERE,
100       NewRunnableMethod(host_, &ImporterHost::NotifyImportItemEnded, item));
101 }
102 
NotifyEnded()103 void InProcessImporterBridge::NotifyEnded() {
104   BrowserThread::PostTask(
105       BrowserThread::UI, FROM_HERE,
106       NewRunnableMethod(host_, &ImporterHost::NotifyImportEnded));
107 }
108 
GetLocalizedString(int message_id)109 string16 InProcessImporterBridge::GetLocalizedString(int message_id) {
110   return l10n_util::GetStringUTF16(message_id);
111 }
112 
~InProcessImporterBridge()113 InProcessImporterBridge::~InProcessImporterBridge() {}
114