| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/dom_distiller/core/dom_distiller_store.h" | 5 #include "components/dom_distiller/core/dom_distiller_store.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" |
| 8 #include "base/logging.h" | 9 #include "base/logging.h" |
| 9 #include "base/message_loop/message_loop.h" | 10 #include "base/single_thread_task_runner.h" |
| 11 #include "base/thread_task_runner_handle.h" |
| 10 #include "components/dom_distiller/core/article_entry.h" | 12 #include "components/dom_distiller/core/article_entry.h" |
| 11 #include "sync/api/sync_change.h" | 13 #include "sync/api/sync_change.h" |
| 12 #include "sync/protocol/article_specifics.pb.h" | 14 #include "sync/protocol/article_specifics.pb.h" |
| 13 #include "sync/protocol/sync.pb.h" | 15 #include "sync/protocol/sync.pb.h" |
| 14 | 16 |
| 15 using leveldb_proto::ProtoDatabase; | 17 using leveldb_proto::ProtoDatabase; |
| 16 using sync_pb::ArticleSpecifics; | 18 using sync_pb::ArticleSpecifics; |
| 17 using sync_pb::EntitySpecifics; | 19 using sync_pb::EntitySpecifics; |
| 18 using syncer::ModelType; | 20 using syncer::ModelType; |
| 19 using syncer::SyncChange; | 21 using syncer::SyncChange; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 | 65 |
| 64 bool DomDistillerStore::GetEntryByUrl(const GURL& url, ArticleEntry* entry) { | 66 bool DomDistillerStore::GetEntryByUrl(const GURL& url, ArticleEntry* entry) { |
| 65 return model_.GetEntryByUrl(url, entry); | 67 return model_.GetEntryByUrl(url, entry); |
| 66 } | 68 } |
| 67 | 69 |
| 68 void DomDistillerStore::UpdateAttachments( | 70 void DomDistillerStore::UpdateAttachments( |
| 69 const std::string& entry_id, | 71 const std::string& entry_id, |
| 70 scoped_ptr<ArticleAttachmentsData> attachments_data, | 72 scoped_ptr<ArticleAttachmentsData> attachments_data, |
| 71 const UpdateAttachmentsCallback& callback) { | 73 const UpdateAttachmentsCallback& callback) { |
| 72 if (!GetEntryById(entry_id, nullptr)) { | 74 if (!GetEntryById(entry_id, nullptr)) { |
| 73 base::MessageLoop::current()->PostTask(FROM_HERE, | 75 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
| 74 base::Bind(callback, false)); | 76 base::Bind(callback, false)); |
| 75 } | 77 } |
| 76 | 78 |
| 77 scoped_ptr<sync_pb::ArticleAttachments> article_attachments( | 79 scoped_ptr<sync_pb::ArticleAttachments> article_attachments( |
| 78 new sync_pb::ArticleAttachments()); | 80 new sync_pb::ArticleAttachments()); |
| 79 syncer::AttachmentList attachment_list; | 81 syncer::AttachmentList attachment_list; |
| 80 attachments_data->CreateSyncAttachments(&attachment_list, | 82 attachments_data->CreateSyncAttachments(&attachment_list, |
| 81 article_attachments.get()); | 83 article_attachments.get()); |
| 82 | 84 |
| 83 attachment_store_->Write( | 85 attachment_store_->Write( |
| 84 attachment_list, | 86 attachment_list, |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 | 127 |
| 126 ApplyChangesToModel(changes_to_apply, &changes_applied, &changes_missing); | 128 ApplyChangesToModel(changes_to_apply, &changes_applied, &changes_missing); |
| 127 | 129 |
| 128 DCHECK_EQ(size_t(0), changes_missing.size()); | 130 DCHECK_EQ(size_t(0), changes_missing.size()); |
| 129 DCHECK_EQ(size_t(1), changes_applied.size()); | 131 DCHECK_EQ(size_t(1), changes_applied.size()); |
| 130 | 132 |
| 131 ApplyChangesToSync(FROM_HERE, changes_applied); | 133 ApplyChangesToSync(FROM_HERE, changes_applied); |
| 132 ApplyChangesToDatabase(changes_applied); | 134 ApplyChangesToDatabase(changes_applied); |
| 133 } | 135 } |
| 134 } | 136 } |
| 135 base::MessageLoop::current()->PostTask(FROM_HERE, | 137 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
| 136 base::Bind(callback, success)); | 138 base::Bind(callback, success)); |
| 137 } | 139 } |
| 138 | 140 |
| 139 void DomDistillerStore::GetAttachments( | 141 void DomDistillerStore::GetAttachments( |
| 140 const std::string& entry_id, | 142 const std::string& entry_id, |
| 141 const GetAttachmentsCallback& callback) { | 143 const GetAttachmentsCallback& callback) { |
| 142 ArticleEntry entry; | 144 ArticleEntry entry; |
| 143 if (!model_.GetEntryById(entry_id, &entry) | 145 if (!model_.GetEntryById(entry_id, &entry) |
| 144 || !entry.has_attachments()) { | 146 || !entry.has_attachments()) { |
| 145 base::MessageLoop::current()->PostTask( | 147 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 146 FROM_HERE, base::Bind(callback, false, nullptr)); | 148 FROM_HERE, base::Bind(callback, false, nullptr)); |
| 147 return; | 149 return; |
| 148 } | 150 } |
| 149 | 151 |
| 150 // TODO(cjhopman): This should use GetOrDownloadAttachments() once there is a | 152 // TODO(cjhopman): This should use GetOrDownloadAttachments() once there is a |
| 151 // feasible way to use that. | 153 // feasible way to use that. |
| 152 attachment_store_->Read(GetAttachmentIds(entry.attachments()), | 154 attachment_store_->Read(GetAttachmentIds(entry.attachments()), |
| 153 base::Bind(&DomDistillerStore::OnAttachmentsRead, | 155 base::Bind(&DomDistillerStore::OnAttachmentsRead, |
| 154 weak_ptr_factory_.GetWeakPtr(), | 156 weak_ptr_factory_.GetWeakPtr(), |
| 155 entry.attachments(), callback)); | 157 entry.attachments(), callback)); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 169 case syncer::AttachmentStore::SUCCESS: | 171 case syncer::AttachmentStore::SUCCESS: |
| 170 DCHECK(missing->empty()); | 172 DCHECK(missing->empty()); |
| 171 success = true; | 173 success = true; |
| 172 break; | 174 break; |
| 173 } | 175 } |
| 174 scoped_ptr<ArticleAttachmentsData> attachments_data; | 176 scoped_ptr<ArticleAttachmentsData> attachments_data; |
| 175 if (success) { | 177 if (success) { |
| 176 attachments_data = ArticleAttachmentsData::GetFromAttachmentMap( | 178 attachments_data = ArticleAttachmentsData::GetFromAttachmentMap( |
| 177 attachments_proto, *attachments); | 179 attachments_proto, *attachments); |
| 178 } | 180 } |
| 179 base::MessageLoop::current()->PostTask( | 181 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 180 FROM_HERE, | 182 FROM_HERE, |
| 181 base::Bind(callback, success, base::Passed(&attachments_data))); | 183 base::Bind(callback, success, base::Passed(&attachments_data))); |
| 182 } | 184 } |
| 183 | 185 |
| 184 bool DomDistillerStore::AddEntry(const ArticleEntry& entry) { | 186 bool DomDistillerStore::AddEntry(const ArticleEntry& entry) { |
| 185 return ChangeEntry(entry, SyncChange::ACTION_ADD); | 187 return ChangeEntry(entry, SyncChange::ACTION_ADD); |
| 186 } | 188 } |
| 187 | 189 |
| 188 bool DomDistillerStore::UpdateEntry(const ArticleEntry& entry) { | 190 bool DomDistillerStore::UpdateEntry(const ArticleEntry& entry) { |
| 189 return ChangeEntry(entry, SyncChange::ACTION_UPDATE); | 191 return ChangeEntry(entry, SyncChange::ACTION_UPDATE); |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 result.set_num_items_deleted(0); | 469 result.set_num_items_deleted(0); |
| 468 | 470 |
| 469 result.set_pre_association_version(0); | 471 result.set_pre_association_version(0); |
| 470 result.set_num_items_after_association(model_.GetNumEntries()); | 472 result.set_num_items_after_association(model_.GetNumEntries()); |
| 471 result.set_error(error); | 473 result.set_error(error); |
| 472 | 474 |
| 473 return result; | 475 return result; |
| 474 } | 476 } |
| 475 | 477 |
| 476 } // namespace dom_distiller | 478 } // namespace dom_distiller |
| OLD | NEW |