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

Side by Side 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 comments. 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "components/offline_pages/offline_page_metadata_store_impl.h" 5 #include "components/offline_pages/offline_page_metadata_store_impl.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 23 matching lines...) Expand all
34 const char kDatabaseUMAClientName[] = "OfflinePageMetadataStore"; 34 const char kDatabaseUMAClientName[] = "OfflinePageMetadataStore";
35 } 35 }
36 36
37 namespace offline_pages { 37 namespace offline_pages {
38 namespace { 38 namespace {
39 39
40 void OfflinePageItemToEntry(const OfflinePageItem& item, 40 void OfflinePageItemToEntry(const OfflinePageItem& item,
41 offline_pages::OfflinePageEntry* item_proto) { 41 offline_pages::OfflinePageEntry* item_proto) {
42 DCHECK(item_proto); 42 DCHECK(item_proto);
43 item_proto->set_url(item.url.spec()); 43 item_proto->set_url(item.url.spec());
44 item_proto->set_bookmark_id(item.bookmark_id); 44 item_proto->set_offline_id(item.offline_id);
45 item_proto->set_version(item.version); 45 item_proto->set_version(item.version);
46 std::string path_string; 46 std::string path_string;
47 #if defined(OS_POSIX) 47 #if defined(OS_POSIX)
48 path_string = item.file_path.value(); 48 path_string = item.file_path.value();
49 #elif defined(OS_WIN) 49 #elif defined(OS_WIN)
50 path_string = base::WideToUTF8(item.file_path.value()); 50 path_string = base::WideToUTF8(item.file_path.value());
51 #endif 51 #endif
52 item_proto->set_file_path(path_string); 52 item_proto->set_file_path(path_string);
53 item_proto->set_file_size(item.file_size); 53 item_proto->set_file_size(item.file_size);
54 item_proto->set_creation_time(item.creation_time.ToInternalValue()); 54 item_proto->set_creation_time(item.creation_time.ToInternalValue());
55 item_proto->set_last_access_time(item.last_access_time.ToInternalValue()); 55 item_proto->set_last_access_time(item.last_access_time.ToInternalValue());
56 item_proto->set_access_count(item.access_count); 56 item_proto->set_access_count(item.access_count);
57 item_proto->set_flags( 57 item_proto->set_flags(
58 static_cast<::offline_pages::OfflinePageEntry_Flags>(item.flags)); 58 static_cast<::offline_pages::OfflinePageEntry_Flags>(item.flags));
59 item_proto->set_client_id_namespace(item.client_id_namespace);
60 item_proto->set_client_id(item.client_id);
59 } 61 }
60 62
61 bool OfflinePageItemFromEntry(const offline_pages::OfflinePageEntry& item_proto, 63 bool OfflinePageItemFromEntry(const offline_pages::OfflinePageEntry& item_proto,
62 OfflinePageItem* item) { 64 OfflinePageItem* item) {
63 DCHECK(item); 65 DCHECK(item);
64 if (!item_proto.has_url() || !item_proto.has_bookmark_id() || 66 if (!item_proto.has_url() || !item_proto.has_offline_id() ||
65 !item_proto.has_version() || !item_proto.has_file_path()) { 67 !item_proto.has_version() || !item_proto.has_file_path()) {
66 return false; 68 return false;
67 } 69 }
68 item->url = GURL(item_proto.url()); 70 item->url = GURL(item_proto.url());
69 item->bookmark_id = item_proto.bookmark_id(); 71 item->offline_id = item_proto.offline_id();
70 item->version = item_proto.version(); 72 item->version = item_proto.version();
71 #if defined(OS_POSIX) 73 #if defined(OS_POSIX)
72 item->file_path = base::FilePath(item_proto.file_path()); 74 item->file_path = base::FilePath(item_proto.file_path());
73 #elif defined(OS_WIN) 75 #elif defined(OS_WIN)
74 item->file_path = base::FilePath(base::UTF8ToWide(item_proto.file_path())); 76 item->file_path = base::FilePath(base::UTF8ToWide(item_proto.file_path()));
75 #endif 77 #endif
76 if (item_proto.has_file_size()) { 78 if (item_proto.has_file_size()) {
77 item->file_size = item_proto.file_size(); 79 item->file_size = item_proto.file_size();
78 } 80 }
79 if (item_proto.has_creation_time()) { 81 if (item_proto.has_creation_time()) {
80 item->creation_time = 82 item->creation_time =
81 base::Time::FromInternalValue(item_proto.creation_time()); 83 base::Time::FromInternalValue(item_proto.creation_time());
82 } 84 }
83 if (item_proto.has_last_access_time()) { 85 if (item_proto.has_last_access_time()) {
84 item->last_access_time = 86 item->last_access_time =
85 base::Time::FromInternalValue(item_proto.last_access_time()); 87 base::Time::FromInternalValue(item_proto.last_access_time());
86 } 88 }
87 if (item_proto.has_access_count()) { 89 if (item_proto.has_access_count()) {
88 item->access_count = item_proto.access_count(); 90 item->access_count = item_proto.access_count();
89 } 91 }
90 if (item_proto.has_flags()) { 92 if (item_proto.has_flags()) {
91 item->flags = static_cast<OfflinePageItem::Flags>(item_proto.flags()); 93 item->flags = static_cast<OfflinePageItem::Flags>(item_proto.flags());
92 } 94 }
95 item->client_id_namespace = item_proto.client_id_namespace();
96 item->client_id = item_proto.client_id();
97
98 // Legacy storage.
99 if (item->client_id_namespace == ""
100 && item_proto.deprecated_bookmark_id() != 0) {
101 item->client_id_namespace = "bookmark";
102 item->client_id = base::Int64ToString(item_proto.deprecated_bookmark_id());
103 if (item->offline_id == 0) {
104 item->offline_id = item_proto.deprecated_bookmark_id();
105 }
106 }
93 return true; 107 return true;
94 } 108 }
95 109
96 } // namespace 110 } // namespace
97 111
98 OfflinePageMetadataStoreImpl::OfflinePageMetadataStoreImpl( 112 OfflinePageMetadataStoreImpl::OfflinePageMetadataStoreImpl(
99 scoped_refptr<base::SequencedTaskRunner> background_task_runner, 113 scoped_refptr<base::SequencedTaskRunner> background_task_runner,
100 const base::FilePath& database_dir) 114 const base::FilePath& database_dir)
101 : background_task_runner_(background_task_runner), 115 : background_task_runner_(background_task_runner),
102 database_dir_(database_dir), 116 database_dir_(database_dir),
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 const OfflinePageItem& offline_page_item, 194 const OfflinePageItem& offline_page_item,
181 const UpdateCallback& callback) { 195 const UpdateCallback& callback) {
182 scoped_ptr<ProtoDatabase<OfflinePageEntry>::KeyEntryVector> entries_to_save( 196 scoped_ptr<ProtoDatabase<OfflinePageEntry>::KeyEntryVector> entries_to_save(
183 new ProtoDatabase<OfflinePageEntry>::KeyEntryVector()); 197 new ProtoDatabase<OfflinePageEntry>::KeyEntryVector());
184 scoped_ptr<std::vector<std::string>> keys_to_remove( 198 scoped_ptr<std::vector<std::string>> keys_to_remove(
185 new std::vector<std::string>()); 199 new std::vector<std::string>());
186 200
187 OfflinePageEntry offline_page_proto; 201 OfflinePageEntry offline_page_proto;
188 OfflinePageItemToEntry(offline_page_item, &offline_page_proto); 202 OfflinePageItemToEntry(offline_page_item, &offline_page_proto);
189 entries_to_save->push_back( 203 entries_to_save->push_back(
190 std::make_pair(base::Int64ToString(offline_page_item.bookmark_id), 204 std::make_pair(base::Int64ToString(offline_page_item.offline_id),
191 offline_page_proto)); 205 offline_page_proto));
192 206
193 UpdateEntries(std::move(entries_to_save), std::move(keys_to_remove), 207 UpdateEntries(std::move(entries_to_save), std::move(keys_to_remove),
194 callback); 208 callback);
195 } 209 }
196 210
197 void OfflinePageMetadataStoreImpl::RemoveOfflinePages( 211 void OfflinePageMetadataStoreImpl::RemoveOfflinePages(
198 const std::vector<int64_t>& bookmark_ids, 212 const std::vector<int64_t>& offline_ids,
199 const UpdateCallback& callback) { 213 const UpdateCallback& callback) {
200 scoped_ptr<ProtoDatabase<OfflinePageEntry>::KeyEntryVector> entries_to_save( 214 scoped_ptr<ProtoDatabase<OfflinePageEntry>::KeyEntryVector> entries_to_save(
201 new ProtoDatabase<OfflinePageEntry>::KeyEntryVector()); 215 new ProtoDatabase<OfflinePageEntry>::KeyEntryVector());
202 scoped_ptr<std::vector<std::string>> keys_to_remove( 216 scoped_ptr<std::vector<std::string>> keys_to_remove(
203 new std::vector<std::string>()); 217 new std::vector<std::string>());
204 218
205 for (int64_t id : bookmark_ids) 219 for (int64_t id : offline_ids)
206 keys_to_remove->push_back(base::Int64ToString(id)); 220 keys_to_remove->push_back(base::Int64ToString(id));
207 221
208 UpdateEntries(std::move(entries_to_save), std::move(keys_to_remove), 222 UpdateEntries(std::move(entries_to_save), std::move(keys_to_remove),
209 callback); 223 callback);
210 } 224 }
211 225
212 void OfflinePageMetadataStoreImpl::UpdateEntries( 226 void OfflinePageMetadataStoreImpl::UpdateEntries(
213 scoped_ptr<ProtoDatabase<OfflinePageEntry>::KeyEntryVector> entries_to_save, 227 scoped_ptr<ProtoDatabase<OfflinePageEntry>::KeyEntryVector> entries_to_save,
214 scoped_ptr<std::vector<std::string>> keys_to_remove, 228 scoped_ptr<std::vector<std::string>> keys_to_remove,
215 const UpdateCallback& callback) { 229 const UpdateCallback& callback) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 264
251 void OfflinePageMetadataStoreImpl::ResetDone( 265 void OfflinePageMetadataStoreImpl::ResetDone(
252 const ResetCallback& callback, 266 const ResetCallback& callback,
253 bool success) { 267 bool success) {
254 database_.reset(); 268 database_.reset();
255 weak_ptr_factory_.InvalidateWeakPtrs(); 269 weak_ptr_factory_.InvalidateWeakPtrs();
256 callback.Run(success); 270 callback.Run(success);
257 } 271 }
258 272
259 } // namespace offline_pages 273 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698