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

Unified Diff: chrome/browser/history/android/android_provider_backend.cc

Issue 10825214: AndroidProvider: Add history for bookmarks if it doesn't exist. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/history/android/android_provider_backend.cc
diff --git a/chrome/browser/history/android/android_provider_backend.cc b/chrome/browser/history/android/android_provider_backend.cc
index 9f2d9255e489dd7e1ef01527f5231f564ad7ccc1..a0c6ff5b9f35ca051e36834e384e7999201a50ec 100644
--- a/chrome/browser/history/android/android_provider_backend.cc
+++ b/chrome/browser/history/android/android_provider_backend.cc
@@ -176,7 +176,7 @@ AndroidURLID AndroidProviderBackend::InsertHistoryAndBookmark(
ScopedTransaction transaction(history_db_, thumbnail_db_);
- AndroidURLID id = InsertHistoryAndBookmark(values, &notifications);
+ AndroidURLID id = InsertHistoryAndBookmark(values, &notifications, true);
if (id) {
transaction.Commit();
BroadcastNotifications(notifications);
@@ -357,11 +357,12 @@ bool AndroidProviderBackend::UpdateHistoryAndBookmarks(
AndroidURLID AndroidProviderBackend::InsertHistoryAndBookmark(
const HistoryAndBookmarkRow& values,
- HistoryNotifications* notifications) {
+ HistoryNotifications* notifications,
+ bool update_tables) {
if (!IsHistoryAndBookmarkRowValid(values))
return false;
- if (!EnsureInitializedAndUpdated())
+ if (update_tables && !EnsureInitializedAndUpdated())
return 0;
DCHECK(values.is_value_set_explicitly(HistoryAndBookmarkRow::URL));
@@ -471,10 +472,13 @@ bool AndroidProviderBackend::DeleteHistory(
for (std::vector<HistoryAndBookmarkRow>::const_iterator i = bookmarks.begin();
i != bookmarks.end(); ++i) {
- if (!InsertHistoryAndBookmark(*i, notifications))
+ // Don't update the tables, otherwise, the bookmarks will be added to
+ // database during UpdateBookmark(), then the insertion will fail.
+ // We can't rely on UpdateBookmark() to insert the bookmarks into history
+ // database as the raw_url will be lost.
+ if (!InsertHistoryAndBookmark(*i, notifications, false))
return false;
}
-
return true;
}
@@ -759,11 +763,21 @@ bool AndroidProviderBackend::UpdateBookmarks() {
for (std::vector<BookmarkService::URLAndTitle>::const_iterator i =
bookmarks.begin(); i != bookmarks.end(); ++i) {
URLID url_id = history_db_->GetRowForURL(i->url, NULL);
- if (url_id == 0)
- // TODO(michaelbai): Add a row to url and android_url table as the
- // bookmark could be added manually by user or insertted by sync.
- continue;
-
+ if (url_id == 0) {
+ URLRow url_row(i->url);
+ url_row.set_title(i->title);
+ 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.
+ url_id = history_db_->AddURL(url_row);
+ if (url_id == 0) {
+ LOG(ERROR) << "Can not add url for the new bookmark";
+ return false;
+ }
+ if (!history_db_->AddAndroidURLRow(i->url.spec(), url_id))
+ return false;
+ if (!history_db_->AddBookmarkCacheRow(Time::UnixEpoch(),
+ Time::UnixEpoch(), url_id))
+ return false;
+ }
url_ids.push_back(url_id);
}

Powered by Google App Engine
This is Rietveld 408576698