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 <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 12 #include "base/location.h" | 12 #include "base/location.h" |
| 13 #include "base/message_loop/message_loop.h" | |
| 14 #include "base/metrics/histogram_macros.h" | 13 #include "base/metrics/histogram_macros.h" |
| 15 #include "base/sequenced_task_runner.h" | 14 #include "base/sequenced_task_runner.h" |
| 16 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
| 17 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 18 #include "base/thread_task_runner_handle.h" | 17 #include "base/thread_task_runner_handle.h" |
| 19 #include "components/leveldb_proto/proto_database_impl.h" | 18 #include "components/leveldb_proto/proto_database_impl.h" |
| 20 #include "components/offline_pages/offline_page_item.h" | 19 #include "components/offline_pages/offline_page_item.h" |
| 21 #include "components/offline_pages/proto/offline_pages.pb.h" | 20 #include "components/offline_pages/proto/offline_pages.pb.h" |
| 22 #include "third_party/leveldatabase/env_chromium.h" | 21 #include "third_party/leveldatabase/env_chromium.h" |
| 23 #include "third_party/leveldatabase/src/include/leveldb/db.h" | 22 #include "third_party/leveldatabase/src/include/leveldb/db.h" |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 209 void OfflinePageMetadataStoreImpl::UpdateEntries( | 208 void OfflinePageMetadataStoreImpl::UpdateEntries( |
| 210 scoped_ptr<ProtoDatabase<OfflinePageEntry>::KeyEntryVector> entries_to_save, | 209 scoped_ptr<ProtoDatabase<OfflinePageEntry>::KeyEntryVector> entries_to_save, |
| 211 scoped_ptr<std::vector<std::string>> keys_to_remove, | 210 scoped_ptr<std::vector<std::string>> keys_to_remove, |
| 212 const UpdateCallback& callback) { | 211 const UpdateCallback& callback) { |
| 213 if (!database_.get()) { | 212 if (!database_.get()) { |
| 214 // Failing fast here, because DB is not initialized, and there is nothing | 213 // Failing fast here, because DB is not initialized, and there is nothing |
| 215 // that can be done about it. | 214 // that can be done about it. |
| 216 // Callback is invoked through message loop to avoid improper retry and | 215 // Callback is invoked through message loop to avoid improper retry and |
| 217 // simplify testing. | 216 // simplify testing. |
| 218 DVLOG(1) << "Offline pages database not available in UpdateEntries."; | 217 DVLOG(1) << "Offline pages database not available in UpdateEntries."; |
| 219 base::MessageLoop::current()->PostTask(FROM_HERE, | 218 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
|
jianli
2015/12/08 23:25:25
nit: include base/thread_task_runner_handle.h
fgorski
2015/12/08 23:39:14
It is actually already there, but it was not used
| |
| 220 base::Bind(callback, false)); | 219 base::Bind(callback, false)); |
| 221 return; | 220 return; |
| 222 } | 221 } |
| 223 | 222 |
| 224 database_->UpdateEntries( | 223 database_->UpdateEntries( |
| 225 entries_to_save.Pass(), keys_to_remove.Pass(), | 224 entries_to_save.Pass(), keys_to_remove.Pass(), |
| 226 base::Bind(&OfflinePageMetadataStoreImpl::UpdateDone, | 225 base::Bind(&OfflinePageMetadataStoreImpl::UpdateDone, |
| 227 weak_ptr_factory_.GetWeakPtr(), | 226 weak_ptr_factory_.GetWeakPtr(), |
| 228 callback)); | 227 callback)); |
| 229 } | 228 } |
| 230 | 229 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 248 | 247 |
| 249 void OfflinePageMetadataStoreImpl::ResetDone( | 248 void OfflinePageMetadataStoreImpl::ResetDone( |
| 250 const ResetCallback& callback, | 249 const ResetCallback& callback, |
| 251 bool success) { | 250 bool success) { |
| 252 database_.reset(); | 251 database_.reset(); |
| 253 weak_ptr_factory_.InvalidateWeakPtrs(); | 252 weak_ptr_factory_.InvalidateWeakPtrs(); |
| 254 callback.Run(success); | 253 callback.Run(success); |
| 255 } | 254 } |
| 256 | 255 |
| 257 } // namespace offline_pages | 256 } // namespace offline_pages |
| OLD | NEW |