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

Side by Side Diff: components/dom_distiller/core/dom_distiller_store.cc

Issue 1879613003: Convert //components/dom_distiller from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 8 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 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 <stddef.h> 7 #include <stddef.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 21 matching lines...) Expand all
32 // Statistics are logged to UMA with this string as part of histogram name. They 32 // Statistics are logged to UMA with this string as part of histogram name. They
33 // can all be found under LevelDB.*.DomDistillerStore. Changing this needs to 33 // can all be found under LevelDB.*.DomDistillerStore. Changing this needs to
34 // synchronize with histograms.xml, AND will also become incompatible with older 34 // synchronize with histograms.xml, AND will also become incompatible with older
35 // browsers still reporting the previous values. 35 // browsers still reporting the previous values.
36 const char kDatabaseUMAClientName[] = "DomDistillerStore"; 36 const char kDatabaseUMAClientName[] = "DomDistillerStore";
37 } 37 }
38 38
39 namespace dom_distiller { 39 namespace dom_distiller {
40 40
41 DomDistillerStore::DomDistillerStore( 41 DomDistillerStore::DomDistillerStore(
42 scoped_ptr<ProtoDatabase<ArticleEntry>> database, 42 std::unique_ptr<ProtoDatabase<ArticleEntry>> database,
43 const base::FilePath& database_dir) 43 const base::FilePath& database_dir)
44 : database_(std::move(database)), 44 : database_(std::move(database)),
45 database_loaded_(false), 45 database_loaded_(false),
46 attachment_store_(syncer::AttachmentStore::CreateInMemoryStore()), 46 attachment_store_(syncer::AttachmentStore::CreateInMemoryStore()),
47 weak_ptr_factory_(this) { 47 weak_ptr_factory_(this) {
48 database_->Init(kDatabaseUMAClientName, database_dir, 48 database_->Init(kDatabaseUMAClientName, database_dir,
49 base::Bind(&DomDistillerStore::OnDatabaseInit, 49 base::Bind(&DomDistillerStore::OnDatabaseInit,
50 weak_ptr_factory_.GetWeakPtr())); 50 weak_ptr_factory_.GetWeakPtr()));
51 } 51 }
52 52
53 DomDistillerStore::DomDistillerStore( 53 DomDistillerStore::DomDistillerStore(
54 scoped_ptr<ProtoDatabase<ArticleEntry>> database, 54 std::unique_ptr<ProtoDatabase<ArticleEntry>> database,
55 const std::vector<ArticleEntry>& initial_data, 55 const std::vector<ArticleEntry>& initial_data,
56 const base::FilePath& database_dir) 56 const base::FilePath& database_dir)
57 : database_(std::move(database)), 57 : database_(std::move(database)),
58 database_loaded_(false), 58 database_loaded_(false),
59 attachment_store_(syncer::AttachmentStore::CreateInMemoryStore()), 59 attachment_store_(syncer::AttachmentStore::CreateInMemoryStore()),
60 model_(initial_data), 60 model_(initial_data),
61 weak_ptr_factory_(this) { 61 weak_ptr_factory_(this) {
62 database_->Init(kDatabaseUMAClientName, database_dir, 62 database_->Init(kDatabaseUMAClientName, database_dir,
63 base::Bind(&DomDistillerStore::OnDatabaseInit, 63 base::Bind(&DomDistillerStore::OnDatabaseInit,
64 weak_ptr_factory_.GetWeakPtr())); 64 weak_ptr_factory_.GetWeakPtr()));
(...skipping 10 matching lines...) Expand all
75 ArticleEntry* entry) { 75 ArticleEntry* entry) {
76 return model_.GetEntryById(entry_id, entry); 76 return model_.GetEntryById(entry_id, entry);
77 } 77 }
78 78
79 bool DomDistillerStore::GetEntryByUrl(const GURL& url, ArticleEntry* entry) { 79 bool DomDistillerStore::GetEntryByUrl(const GURL& url, ArticleEntry* entry) {
80 return model_.GetEntryByUrl(url, entry); 80 return model_.GetEntryByUrl(url, entry);
81 } 81 }
82 82
83 void DomDistillerStore::UpdateAttachments( 83 void DomDistillerStore::UpdateAttachments(
84 const std::string& entry_id, 84 const std::string& entry_id,
85 scoped_ptr<ArticleAttachmentsData> attachments_data, 85 std::unique_ptr<ArticleAttachmentsData> attachments_data,
86 const UpdateAttachmentsCallback& callback) { 86 const UpdateAttachmentsCallback& callback) {
87 if (!GetEntryById(entry_id, nullptr)) { 87 if (!GetEntryById(entry_id, nullptr)) {
88 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, 88 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
89 base::Bind(callback, false)); 89 base::Bind(callback, false));
90 } 90 }
91 91
92 scoped_ptr<sync_pb::ArticleAttachments> article_attachments( 92 std::unique_ptr<sync_pb::ArticleAttachments> article_attachments(
93 new sync_pb::ArticleAttachments()); 93 new sync_pb::ArticleAttachments());
94 syncer::AttachmentList attachment_list; 94 syncer::AttachmentList attachment_list;
95 attachments_data->CreateSyncAttachments(&attachment_list, 95 attachments_data->CreateSyncAttachments(&attachment_list,
96 article_attachments.get()); 96 article_attachments.get());
97 97
98 attachment_store_->Write( 98 attachment_store_->Write(
99 attachment_list, 99 attachment_list,
100 base::Bind(&DomDistillerStore::OnAttachmentsWrite, 100 base::Bind(&DomDistillerStore::OnAttachmentsWrite,
101 weak_ptr_factory_.GetWeakPtr(), entry_id, 101 weak_ptr_factory_.GetWeakPtr(), entry_id,
102 base::Passed(&article_attachments), callback)); 102 base::Passed(&article_attachments), callback));
103 } 103 }
104 104
105 void DomDistillerStore::OnAttachmentsWrite( 105 void DomDistillerStore::OnAttachmentsWrite(
106 const std::string& entry_id, 106 const std::string& entry_id,
107 scoped_ptr<sync_pb::ArticleAttachments> article_attachments, 107 std::unique_ptr<sync_pb::ArticleAttachments> article_attachments,
108 const UpdateAttachmentsCallback& callback, 108 const UpdateAttachmentsCallback& callback,
109 const syncer::AttachmentStore::Result& result) { 109 const syncer::AttachmentStore::Result& result) {
110 bool success = false; 110 bool success = false;
111 switch (result) { 111 switch (result) {
112 case syncer::AttachmentStore::UNSPECIFIED_ERROR: 112 case syncer::AttachmentStore::UNSPECIFIED_ERROR:
113 case syncer::AttachmentStore::STORE_INITIALIZATION_FAILED: 113 case syncer::AttachmentStore::STORE_INITIALIZATION_FAILED:
114 break; 114 break;
115 case syncer::AttachmentStore::SUCCESS: 115 case syncer::AttachmentStore::SUCCESS:
116 success = true; 116 success = true;
117 break; 117 break;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 attachment_store_->Read(GetAttachmentIds(entry.attachments()), 167 attachment_store_->Read(GetAttachmentIds(entry.attachments()),
168 base::Bind(&DomDistillerStore::OnAttachmentsRead, 168 base::Bind(&DomDistillerStore::OnAttachmentsRead,
169 weak_ptr_factory_.GetWeakPtr(), 169 weak_ptr_factory_.GetWeakPtr(),
170 entry.attachments(), callback)); 170 entry.attachments(), callback));
171 } 171 }
172 172
173 void DomDistillerStore::OnAttachmentsRead( 173 void DomDistillerStore::OnAttachmentsRead(
174 const sync_pb::ArticleAttachments& attachments_proto, 174 const sync_pb::ArticleAttachments& attachments_proto,
175 const GetAttachmentsCallback& callback, 175 const GetAttachmentsCallback& callback,
176 const syncer::AttachmentStore::Result& result, 176 const syncer::AttachmentStore::Result& result,
177 scoped_ptr<syncer::AttachmentMap> attachments, 177 std::unique_ptr<syncer::AttachmentMap> attachments,
178 scoped_ptr<syncer::AttachmentIdList> missing) { 178 std::unique_ptr<syncer::AttachmentIdList> missing) {
179 bool success = false; 179 bool success = false;
180 switch (result) { 180 switch (result) {
181 case syncer::AttachmentStore::UNSPECIFIED_ERROR: 181 case syncer::AttachmentStore::UNSPECIFIED_ERROR:
182 case syncer::AttachmentStore::STORE_INITIALIZATION_FAILED: 182 case syncer::AttachmentStore::STORE_INITIALIZATION_FAILED:
183 break; 183 break;
184 case syncer::AttachmentStore::SUCCESS: 184 case syncer::AttachmentStore::SUCCESS:
185 DCHECK(missing->empty()); 185 DCHECK(missing->empty());
186 success = true; 186 success = true;
187 break; 187 break;
188 } 188 }
189 scoped_ptr<ArticleAttachmentsData> attachments_data; 189 std::unique_ptr<ArticleAttachmentsData> attachments_data;
190 if (success) { 190 if (success) {
191 attachments_data = ArticleAttachmentsData::GetFromAttachmentMap( 191 attachments_data = ArticleAttachmentsData::GetFromAttachmentMap(
192 attachments_proto, *attachments); 192 attachments_proto, *attachments);
193 } 193 }
194 base::ThreadTaskRunnerHandle::Get()->PostTask( 194 base::ThreadTaskRunnerHandle::Get()->PostTask(
195 FROM_HERE, 195 FROM_HERE,
196 base::Bind(callback, success, base::Passed(&attachments_data))); 196 base::Bind(callback, success, base::Passed(&attachments_data)));
197 } 197 }
198 198
199 bool DomDistillerStore::AddEntry(const ArticleEntry& entry) { 199 bool DomDistillerStore::AddEntry(const ArticleEntry& entry) {
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 void DomDistillerStore::RemoveObserver(DomDistillerObserver* observer) { 272 void DomDistillerStore::RemoveObserver(DomDistillerObserver* observer) {
273 observers_.RemoveObserver(observer); 273 observers_.RemoveObserver(observer);
274 } 274 }
275 275
276 std::vector<ArticleEntry> DomDistillerStore::GetEntries() const { 276 std::vector<ArticleEntry> DomDistillerStore::GetEntries() const {
277 return model_.GetEntries(); 277 return model_.GetEntries();
278 } 278 }
279 279
280 // syncer::SyncableService implementation. 280 // syncer::SyncableService implementation.
281 SyncMergeResult DomDistillerStore::MergeDataAndStartSyncing( 281 SyncMergeResult DomDistillerStore::MergeDataAndStartSyncing(
282 ModelType type, const SyncDataList& initial_sync_data, 282 ModelType type,
283 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, 283 const SyncDataList& initial_sync_data,
284 scoped_ptr<syncer::SyncErrorFactory> error_handler) { 284 std::unique_ptr<syncer::SyncChangeProcessor> sync_processor,
285 std::unique_ptr<syncer::SyncErrorFactory> error_handler) {
285 DCHECK_EQ(syncer::ARTICLES, type); 286 DCHECK_EQ(syncer::ARTICLES, type);
286 DCHECK(!sync_processor_); 287 DCHECK(!sync_processor_);
287 DCHECK(!error_factory_); 288 DCHECK(!error_factory_);
288 sync_processor_.reset(sync_processor.release()); 289 sync_processor_.reset(sync_processor.release());
289 error_factory_.reset(error_handler.release()); 290 error_factory_.reset(error_handler.release());
290 291
291 SyncChangeList database_changes; 292 SyncChangeList database_changes;
292 SyncChangeList sync_changes; 293 SyncChangeList sync_changes;
293 SyncMergeResult result = 294 SyncMergeResult result =
294 MergeDataWithModel(initial_sync_data, &database_changes, &sync_changes); 295 MergeDataWithModel(initial_sync_data, &database_changes, &sync_changes);
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 if (!success) { 362 if (!success) {
362 DVLOG(1) << "DOM Distiller database init failed."; 363 DVLOG(1) << "DOM Distiller database init failed.";
363 database_.reset(); 364 database_.reset();
364 return; 365 return;
365 } 366 }
366 database_->LoadEntries(base::Bind(&DomDistillerStore::OnDatabaseLoad, 367 database_->LoadEntries(base::Bind(&DomDistillerStore::OnDatabaseLoad,
367 weak_ptr_factory_.GetWeakPtr())); 368 weak_ptr_factory_.GetWeakPtr()));
368 } 369 }
369 370
370 void DomDistillerStore::OnDatabaseLoad(bool success, 371 void DomDistillerStore::OnDatabaseLoad(bool success,
371 scoped_ptr<EntryVector> entries) { 372 std::unique_ptr<EntryVector> entries) {
372 if (!success) { 373 if (!success) {
373 DVLOG(1) << "DOM Distiller database load failed."; 374 DVLOG(1) << "DOM Distiller database load failed.";
374 database_.reset(); 375 database_.reset();
375 return; 376 return;
376 } 377 }
377 database_loaded_ = true; 378 database_loaded_ = true;
378 379
379 SyncDataList data; 380 SyncDataList data;
380 for (EntryVector::iterator it = entries->begin(); it != entries->end(); 381 for (EntryVector::iterator it = entries->begin(); it != entries->end();
381 ++it) { 382 ++it) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 } 418 }
418 419
419 bool DomDistillerStore::ApplyChangesToDatabase( 420 bool DomDistillerStore::ApplyChangesToDatabase(
420 const SyncChangeList& change_list) { 421 const SyncChangeList& change_list) {
421 if (!database_loaded_) { 422 if (!database_loaded_) {
422 return false; 423 return false;
423 } 424 }
424 if (change_list.empty()) { 425 if (change_list.empty()) {
425 return true; 426 return true;
426 } 427 }
427 scoped_ptr<ProtoDatabase<ArticleEntry>::KeyEntryVector> entries_to_save( 428 std::unique_ptr<ProtoDatabase<ArticleEntry>::KeyEntryVector> entries_to_save(
428 new ProtoDatabase<ArticleEntry>::KeyEntryVector()); 429 new ProtoDatabase<ArticleEntry>::KeyEntryVector());
429 scoped_ptr<std::vector<std::string> > keys_to_remove( 430 std::unique_ptr<std::vector<std::string>> keys_to_remove(
430 new std::vector<std::string>()); 431 new std::vector<std::string>());
431 432
432 for (SyncChangeList::const_iterator it = change_list.begin(); 433 for (SyncChangeList::const_iterator it = change_list.begin();
433 it != change_list.end(); ++it) { 434 it != change_list.end(); ++it) {
434 if (it->change_type() == SyncChange::ACTION_DELETE) { 435 if (it->change_type() == SyncChange::ACTION_DELETE) {
435 ArticleEntry entry = GetEntryFromChange(*it); 436 ArticleEntry entry = GetEntryFromChange(*it);
436 keys_to_remove->push_back(entry.entry_id()); 437 keys_to_remove->push_back(entry.entry_id());
437 } else { 438 } else {
438 ArticleEntry entry = GetEntryFromChange(*it); 439 ArticleEntry entry = GetEntryFromChange(*it);
439 entries_to_save->push_back(std::make_pair(entry.entry_id(), entry)); 440 entries_to_save->push_back(std::make_pair(entry.entry_id(), entry));
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 result.set_num_items_deleted(0); 484 result.set_num_items_deleted(0);
484 485
485 result.set_pre_association_version(0); 486 result.set_pre_association_version(0);
486 result.set_num_items_after_association(model_.GetNumEntries()); 487 result.set_num_items_after_association(model_.GetNumEntries());
487 result.set_error(error); 488 result.set_error(error);
488 489
489 return result; 490 return result;
490 } 491 }
491 492
492 } // namespace dom_distiller 493 } // namespace dom_distiller
OLDNEW
« no previous file with comments | « components/dom_distiller/core/dom_distiller_store.h ('k') | components/dom_distiller/core/dom_distiller_store_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698