Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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->mutable_client_id()->set_space(item.client_id_namespace); | |
| 60 item_proto->mutable_client_id()->set_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) { |
|
fgorski
2016/02/12 21:43:41
this should also read the client id
bburns
2016/02/20 01:14:18
Done.
| |
| 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()) { |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 180 const OfflinePageItem& offline_page_item, | 182 const OfflinePageItem& offline_page_item, |
| 181 const UpdateCallback& callback) { | 183 const UpdateCallback& callback) { |
| 182 scoped_ptr<ProtoDatabase<OfflinePageEntry>::KeyEntryVector> entries_to_save( | 184 scoped_ptr<ProtoDatabase<OfflinePageEntry>::KeyEntryVector> entries_to_save( |
| 183 new ProtoDatabase<OfflinePageEntry>::KeyEntryVector()); | 185 new ProtoDatabase<OfflinePageEntry>::KeyEntryVector()); |
| 184 scoped_ptr<std::vector<std::string>> keys_to_remove( | 186 scoped_ptr<std::vector<std::string>> keys_to_remove( |
| 185 new std::vector<std::string>()); | 187 new std::vector<std::string>()); |
| 186 | 188 |
| 187 OfflinePageEntry offline_page_proto; | 189 OfflinePageEntry offline_page_proto; |
| 188 OfflinePageItemToEntry(offline_page_item, &offline_page_proto); | 190 OfflinePageItemToEntry(offline_page_item, &offline_page_proto); |
| 189 entries_to_save->push_back( | 191 entries_to_save->push_back( |
| 190 std::make_pair(base::Int64ToString(offline_page_item.bookmark_id), | 192 std::make_pair(base::Int64ToString(offline_page_item.offline_id), |
| 191 offline_page_proto)); | 193 offline_page_proto)); |
| 192 | 194 |
| 193 UpdateEntries(std::move(entries_to_save), std::move(keys_to_remove), | 195 UpdateEntries(std::move(entries_to_save), std::move(keys_to_remove), |
| 194 callback); | 196 callback); |
| 195 } | 197 } |
| 196 | 198 |
| 197 void OfflinePageMetadataStoreImpl::RemoveOfflinePages( | 199 void OfflinePageMetadataStoreImpl::RemoveOfflinePages( |
| 198 const std::vector<int64_t>& bookmark_ids, | 200 const std::vector<int64_t>& offline_ids, |
| 199 const UpdateCallback& callback) { | 201 const UpdateCallback& callback) { |
| 200 scoped_ptr<ProtoDatabase<OfflinePageEntry>::KeyEntryVector> entries_to_save( | 202 scoped_ptr<ProtoDatabase<OfflinePageEntry>::KeyEntryVector> entries_to_save( |
| 201 new ProtoDatabase<OfflinePageEntry>::KeyEntryVector()); | 203 new ProtoDatabase<OfflinePageEntry>::KeyEntryVector()); |
| 202 scoped_ptr<std::vector<std::string>> keys_to_remove( | 204 scoped_ptr<std::vector<std::string>> keys_to_remove( |
| 203 new std::vector<std::string>()); | 205 new std::vector<std::string>()); |
| 204 | 206 |
| 205 for (int64_t id : bookmark_ids) | 207 for (int64_t id : offline_ids) |
| 206 keys_to_remove->push_back(base::Int64ToString(id)); | 208 keys_to_remove->push_back(base::Int64ToString(id)); |
| 207 | 209 |
| 208 UpdateEntries(std::move(entries_to_save), std::move(keys_to_remove), | 210 UpdateEntries(std::move(entries_to_save), std::move(keys_to_remove), |
| 209 callback); | 211 callback); |
| 210 } | 212 } |
| 211 | 213 |
| 212 void OfflinePageMetadataStoreImpl::UpdateEntries( | 214 void OfflinePageMetadataStoreImpl::UpdateEntries( |
| 213 scoped_ptr<ProtoDatabase<OfflinePageEntry>::KeyEntryVector> entries_to_save, | 215 scoped_ptr<ProtoDatabase<OfflinePageEntry>::KeyEntryVector> entries_to_save, |
| 214 scoped_ptr<std::vector<std::string>> keys_to_remove, | 216 scoped_ptr<std::vector<std::string>> keys_to_remove, |
| 215 const UpdateCallback& callback) { | 217 const UpdateCallback& callback) { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 250 | 252 |
| 251 void OfflinePageMetadataStoreImpl::ResetDone( | 253 void OfflinePageMetadataStoreImpl::ResetDone( |
| 252 const ResetCallback& callback, | 254 const ResetCallback& callback, |
| 253 bool success) { | 255 bool success) { |
| 254 database_.reset(); | 256 database_.reset(); |
| 255 weak_ptr_factory_.InvalidateWeakPtrs(); | 257 weak_ptr_factory_.InvalidateWeakPtrs(); |
| 256 callback.Run(success); | 258 callback.Run(success); |
| 257 } | 259 } |
| 258 | 260 |
| 259 } // namespace offline_pages | 261 } // namespace offline_pages |
| OLD | NEW |