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

Side by Side Diff: sync/engine/directory_update_handler_unittest.cc

Issue 1096983002: Update usages of std::map to use ScopedPtrMap. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@passwordmanager-scopedmemory
Patch Set: Rebase. Created 5 years, 5 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
« no previous file with comments | « sync/engine/commit_processor.cc ('k') | sync/engine/entity_tracker.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "sync/engine/directory_update_handler.h" 5 #include "sync/engine/directory_update_handler.h"
6 6
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/containers/scoped_ptr_map.h"
9 #include "base/memory/scoped_ptr.h"
8 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
9 #include "base/stl_util.h"
10 #include "sync/engine/syncer_proto_util.h" 11 #include "sync/engine/syncer_proto_util.h"
11 #include "sync/internal_api/public/base/attachment_id_proto.h" 12 #include "sync/internal_api/public/base/attachment_id_proto.h"
12 #include "sync/internal_api/public/base/model_type.h" 13 #include "sync/internal_api/public/base/model_type.h"
13 #include "sync/internal_api/public/test/test_entry_factory.h" 14 #include "sync/internal_api/public/test/test_entry_factory.h"
14 #include "sync/protocol/sync.pb.h" 15 #include "sync/protocol/sync.pb.h"
15 #include "sync/sessions/directory_type_debug_info_emitter.h" 16 #include "sync/sessions/directory_type_debug_info_emitter.h"
16 #include "sync/sessions/status_controller.h" 17 #include "sync/sessions/status_controller.h"
17 #include "sync/syncable/directory.h" 18 #include "sync/syncable/directory.h"
18 #include "sync/syncable/entry.h" 19 #include "sync/syncable/entry.h"
19 #include "sync/syncable/mutable_entry.h" 20 #include "sync/syncable/mutable_entry.h"
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 // using FakeModelWorkers, so there's not much difference between the two test 450 // using FakeModelWorkers, so there's not much difference between the two test
450 // harnesses. 451 // harnesses.
451 class DirectoryUpdateHandlerApplyUpdateTest : public ::testing::Test { 452 class DirectoryUpdateHandlerApplyUpdateTest : public ::testing::Test {
452 public: 453 public:
453 DirectoryUpdateHandlerApplyUpdateTest() 454 DirectoryUpdateHandlerApplyUpdateTest()
454 : ui_worker_(new FakeModelWorker(GROUP_UI)), 455 : ui_worker_(new FakeModelWorker(GROUP_UI)),
455 password_worker_(new FakeModelWorker(GROUP_PASSWORD)), 456 password_worker_(new FakeModelWorker(GROUP_PASSWORD)),
456 passive_worker_(new FakeModelWorker(GROUP_PASSIVE)), 457 passive_worker_(new FakeModelWorker(GROUP_PASSIVE)),
457 bookmarks_emitter_(BOOKMARKS, &type_observers_), 458 bookmarks_emitter_(BOOKMARKS, &type_observers_),
458 passwords_emitter_(PASSWORDS, &type_observers_), 459 passwords_emitter_(PASSWORDS, &type_observers_),
459 articles_emitter_(ARTICLES, &type_observers_), 460 articles_emitter_(ARTICLES, &type_observers_) {}
460 update_handler_map_deleter_(&update_handler_map_) {}
461 461
462 void SetUp() override { 462 void SetUp() override {
463 dir_maker_.SetUp(); 463 dir_maker_.SetUp();
464 entry_factory_.reset(new TestEntryFactory(directory())); 464 entry_factory_.reset(new TestEntryFactory(directory()));
465 465
466 update_handler_map_.insert(std::make_pair( 466 update_handler_map_.insert(
467 BOOKMARKS, 467 BOOKMARKS,
468 new DirectoryUpdateHandler(directory(), BOOKMARKS, 468 make_scoped_ptr(new DirectoryUpdateHandler(
469 ui_worker_, &bookmarks_emitter_))); 469 directory(), BOOKMARKS, ui_worker_, &bookmarks_emitter_)));
470 update_handler_map_.insert(std::make_pair( 470 update_handler_map_.insert(
471 PASSWORDS, 471 PASSWORDS,
472 new DirectoryUpdateHandler(directory(), 472 make_scoped_ptr(new DirectoryUpdateHandler(
473 PASSWORDS, 473 directory(), PASSWORDS, password_worker_, &passwords_emitter_)));
474 password_worker_, 474 update_handler_map_.insert(
475 &passwords_emitter_))); 475 ARTICLES, make_scoped_ptr(new DirectoryUpdateHandler(
476 update_handler_map_.insert(std::make_pair( 476 directory(), ARTICLES, ui_worker_, &articles_emitter_)));
477 ARTICLES,
478 new DirectoryUpdateHandler(
479 directory(), ARTICLES, ui_worker_, &articles_emitter_)));
480 } 477 }
481 478
482 void TearDown() override { dir_maker_.TearDown(); } 479 void TearDown() override { dir_maker_.TearDown(); }
483 480
484 const UpdateCounters& GetBookmarksUpdateCounters() { 481 const UpdateCounters& GetBookmarksUpdateCounters() {
485 return bookmarks_emitter_.GetUpdateCounters(); 482 return bookmarks_emitter_.GetUpdateCounters();
486 } 483 }
487 484
488 const UpdateCounters& GetPasswordsUpdateCounters() { 485 const UpdateCounters& GetPasswordsUpdateCounters() {
489 return passwords_emitter_.GetUpdateCounters(); 486 return passwords_emitter_.GetUpdateCounters();
490 } 487 }
491 488
492 const UpdateCounters& GetArticlesUpdateCounters() { 489 const UpdateCounters& GetArticlesUpdateCounters() {
493 return articles_emitter_.GetUpdateCounters(); 490 return articles_emitter_.GetUpdateCounters();
494 } 491 }
495 492
496 protected: 493 protected:
497 void ApplyBookmarkUpdates(sessions::StatusController* status) { 494 void ApplyBookmarkUpdates(sessions::StatusController* status) {
498 update_handler_map_[BOOKMARKS]->ApplyUpdates(status); 495 update_handler_map_.find(BOOKMARKS)->second->ApplyUpdates(status);
499 } 496 }
500 497
501 void ApplyPasswordUpdates(sessions::StatusController* status) { 498 void ApplyPasswordUpdates(sessions::StatusController* status) {
502 update_handler_map_[PASSWORDS]->ApplyUpdates(status); 499 update_handler_map_.find(PASSWORDS)->second->ApplyUpdates(status);
503 } 500 }
504 501
505 void ApplyArticlesUpdates(sessions::StatusController* status) { 502 void ApplyArticlesUpdates(sessions::StatusController* status) {
506 update_handler_map_[ARTICLES]->ApplyUpdates(status); 503 update_handler_map_.find(ARTICLES)->second->ApplyUpdates(status);
507 } 504 }
508 505
509 TestEntryFactory* entry_factory() { 506 TestEntryFactory* entry_factory() {
510 return entry_factory_.get(); 507 return entry_factory_.get();
511 } 508 }
512 509
513 syncable::Directory* directory() { 510 syncable::Directory* directory() {
514 return dir_maker_.directory(); 511 return dir_maker_.directory();
515 } 512 }
516 513
517 private: 514 private:
518 typedef std::map<ModelType, UpdateHandler*> UpdateHandlerMap;
519
520 base::MessageLoop loop_; // Needed to initialize the directory. 515 base::MessageLoop loop_; // Needed to initialize the directory.
521 TestDirectorySetterUpper dir_maker_; 516 TestDirectorySetterUpper dir_maker_;
522 scoped_ptr<TestEntryFactory> entry_factory_; 517 scoped_ptr<TestEntryFactory> entry_factory_;
523 518
524 scoped_refptr<FakeModelWorker> ui_worker_; 519 scoped_refptr<FakeModelWorker> ui_worker_;
525 scoped_refptr<FakeModelWorker> password_worker_; 520 scoped_refptr<FakeModelWorker> password_worker_;
526 scoped_refptr<FakeModelWorker> passive_worker_; 521 scoped_refptr<FakeModelWorker> passive_worker_;
527 522
528 base::ObserverList<TypeDebugInfoObserver> type_observers_; 523 base::ObserverList<TypeDebugInfoObserver> type_observers_;
529 DirectoryTypeDebugInfoEmitter bookmarks_emitter_; 524 DirectoryTypeDebugInfoEmitter bookmarks_emitter_;
530 DirectoryTypeDebugInfoEmitter passwords_emitter_; 525 DirectoryTypeDebugInfoEmitter passwords_emitter_;
531 DirectoryTypeDebugInfoEmitter articles_emitter_; 526 DirectoryTypeDebugInfoEmitter articles_emitter_;
532 527
533 UpdateHandlerMap update_handler_map_; 528 base::ScopedPtrMap<ModelType, scoped_ptr<UpdateHandler>> update_handler_map_;
534 STLValueDeleter<UpdateHandlerMap> update_handler_map_deleter_;
535 }; 529 };
536 530
537 namespace { 531 namespace {
538 sync_pb::EntitySpecifics DefaultBookmarkSpecifics() { 532 sync_pb::EntitySpecifics DefaultBookmarkSpecifics() {
539 sync_pb::EntitySpecifics result; 533 sync_pb::EntitySpecifics result;
540 AddDefaultFieldValue(BOOKMARKS, &result); 534 AddDefaultFieldValue(BOOKMARKS, &result);
541 return result; 535 return result;
542 } 536 }
543 } // namespace 537 } // namespace
544 538
(...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after
1156 const UpdateCounters& counters = GetArticlesUpdateCounters(); 1150 const UpdateCounters& counters = GetArticlesUpdateCounters();
1157 EXPECT_EQ(1, counters.num_updates_applied); 1151 EXPECT_EQ(1, counters.num_updates_applied);
1158 EXPECT_EQ(1, counters.num_local_overwrites); 1152 EXPECT_EQ(1, counters.num_local_overwrites);
1159 EXPECT_EQ(0, counters.num_server_overwrites); 1153 EXPECT_EQ(0, counters.num_server_overwrites);
1160 local_metadata = entry_factory()->GetLocalAttachmentMetadataForItem(handle); 1154 local_metadata = entry_factory()->GetLocalAttachmentMetadataForItem(handle);
1161 EXPECT_EQ(server_metadata.SerializeAsString(), 1155 EXPECT_EQ(server_metadata.SerializeAsString(),
1162 local_metadata.SerializeAsString()); 1156 local_metadata.SerializeAsString());
1163 } 1157 }
1164 1158
1165 } // namespace syncer 1159 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/engine/commit_processor.cc ('k') | sync/engine/entity_tracker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698