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

Unified Diff: components/offline_pages/offline_page_metadata_store_impl.cc

Issue 1694863003: Refactor the offline page storage to include client namespace and id. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address changes. Created 4 years, 10 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: components/offline_pages/offline_page_metadata_store_impl.cc
diff --git a/components/offline_pages/offline_page_metadata_store_impl.cc b/components/offline_pages/offline_page_metadata_store_impl.cc
index 52620639a023ea8e0b9a0370e1d79ec91727804f..dd0509141c4f431bb9dd7d5960e542ebcc76a7eb 100644
--- a/components/offline_pages/offline_page_metadata_store_impl.cc
+++ b/components/offline_pages/offline_page_metadata_store_impl.cc
@@ -19,6 +19,7 @@
#include "build/build_config.h"
#include "components/leveldb_proto/proto_database_impl.h"
#include "components/offline_pages/offline_page_item.h"
+#include "components/offline_pages/offline_page_model.h"
#include "components/offline_pages/proto/offline_pages.pb.h"
#include "third_party/leveldatabase/env_chromium.h"
#include "third_party/leveldatabase/src/include/leveldb/db.h"
@@ -41,7 +42,9 @@ void OfflinePageItemToEntry(const OfflinePageItem& item,
offline_pages::OfflinePageEntry* item_proto) {
DCHECK(item_proto);
item_proto->set_url(item.url.spec());
- item_proto->set_bookmark_id(item.bookmark_id);
+ // TODO(bburns): switch this to offline id when we stop passing bookmark
+ // id down.
+ item_proto->set_deprecated_bookmark_id(item.offline_id);
item_proto->set_version(item.version);
std::string path_string;
#if defined(OS_POSIX)
@@ -56,17 +59,19 @@ void OfflinePageItemToEntry(const OfflinePageItem& item,
item_proto->set_access_count(item.access_count);
item_proto->set_flags(
static_cast<::offline_pages::OfflinePageEntry_Flags>(item.flags));
+ item_proto->set_client_id_name_space(item.client_id.name_space);
+ item_proto->set_client_id(item.client_id.id);
}
bool OfflinePageItemFromEntry(const offline_pages::OfflinePageEntry& item_proto,
OfflinePageItem* item) {
DCHECK(item);
- if (!item_proto.has_url() || !item_proto.has_bookmark_id() ||
+ if (!item_proto.has_url() || !item_proto.has_offline_id() ||
!item_proto.has_version() || !item_proto.has_file_path()) {
return false;
}
item->url = GURL(item_proto.url());
- item->bookmark_id = item_proto.bookmark_id();
+ item->offline_id = item_proto.offline_id();
item->version = item_proto.version();
#if defined(OS_POSIX)
item->file_path = base::FilePath(item_proto.file_path());
@@ -90,6 +95,19 @@ bool OfflinePageItemFromEntry(const offline_pages::OfflinePageEntry& item_proto,
if (item_proto.has_flags()) {
item->flags = static_cast<OfflinePageItem::Flags>(item_proto.flags());
}
+ item->client_id.name_space = item_proto.client_id_name_space();
+ item->client_id.id = item_proto.client_id();
+
+ // Legacy storage.
+ if (item->client_id.name_space == "" &&
+ item_proto.has_deprecated_bookmark_id()) {
+ item->client_id.name_space = offline_pages::BOOKMARK_NAMESPACE;
+ item->client_id.id =
+ base::Int64ToString(item_proto.deprecated_bookmark_id());
+ if (item->offline_id == 0) {
+ item->offline_id = item_proto.deprecated_bookmark_id();
+ }
+ }
return true;
}
@@ -186,23 +204,22 @@ void OfflinePageMetadataStoreImpl::AddOrUpdateOfflinePage(
OfflinePageEntry offline_page_proto;
OfflinePageItemToEntry(offline_page_item, &offline_page_proto);
- entries_to_save->push_back(
- std::make_pair(base::Int64ToString(offline_page_item.bookmark_id),
- offline_page_proto));
+ entries_to_save->push_back(std::make_pair(
+ base::Int64ToString(offline_page_item.offline_id), offline_page_proto));
UpdateEntries(std::move(entries_to_save), std::move(keys_to_remove),
callback);
}
void OfflinePageMetadataStoreImpl::RemoveOfflinePages(
- const std::vector<int64_t>& bookmark_ids,
+ const std::vector<int64_t>& offline_ids,
const UpdateCallback& callback) {
scoped_ptr<ProtoDatabase<OfflinePageEntry>::KeyEntryVector> entries_to_save(
new ProtoDatabase<OfflinePageEntry>::KeyEntryVector());
scoped_ptr<std::vector<std::string>> keys_to_remove(
new std::vector<std::string>());
- for (int64_t id : bookmark_ids)
+ for (int64_t id : offline_ids)
keys_to_remove->push_back(base::Int64ToString(id));
UpdateEntries(std::move(entries_to_save), std::move(keys_to_remove),

Powered by Google App Engine
This is Rietveld 408576698