Chromium Code Reviews| 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/history/android/android_provider_backend.h" | 5 #include "chrome/browser/history/android/android_provider_backend.h" |
| 6 | 6 |
| 7 #include "base/i18n/case_conversion.h" | 7 #include "base/i18n/case_conversion.h" |
| 8 #include "chrome/browser/bookmarks/bookmark_service.h" | 8 #include "chrome/browser/bookmarks/bookmark_service.h" |
| 9 #include "chrome/common/chrome_notification_types.h" | 9 #include "chrome/common/chrome_notification_types.h" |
| 10 #include "chrome/browser/history/android/android_time.h" | 10 #include "chrome/browser/history/android/android_time.h" |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 169 BroadcastNotifications(notifications); | 169 BroadcastNotifications(notifications); |
| 170 return true; | 170 return true; |
| 171 } | 171 } |
| 172 | 172 |
| 173 AndroidURLID AndroidProviderBackend::InsertHistoryAndBookmark( | 173 AndroidURLID AndroidProviderBackend::InsertHistoryAndBookmark( |
| 174 const HistoryAndBookmarkRow& values) { | 174 const HistoryAndBookmarkRow& values) { |
| 175 HistoryNotifications notifications; | 175 HistoryNotifications notifications; |
| 176 | 176 |
| 177 ScopedTransaction transaction(history_db_, thumbnail_db_); | 177 ScopedTransaction transaction(history_db_, thumbnail_db_); |
| 178 | 178 |
| 179 AndroidURLID id = InsertHistoryAndBookmark(values, ¬ifications); | 179 AndroidURLID id = InsertHistoryAndBookmark(values, ¬ifications, true); |
| 180 if (id) { | 180 if (id) { |
| 181 transaction.Commit(); | 181 transaction.Commit(); |
| 182 BroadcastNotifications(notifications); | 182 BroadcastNotifications(notifications); |
| 183 return id; | 183 return id; |
| 184 } | 184 } |
| 185 return 0; | 185 return 0; |
| 186 } | 186 } |
| 187 | 187 |
| 188 bool AndroidProviderBackend::DeleteHistoryAndBookmarks( | 188 bool AndroidProviderBackend::DeleteHistoryAndBookmarks( |
| 189 const std::string& selection, | 189 const std::string& selection, |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 350 | 350 |
| 351 if (!favicon->urls.empty()) | 351 if (!favicon->urls.empty()) |
| 352 notifications->push_back(HistoryNotification( | 352 notifications->push_back(HistoryNotification( |
| 353 chrome::NOTIFICATION_FAVICON_CHANGED, favicon.release())); | 353 chrome::NOTIFICATION_FAVICON_CHANGED, favicon.release())); |
| 354 | 354 |
| 355 return true; | 355 return true; |
| 356 } | 356 } |
| 357 | 357 |
| 358 AndroidURLID AndroidProviderBackend::InsertHistoryAndBookmark( | 358 AndroidURLID AndroidProviderBackend::InsertHistoryAndBookmark( |
| 359 const HistoryAndBookmarkRow& values, | 359 const HistoryAndBookmarkRow& values, |
| 360 HistoryNotifications* notifications) { | 360 HistoryNotifications* notifications, |
| 361 bool update_tables) { | |
| 361 if (!IsHistoryAndBookmarkRowValid(values)) | 362 if (!IsHistoryAndBookmarkRowValid(values)) |
| 362 return false; | 363 return false; |
| 363 | 364 |
| 364 if (!EnsureInitializedAndUpdated()) | 365 if (update_tables && !EnsureInitializedAndUpdated()) |
| 365 return 0; | 366 return 0; |
| 366 | 367 |
| 367 DCHECK(values.is_value_set_explicitly(HistoryAndBookmarkRow::URL)); | 368 DCHECK(values.is_value_set_explicitly(HistoryAndBookmarkRow::URL)); |
| 368 // Make a copy of values as we need change it during insert. | 369 // Make a copy of values as we need change it during insert. |
| 369 HistoryAndBookmarkRow row = values; | 370 HistoryAndBookmarkRow row = values; |
| 370 for (std::vector<SQLHandler*>::iterator i = | 371 for (std::vector<SQLHandler*>::iterator i = |
| 371 sql_handlers_.begin(); i != sql_handlers_.end(); ++i) { | 372 sql_handlers_.begin(); i != sql_handlers_.end(); ++i) { |
| 372 if (!(*i)->Insert(&row)) | 373 if (!(*i)->Insert(&row)) |
| 373 return 0; | 374 return 0; |
| 374 } | 375 } |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 464 bookmarks.push_back(row); | 465 bookmarks.push_back(row); |
| 465 } | 466 } |
| 466 } | 467 } |
| 467 | 468 |
| 468 // Don't delete the bookmark from bookmark model when deleting the history. | 469 // Don't delete the bookmark from bookmark model when deleting the history. |
| 469 if (!DeleteHistoryInternal(ids_set, false, notifications)) | 470 if (!DeleteHistoryInternal(ids_set, false, notifications)) |
| 470 return false; | 471 return false; |
| 471 | 472 |
| 472 for (std::vector<HistoryAndBookmarkRow>::const_iterator i = bookmarks.begin(); | 473 for (std::vector<HistoryAndBookmarkRow>::const_iterator i = bookmarks.begin(); |
| 473 i != bookmarks.end(); ++i) { | 474 i != bookmarks.end(); ++i) { |
| 474 if (!InsertHistoryAndBookmark(*i, notifications)) | 475 // Don't update the tables, otherwise, the bookmarks will be added to |
| 476 // database during UpdateBookmark(), then the insertion will fail. | |
| 477 // We can't rely on UpdateBookmark() to insert the bookmarks into history | |
| 478 // database as the raw_url will be lost. | |
| 479 if (!InsertHistoryAndBookmark(*i, notifications, false)) | |
| 475 return false; | 480 return false; |
| 476 } | 481 } |
| 477 | |
| 478 return true; | 482 return true; |
| 479 } | 483 } |
| 480 | 484 |
| 481 AndroidStatement* AndroidProviderBackend::QuerySearchTerms( | 485 AndroidStatement* AndroidProviderBackend::QuerySearchTerms( |
| 482 const std::vector<SearchRow::ColumnID>& projections, | 486 const std::vector<SearchRow::ColumnID>& projections, |
| 483 const std::string& selection, | 487 const std::string& selection, |
| 484 const std::vector<string16>& selection_args, | 488 const std::vector<string16>& selection_args, |
| 485 const std::string& sort_order) { | 489 const std::string& sort_order) { |
| 486 if (projections.empty()) | 490 if (projections.empty()) |
| 487 return NULL; | 491 return NULL; |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 752 std::vector<BookmarkService::URLAndTitle> bookmarks; | 756 std::vector<BookmarkService::URLAndTitle> bookmarks; |
| 753 bookmark_service_->GetBookmarks(&bookmarks); | 757 bookmark_service_->GetBookmarks(&bookmarks); |
| 754 | 758 |
| 755 if (bookmarks.empty()) | 759 if (bookmarks.empty()) |
| 756 return true; | 760 return true; |
| 757 | 761 |
| 758 std::vector<URLID> url_ids; | 762 std::vector<URLID> url_ids; |
| 759 for (std::vector<BookmarkService::URLAndTitle>::const_iterator i = | 763 for (std::vector<BookmarkService::URLAndTitle>::const_iterator i = |
| 760 bookmarks.begin(); i != bookmarks.end(); ++i) { | 764 bookmarks.begin(); i != bookmarks.end(); ++i) { |
| 761 URLID url_id = history_db_->GetRowForURL(i->url, NULL); | 765 URLID url_id = history_db_->GetRowForURL(i->url, NULL); |
| 762 if (url_id == 0) | 766 if (url_id == 0) { |
| 763 // TODO(michaelbai): Add a row to url and android_url table as the | 767 URLRow url_row(i->url); |
| 764 // bookmark could be added manually by user or insertted by sync. | 768 url_row.set_title(i->title); |
| 765 continue; | 769 url_row.set_last_visit(Time::UnixEpoch()); |
|
sky
2012/08/07 18:31:43
You sure you don't want a time of now? And do you
michaelbai
2012/08/07 19:21:32
- Set the time to Time::UnixEpoch() consistent wit
sky
2012/08/07 20:43:08
Add a comment why then.
| |
| 766 | 770 url_id = history_db_->AddURL(url_row); |
| 771 if (url_id == 0) { | |
| 772 LOG(ERROR) << "Can not add url for the new bookmark"; | |
| 773 return false; | |
| 774 } | |
| 775 if (!history_db_->AddAndroidURLRow(i->url.spec(), url_id)) | |
| 776 return false; | |
| 777 if (!history_db_->AddBookmarkCacheRow(Time::UnixEpoch(), | |
| 778 Time::UnixEpoch(), url_id)) | |
| 779 return false; | |
| 780 } | |
| 767 url_ids.push_back(url_id); | 781 url_ids.push_back(url_id); |
| 768 } | 782 } |
| 769 | 783 |
| 770 return history_db_->MarkURLsAsBookmarked(url_ids); | 784 return history_db_->MarkURLsAsBookmarked(url_ids); |
| 771 } | 785 } |
| 772 | 786 |
| 773 bool AndroidProviderBackend::UpdateFavicon() { | 787 bool AndroidProviderBackend::UpdateFavicon() { |
| 774 ThumbnailDatabase::IconMappingEnumerator enumerator; | 788 ThumbnailDatabase::IconMappingEnumerator enumerator; |
| 775 if (!thumbnail_db_->InitIconMappingEnumerator(FAVICON, &enumerator)) | 789 if (!thumbnail_db_->InitIconMappingEnumerator(FAVICON, &enumerator)) |
| 776 return false; | 790 return false; |
| (...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1147 return false; | 1161 return false; |
| 1148 | 1162 |
| 1149 if (!history_db_->SetKeywordSearchTermsForURL(bookmark_row.url_id(), | 1163 if (!history_db_->SetKeywordSearchTermsForURL(bookmark_row.url_id(), |
| 1150 values.template_url_id(), values.search_term())) | 1164 values.template_url_id(), values.search_term())) |
| 1151 return false; | 1165 return false; |
| 1152 } | 1166 } |
| 1153 return true; | 1167 return true; |
| 1154 } | 1168 } |
| 1155 | 1169 |
| 1156 } // namespace history | 1170 } // namespace history |
| OLD | NEW |