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

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 // TODO(bburns): switch this to offline id when we stop passing bookmark
45 // id down.
46 item_proto->set_deprecated_bookmark_id(item.offline_id);
45 item_proto->set_version(item.version); 47 item_proto->set_version(item.version);
46 std::string path_string; 48 std::string path_string;
47 #if defined(OS_POSIX) 49 #if defined(OS_POSIX)
48 path_string = item.file_path.value(); 50 path_string = item.file_path.value();
49 #elif defined(OS_WIN) 51 #elif defined(OS_WIN)
50 path_string = base::WideToUTF8(item.file_path.value()); 52 path_string = base::WideToUTF8(item.file_path.value());
51 #endif 53 #endif
52 item_proto->set_file_path(path_string); 54 item_proto->set_file_path(path_string);
53 item_proto->set_file_size(item.file_size); 55 item_proto->set_file_size(item.file_size);
54 item_proto->set_creation_time(item.creation_time.ToInternalValue()); 56 item_proto->set_creation_time(item.creation_time.ToInternalValue());
55 item_proto->set_last_access_time(item.last_access_time.ToInternalValue()); 57 item_proto->set_last_access_time(item.last_access_time.ToInternalValue());
56 item_proto->set_access_count(item.access_count); 58 item_proto->set_access_count(item.access_count);
57 item_proto->set_flags( 59 item_proto->set_flags(
58 static_cast<::offline_pages::OfflinePageEntry_Flags>(item.flags)); 60 static_cast<::offline_pages::OfflinePageEntry_Flags>(item.flags));
61 item_proto->set_client_id_name_space(item.client_id_name_space);
62 item_proto->set_client_id(item.client_id);
59 } 63 }
60 64
61 bool OfflinePageItemFromEntry(const offline_pages::OfflinePageEntry& item_proto, 65 bool OfflinePageItemFromEntry(const offline_pages::OfflinePageEntry& item_proto,
62 OfflinePageItem* item) { 66 OfflinePageItem* item) {
63 DCHECK(item); 67 DCHECK(item);
64 if (!item_proto.has_url() || !item_proto.has_bookmark_id() || 68 if (!item_proto.has_url() || !item_proto.has_offline_id() ||
65 !item_proto.has_version() || !item_proto.has_file_path()) { 69 !item_proto.has_version() || !item_proto.has_file_path()) {
66 return false; 70 return false;
67 } 71 }
68 item->url = GURL(item_proto.url()); 72 item->url = GURL(item_proto.url());
69 item->bookmark_id = item_proto.bookmark_id(); 73 item->offline_id = item_proto.offline_id();
70 item->version = item_proto.version(); 74 item->version = item_proto.version();
71 #if defined(OS_POSIX) 75 #if defined(OS_POSIX)
72 item->file_path = base::FilePath(item_proto.file_path()); 76 item->file_path = base::FilePath(item_proto.file_path());
73 #elif defined(OS_WIN) 77 #elif defined(OS_WIN)
74 item->file_path = base::FilePath(base::UTF8ToWide(item_proto.file_path())); 78 item->file_path = base::FilePath(base::UTF8ToWide(item_proto.file_path()));
75 #endif 79 #endif
76 if (item_proto.has_file_size()) { 80 if (item_proto.has_file_size()) {
77 item->file_size = item_proto.file_size(); 81 item->file_size = item_proto.file_size();
78 } 82 }
79 if (item_proto.has_creation_time()) { 83 if (item_proto.has_creation_time()) {
80 item->creation_time = 84 item->creation_time =
81 base::Time::FromInternalValue(item_proto.creation_time()); 85 base::Time::FromInternalValue(item_proto.creation_time());
82 } 86 }
83 if (item_proto.has_last_access_time()) { 87 if (item_proto.has_last_access_time()) {
84 item->last_access_time = 88 item->last_access_time =
85 base::Time::FromInternalValue(item_proto.last_access_time()); 89 base::Time::FromInternalValue(item_proto.last_access_time());
86 } 90 }
87 if (item_proto.has_access_count()) { 91 if (item_proto.has_access_count()) {
88 item->access_count = item_proto.access_count(); 92 item->access_count = item_proto.access_count();
89 } 93 }
90 if (item_proto.has_flags()) { 94 if (item_proto.has_flags()) {
91 item->flags = static_cast<OfflinePageItem::Flags>(item_proto.flags()); 95 item->flags = static_cast<OfflinePageItem::Flags>(item_proto.flags());
92 } 96 }
97 item->client_id_name_space = item_proto.client_id_name_space();
98 item->client_id = item_proto.client_id();
99
100 // Legacy storage.
101 if (item->client_id_name_space == ""
102 && item_proto.deprecated_bookmark_id() != 0) {
fgorski 2016/02/23 17:15:30 we need to check for has_deprecated_bookmark_id, a
bburns 2016/02/23 19:25:38 Done.
103 item->client_id_name_space = "bookmark";
fgorski 2016/02/23 17:15:30 refer to const for bookmarks namespace
bburns 2016/02/23 19:25:38 Done.
104 item->client_id = base::Int64ToString(item_proto.deprecated_bookmark_id());
105 if (item->offline_id == 0) {
106 item->offline_id = item_proto.deprecated_bookmark_id();
107 }
108 }
93 return true; 109 return true;
94 } 110 }
95 111
96 } // namespace 112 } // namespace
97 113
98 OfflinePageMetadataStoreImpl::OfflinePageMetadataStoreImpl( 114 OfflinePageMetadataStoreImpl::OfflinePageMetadataStoreImpl(
99 scoped_refptr<base::SequencedTaskRunner> background_task_runner, 115 scoped_refptr<base::SequencedTaskRunner> background_task_runner,
100 const base::FilePath& database_dir) 116 const base::FilePath& database_dir)
101 : background_task_runner_(background_task_runner), 117 : background_task_runner_(background_task_runner),
102 database_dir_(database_dir), 118 database_dir_(database_dir),
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 const OfflinePageItem& offline_page_item, 196 const OfflinePageItem& offline_page_item,
181 const UpdateCallback& callback) { 197 const UpdateCallback& callback) {
182 scoped_ptr<ProtoDatabase<OfflinePageEntry>::KeyEntryVector> entries_to_save( 198 scoped_ptr<ProtoDatabase<OfflinePageEntry>::KeyEntryVector> entries_to_save(
183 new ProtoDatabase<OfflinePageEntry>::KeyEntryVector()); 199 new ProtoDatabase<OfflinePageEntry>::KeyEntryVector());
184 scoped_ptr<std::vector<std::string>> keys_to_remove( 200 scoped_ptr<std::vector<std::string>> keys_to_remove(
185 new std::vector<std::string>()); 201 new std::vector<std::string>());
186 202
187 OfflinePageEntry offline_page_proto; 203 OfflinePageEntry offline_page_proto;
188 OfflinePageItemToEntry(offline_page_item, &offline_page_proto); 204 OfflinePageItemToEntry(offline_page_item, &offline_page_proto);
189 entries_to_save->push_back( 205 entries_to_save->push_back(
190 std::make_pair(base::Int64ToString(offline_page_item.bookmark_id), 206 std::make_pair(base::Int64ToString(offline_page_item.offline_id),
191 offline_page_proto)); 207 offline_page_proto));
192 208
193 UpdateEntries(std::move(entries_to_save), std::move(keys_to_remove), 209 UpdateEntries(std::move(entries_to_save), std::move(keys_to_remove),
194 callback); 210 callback);
195 } 211 }
196 212
197 void OfflinePageMetadataStoreImpl::RemoveOfflinePages( 213 void OfflinePageMetadataStoreImpl::RemoveOfflinePages(
198 const std::vector<int64_t>& bookmark_ids, 214 const std::vector<int64_t>& offline_ids,
199 const UpdateCallback& callback) { 215 const UpdateCallback& callback) {
200 scoped_ptr<ProtoDatabase<OfflinePageEntry>::KeyEntryVector> entries_to_save( 216 scoped_ptr<ProtoDatabase<OfflinePageEntry>::KeyEntryVector> entries_to_save(
201 new ProtoDatabase<OfflinePageEntry>::KeyEntryVector()); 217 new ProtoDatabase<OfflinePageEntry>::KeyEntryVector());
202 scoped_ptr<std::vector<std::string>> keys_to_remove( 218 scoped_ptr<std::vector<std::string>> keys_to_remove(
203 new std::vector<std::string>()); 219 new std::vector<std::string>());
204 220
205 for (int64_t id : bookmark_ids) 221 for (int64_t id : offline_ids)
206 keys_to_remove->push_back(base::Int64ToString(id)); 222 keys_to_remove->push_back(base::Int64ToString(id));
207 223
208 UpdateEntries(std::move(entries_to_save), std::move(keys_to_remove), 224 UpdateEntries(std::move(entries_to_save), std::move(keys_to_remove),
209 callback); 225 callback);
210 } 226 }
211 227
212 void OfflinePageMetadataStoreImpl::UpdateEntries( 228 void OfflinePageMetadataStoreImpl::UpdateEntries(
213 scoped_ptr<ProtoDatabase<OfflinePageEntry>::KeyEntryVector> entries_to_save, 229 scoped_ptr<ProtoDatabase<OfflinePageEntry>::KeyEntryVector> entries_to_save,
214 scoped_ptr<std::vector<std::string>> keys_to_remove, 230 scoped_ptr<std::vector<std::string>> keys_to_remove,
215 const UpdateCallback& callback) { 231 const UpdateCallback& callback) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 266
251 void OfflinePageMetadataStoreImpl::ResetDone( 267 void OfflinePageMetadataStoreImpl::ResetDone(
252 const ResetCallback& callback, 268 const ResetCallback& callback,
253 bool success) { 269 bool success) {
254 database_.reset(); 270 database_.reset();
255 weak_ptr_factory_.InvalidateWeakPtrs(); 271 weak_ptr_factory_.InvalidateWeakPtrs();
256 callback.Run(success); 272 callback.Run(success);
257 } 273 }
258 274
259 } // namespace offline_pages 275 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698