| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 #if defined(OS_POSIX) | 37 #if defined(OS_POSIX) |
| 38 path_string = item.file_path.value(); | 38 path_string = item.file_path.value(); |
| 39 #elif defined(OS_WIN) | 39 #elif defined(OS_WIN) |
| 40 path_string = base::WideToUTF8(item.file_path.value()); | 40 path_string = base::WideToUTF8(item.file_path.value()); |
| 41 #endif | 41 #endif |
| 42 item_proto->set_file_path(path_string); | 42 item_proto->set_file_path(path_string); |
| 43 item_proto->set_file_size(item.file_size); | 43 item_proto->set_file_size(item.file_size); |
| 44 item_proto->set_creation_time(item.creation_time.ToInternalValue()); | 44 item_proto->set_creation_time(item.creation_time.ToInternalValue()); |
| 45 item_proto->set_last_access_time(item.last_access_time.ToInternalValue()); | 45 item_proto->set_last_access_time(item.last_access_time.ToInternalValue()); |
| 46 item_proto->set_access_count(item.access_count); | 46 item_proto->set_access_count(item.access_count); |
| 47 item_proto->set_flags( |
| 48 static_cast<::offline_pages::OfflinePageEntry_Flags>(item.flags)); |
| 47 } | 49 } |
| 48 | 50 |
| 49 bool OfflinePageItemFromEntry(const offline_pages::OfflinePageEntry& item_proto, | 51 bool OfflinePageItemFromEntry(const offline_pages::OfflinePageEntry& item_proto, |
| 50 OfflinePageItem* item) { | 52 OfflinePageItem* item) { |
| 51 DCHECK(item); | 53 DCHECK(item); |
| 52 if (!item_proto.has_url() || !item_proto.has_bookmark_id() || | 54 if (!item_proto.has_url() || !item_proto.has_bookmark_id() || |
| 53 !item_proto.has_version() || !item_proto.has_file_path()) { | 55 !item_proto.has_version() || !item_proto.has_file_path()) { |
| 54 return false; | 56 return false; |
| 55 } | 57 } |
| 56 item->url = GURL(item_proto.url()); | 58 item->url = GURL(item_proto.url()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 68 item->creation_time = | 70 item->creation_time = |
| 69 base::Time::FromInternalValue(item_proto.creation_time()); | 71 base::Time::FromInternalValue(item_proto.creation_time()); |
| 70 } | 72 } |
| 71 if (item_proto.has_last_access_time()) { | 73 if (item_proto.has_last_access_time()) { |
| 72 item->last_access_time = | 74 item->last_access_time = |
| 73 base::Time::FromInternalValue(item_proto.last_access_time()); | 75 base::Time::FromInternalValue(item_proto.last_access_time()); |
| 74 } | 76 } |
| 75 if (item_proto.has_access_count()) { | 77 if (item_proto.has_access_count()) { |
| 76 item->access_count = item_proto.access_count(); | 78 item->access_count = item_proto.access_count(); |
| 77 } | 79 } |
| 80 if (item_proto.has_flags()) { |
| 81 item->flags = static_cast<OfflinePageItem::Flags>(item_proto.flags()); |
| 82 } |
| 78 return true; | 83 return true; |
| 79 } | 84 } |
| 80 | 85 |
| 81 void OnLoadDone(const OfflinePageMetadataStore::LoadCallback& callback, | 86 void OnLoadDone(const OfflinePageMetadataStore::LoadCallback& callback, |
| 82 const base::Callback<void()>& failure_callback, | 87 const base::Callback<void()>& failure_callback, |
| 83 bool success, | 88 bool success, |
| 84 scoped_ptr<OfflinePageEntryVector> entries) { | 89 scoped_ptr<OfflinePageEntryVector> entries) { |
| 85 UMA_HISTOGRAM_BOOLEAN("OfflinePages.LoadSuccess", success); | 90 UMA_HISTOGRAM_BOOLEAN("OfflinePages.LoadSuccess", success); |
| 86 if (!success) { | 91 if (!success) { |
| 87 DVLOG(1) << "Offline pages database load failed."; | 92 DVLOG(1) << "Offline pages database load failed."; |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 base::Bind(&OfflinePageMetadataStoreImpl::ResetDB, | 216 base::Bind(&OfflinePageMetadataStoreImpl::ResetDB, |
| 212 weak_ptr_factory_.GetWeakPtr()))); | 217 weak_ptr_factory_.GetWeakPtr()))); |
| 213 } | 218 } |
| 214 | 219 |
| 215 void OfflinePageMetadataStoreImpl::ResetDB() { | 220 void OfflinePageMetadataStoreImpl::ResetDB() { |
| 216 database_.reset(); | 221 database_.reset(); |
| 217 weak_ptr_factory_.InvalidateWeakPtrs(); | 222 weak_ptr_factory_.InvalidateWeakPtrs(); |
| 218 } | 223 } |
| 219 | 224 |
| 220 } // namespace offline_pages | 225 } // namespace offline_pages |
| OLD | NEW |