diff options
-rw-r--r-- | chrome/browser/gtk/import_progress_dialog_gtk.cc | 14 | ||||
-rw-r--r-- | chrome/browser/history/history_backend.cc | 31 | ||||
-rw-r--r-- | chrome/browser/history/history_backend.h | 1 | ||||
-rw-r--r-- | chrome/browser/history/history_backend_unittest.cc | 62 | ||||
-rw-r--r-- | chrome/browser/importer/firefox2_importer.cc | 15 | ||||
-rw-r--r-- | chrome/browser/importer/firefox3_importer.cc | 15 | ||||
-rw-r--r-- | chrome/browser/importer/ie_importer.cc | 10 | ||||
-rw-r--r-- | chrome/browser/importer/safari_importer.mm | 10 | ||||
-rw-r--r-- | chrome/browser/views/importing_progress_view.cc | 12 |
9 files changed, 130 insertions, 40 deletions
diff --git a/chrome/browser/gtk/import_progress_dialog_gtk.cc b/chrome/browser/gtk/import_progress_dialog_gtk.cc index 28ec1d8..beb897c 100644 --- a/chrome/browser/gtk/import_progress_dialog_gtk.cc +++ b/chrome/browser/gtk/import_progress_dialog_gtk.cc @@ -140,6 +140,13 @@ ImportProgressDialogGtk::ImportProgressDialogGtk(const string16& source_profile, GtkWidget* item_box = gtk_vbox_new(FALSE, gtk_util::kControlSpacing); + if (items_ & HISTORY) { + history_ = gtk_label_new( + l10n_util::GetStringUTF8(IDS_IMPORT_PROGRESS_STATUS_HISTORY).c_str()); + gtk_misc_set_alignment(GTK_MISC(history_), 0, 0.5); + gtk_box_pack_start(GTK_BOX(item_box), history_, FALSE, FALSE, 0); + } + if (items_ & FAVORITES) { bookmarks_ = gtk_label_new( l10n_util::GetStringUTF8(IDS_IMPORT_PROGRESS_STATUS_BOOKMARKS).c_str()); @@ -161,13 +168,6 @@ ImportProgressDialogGtk::ImportProgressDialogGtk(const string16& source_profile, gtk_box_pack_start(GTK_BOX(item_box), passwords_, FALSE, FALSE, 0); } - if (items_ & HISTORY) { - history_ = gtk_label_new( - l10n_util::GetStringUTF8(IDS_IMPORT_PROGRESS_STATUS_HISTORY).c_str()); - gtk_misc_set_alignment(GTK_MISC(history_), 0, 0.5); - gtk_box_pack_start(GTK_BOX(item_box), history_, FALSE, FALSE, 0); - } - gtk_box_pack_start(GTK_BOX(control_group), gtk_util::IndentWidget(item_box), FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(content_area), control_group, FALSE, FALSE, 0); diff --git a/chrome/browser/history/history_backend.cc b/chrome/browser/history/history_backend.cc index 0d01496..cedc28b 100644 --- a/chrome/browser/history/history_backend.cc +++ b/chrome/browser/history/history_backend.cc @@ -1433,16 +1433,33 @@ void HistoryBackend::SetImportedFavicons( } // Save the mapping from all the URLs to the favicon. + BookmarkService* bookmark_service = GetBookmarkService(); for (std::set<GURL>::const_iterator url = favicon_usage[i].urls.begin(); url != favicon_usage[i].urls.end(); ++url) { URLRow url_row; - if (!db_->GetRowForURL(*url, &url_row) || - url_row.favicon_id() == favicon_id) - continue; // Don't set favicons for unknown URLs. - url_row.set_favicon_id(favicon_id); - db_->UpdateURLRow(url_row.id(), url_row); - - favicons_changed.insert(*url); + if (!db_->GetRowForURL(*url, &url_row)) { + // If the URL is present as a bookmark, add the url in history to + // save the favicon mapping. This will match with what history db does + // for regular bookmarked URLs with favicons - when history db is + // cleaned, we keep an entry in the db with 0 visits as long as that + // url is bookmarked. + if (bookmark_service && bookmark_service_->IsBookmarked(*url)) { + URLRow url_info(*url); + url_info.set_visit_count(0); + url_info.set_typed_count(0); + url_info.set_last_visit(base::Time()); + url_info.set_hidden(false); + url_info.set_favicon_id(favicon_id); + db_->AddURL(url_info); + favicons_changed.insert(*url); + } + } else if (url_row.favicon_id() == 0) { + // URL is present in history, update the favicon *only* if it + // is not set already. + url_row.set_favicon_id(favicon_id); + db_->UpdateURLRow(url_row.id(), url_row); + favicons_changed.insert(*url); + } } } diff --git a/chrome/browser/history/history_backend.h b/chrome/browser/history/history_backend.h index 36b5193..4effaca 100644 --- a/chrome/browser/history/history_backend.h +++ b/chrome/browser/history/history_backend.h @@ -276,6 +276,7 @@ class HistoryBackend : public base::RefCountedThreadSafe<HistoryBackend>, friend class CommitLaterTask; // The commit task needs to call Commit(). friend class HistoryTest; // So the unit tests can poke our innards. FRIEND_TEST(HistoryBackendTest, DeleteAll); + FRIEND_TEST(HistoryBackendTest, ImportedFaviconsTest); FRIEND_TEST(HistoryBackendTest, URLsNoLongerBookmarked); friend class ::TestingProfile; diff --git a/chrome/browser/history/history_backend_unittest.cc b/chrome/browser/history/history_backend_unittest.cc index 62a518d..9f14f1d 100644 --- a/chrome/browser/history/history_backend_unittest.cc +++ b/chrome/browser/history/history_backend_unittest.cc @@ -501,4 +501,66 @@ TEST_F(HistoryBackendTest, ClientRedirect) { EXPECT_TRUE(transition2 & PageTransition::CHAIN_END); } +TEST_F(HistoryBackendTest, ImportedFaviconsTest) { + // Setup test data - two Urls in the history, one with favicon assigned and + // one without. + GURL favicon_url1("http://www.google.com/favicon.ico"); + FavIconID favicon1 = backend_->thumbnail_db_->AddFavIcon(favicon_url1); + std::vector<unsigned char> data; + data.push_back('1'); + EXPECT_TRUE(backend_->thumbnail_db_->SetFavIcon(favicon1, data, Time::Now())); + URLRow row1(GURL("http://www.google.com/")); + row1.set_favicon_id(favicon1); + row1.set_visit_count(1); + row1.set_last_visit(Time::Now()); + URLRow row2(GURL("http://news.google.com/")); + row2.set_visit_count(1); + row2.set_last_visit(Time::Now()); + std::vector<URLRow> rows; + rows.push_back(row1); + rows.push_back(row2); + backend_->AddPagesWithDetails(rows); + URLRow url_row1, url_row2; + EXPECT_FALSE(backend_->db_->GetRowForURL(row1.url(), &url_row1) == 0); + EXPECT_FALSE(backend_->db_->GetRowForURL(row2.url(), &url_row2) == 0); + EXPECT_FALSE(url_row1.favicon_id() == 0); + EXPECT_TRUE(url_row2.favicon_id() == 0); + + // Now provide one imported favicon for both URLs already in the registry. + // The new favicon should only be used with the URL that doesn't already have + // a favicon. + std::vector<history::ImportedFavIconUsage> favicons; + history::ImportedFavIconUsage favicon; + favicon.favicon_url = GURL("http://news.google.com/favicon.ico"); + favicon.png_data.push_back('2'); + favicon.urls.insert(row1.url()); + favicon.urls.insert(row2.url()); + favicons.push_back(favicon); + backend_->SetImportedFavicons(favicons); + EXPECT_FALSE(backend_->db_->GetRowForURL(row1.url(), &url_row1) == 0); + EXPECT_FALSE(backend_->db_->GetRowForURL(row2.url(), &url_row2) == 0); + EXPECT_FALSE(url_row1.favicon_id() == 0); + EXPECT_FALSE(url_row2.favicon_id() == 0); + EXPECT_FALSE(url_row1.favicon_id() == url_row2.favicon_id()); + + // A URL should not be added to history (to store favicon), if + // the URL is not bookmarked. + GURL url3("http://mail.google.com"); + favicons.clear(); + favicon.favicon_url = GURL("http://mail.google.com/favicon.ico"); + favicon.png_data.push_back('3'); + favicon.urls.insert(url3); + favicons.push_back(favicon); + backend_->SetImportedFavicons(favicons); + URLRow url_row3; + EXPECT_TRUE(backend_->db_->GetRowForURL(url3, &url_row3) == 0); + + // If the URL is bookmarked, it should get added to history with 0 visits. + bookmark_model_.AddURL(bookmark_model_.GetBookmarkBarNode(), 0, + std::wstring(), url3); + backend_->SetImportedFavicons(favicons); + EXPECT_FALSE(backend_->db_->GetRowForURL(url3, &url_row3) == 0); + EXPECT_TRUE(url_row3.visit_count() == 0); +} + } // namespace history diff --git a/chrome/browser/importer/firefox2_importer.cc b/chrome/browser/importer/firefox2_importer.cc index 95d7eb9..3a38b2f 100644 --- a/chrome/browser/importer/firefox2_importer.cc +++ b/chrome/browser/importer/firefox2_importer.cc @@ -49,6 +49,16 @@ void Firefox2Importer::StartImport(ProfileInfo profile_info, NotifyStarted(); if ((items & HOME_PAGE) && !cancelled()) ImportHomepage(); // Doesn't have a UI item. + + // Note history should be imported before bookmarks because bookmark import + // will also import favicons and we store favicon for a URL only if the URL + // exist in history or bookmarks. + if ((items & HISTORY) && !cancelled()) { + NotifyItemStarted(HISTORY); + ImportHistory(); + NotifyItemEnded(HISTORY); + } + if ((items & FAVORITES) && !cancelled()) { NotifyItemStarted(FAVORITES); ImportBookmarks(); @@ -64,11 +74,6 @@ void Firefox2Importer::StartImport(ProfileInfo profile_info, ImportPasswords(); NotifyItemEnded(PASSWORDS); } - if ((items & HISTORY) && !cancelled()) { - NotifyItemStarted(HISTORY); - ImportHistory(); - NotifyItemEnded(HISTORY); - } NotifyEnded(); } diff --git a/chrome/browser/importer/firefox3_importer.cc b/chrome/browser/importer/firefox3_importer.cc index 0a951ad..a509f55 100644 --- a/chrome/browser/importer/firefox3_importer.cc +++ b/chrome/browser/importer/firefox3_importer.cc @@ -38,6 +38,16 @@ void Firefox3Importer::StartImport(ProfileInfo profile_info, NotifyStarted(); if ((items & HOME_PAGE) && !cancelled()) ImportHomepage(); // Doesn't have a UI item. + + // Note history should be imported before bookmarks because bookmark import + // will also import favicons and we store favicon for a URL only if the URL + // exist in history or bookmarks. + if ((items & HISTORY) && !cancelled()) { + NotifyItemStarted(HISTORY); + ImportHistory(); + NotifyItemEnded(HISTORY); + } + if ((items & FAVORITES) && !cancelled()) { NotifyItemStarted(FAVORITES); ImportBookmarks(); @@ -53,11 +63,6 @@ void Firefox3Importer::StartImport(ProfileInfo profile_info, ImportPasswords(); NotifyItemEnded(PASSWORDS); } - if ((items & HISTORY) && !cancelled()) { - NotifyItemStarted(HISTORY); - ImportHistory(); - NotifyItemEnded(HISTORY); - } NotifyEnded(); } diff --git a/chrome/browser/importer/ie_importer.cc b/chrome/browser/importer/ie_importer.cc index 2d979ad..9a2606b 100644 --- a/chrome/browser/importer/ie_importer.cc +++ b/chrome/browser/importer/ie_importer.cc @@ -79,6 +79,11 @@ void IEImporter::StartImport(ProfileInfo profile_info, if ((items & HOME_PAGE) && !cancelled()) ImportHomepage(); // Doesn't have a UI item. // The order here is important! + if ((items & HISTORY) && !cancelled()) { + NotifyItemStarted(HISTORY); + ImportHistory(); + NotifyItemEnded(HISTORY); + } if ((items & FAVORITES) && !cancelled()) { NotifyItemStarted(FAVORITES); ImportFavorites(); @@ -98,11 +103,6 @@ void IEImporter::StartImport(ProfileInfo profile_info, ImportPasswordsIE7(); NotifyItemEnded(PASSWORDS); } - if ((items & HISTORY) && !cancelled()) { - NotifyItemStarted(HISTORY); - ImportHistory(); - NotifyItemEnded(HISTORY); - } NotifyEnded(); } diff --git a/chrome/browser/importer/safari_importer.mm b/chrome/browser/importer/safari_importer.mm index 1f839a7..e862b97 100644 --- a/chrome/browser/importer/safari_importer.mm +++ b/chrome/browser/importer/safari_importer.mm @@ -55,6 +55,11 @@ void SafariImporter::StartImport(ProfileInfo profile_info, NotifyStarted(); if ((items & HOME_PAGE) && !cancelled()) ImportHomepage(); // Doesn't have a UI item. + if ((items & HISTORY) && !cancelled()) { + NotifyItemStarted(HISTORY); + ImportHistory(); + NotifyItemEnded(HISTORY); + } if ((items & FAVORITES) && !cancelled()) { NotifyItemStarted(FAVORITES); ImportBookmarks(); @@ -65,11 +70,6 @@ void SafariImporter::StartImport(ProfileInfo profile_info, ImportPasswords(); NotifyItemEnded(PASSWORDS); } - if ((items & HISTORY) && !cancelled()) { - NotifyItemStarted(HISTORY); - ImportHistory(); - NotifyItemEnded(HISTORY); - } NotifyEnded(); } diff --git a/chrome/browser/views/importing_progress_view.cc b/chrome/browser/views/importing_progress_view.cc index d2545f6..ed58f9c 100644 --- a/chrome/browser/views/importing_progress_view.cc +++ b/chrome/browser/views/importing_progress_view.cc @@ -254,6 +254,12 @@ void ImportingProgressView::InitControlLayout() { layout->AddView(label_info_); layout->AddPaddingRow(0, kUnrelatedControlVerticalSpacing); + if (items_ & HISTORY) { + layout->StartRow(0, double_column_view_set_id); + layout->AddView(state_history_.get()); + layout->AddView(label_history_.get()); + layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); + } if (items_ & FAVORITES && !bookmarks_import_) { layout->StartRow(0, double_column_view_set_id); layout->AddView(state_bookmarks_.get()); @@ -272,12 +278,6 @@ void ImportingProgressView::InitControlLayout() { layout->AddView(label_passwords_.get()); layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); } - if (items_ & HISTORY) { - layout->StartRow(0, double_column_view_set_id); - layout->AddView(state_history_.get()); - layout->AddView(label_history_.get()); - layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); - } if (items_ & COOKIES) { layout->StartRow(0, double_column_view_set_id); layout->AddView(state_cookies_.get()); |