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

Side by Side Diff: components/sync_driver/generic_change_processor_unittest.cc

Issue 548373003: Move AttachmentStore ownership to datatype (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Don't create AttachmentService in GenericChangeProcessor if AttachmentStore is NULL Created 6 years, 3 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 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 "components/sync_driver/generic_change_processor.h" 5 #include "components/sync_driver/generic_change_processor.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/memory/weak_ptr.h" 8 #include "base/memory/weak_ptr.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
(...skipping 18 matching lines...) Expand all
29 29
30 namespace sync_driver { 30 namespace sync_driver {
31 31
32 namespace { 32 namespace {
33 33
34 const char kTestData[] = "some data"; 34 const char kTestData[] = "some data";
35 35
36 // A mock that keeps track of attachments passed to StoreAttachments. 36 // A mock that keeps track of attachments passed to StoreAttachments.
37 class MockAttachmentService : public syncer::AttachmentServiceImpl { 37 class MockAttachmentService : public syncer::AttachmentServiceImpl {
38 public: 38 public:
39 MockAttachmentService(); 39 MockAttachmentService(
40 const scoped_refptr<syncer::AttachmentStore>& attachment_store);
40 virtual ~MockAttachmentService(); 41 virtual ~MockAttachmentService();
41 virtual void StoreAttachments(const syncer::AttachmentList& attachments, 42 virtual void StoreAttachments(const syncer::AttachmentList& attachments,
42 const StoreCallback& callback) OVERRIDE; 43 const StoreCallback& callback) OVERRIDE;
43 std::vector<syncer::AttachmentList>* attachment_lists(); 44 std::vector<syncer::AttachmentList>* attachment_lists();
44 45
45 private: 46 private:
46 std::vector<syncer::AttachmentList> attachment_lists_; 47 std::vector<syncer::AttachmentList> attachment_lists_;
47 }; 48 };
48 49
49 MockAttachmentService::MockAttachmentService() 50 MockAttachmentService::MockAttachmentService(
50 : AttachmentServiceImpl( 51 const scoped_refptr<syncer::AttachmentStore>& attachment_store)
51 scoped_ptr<syncer::AttachmentStore>(new syncer::FakeAttachmentStore( 52 : AttachmentServiceImpl(attachment_store,
52 base::MessageLoopProxy::current())), 53 scoped_ptr<syncer::AttachmentUploader>(
53 scoped_ptr<syncer::AttachmentUploader>( 54 new syncer::FakeAttachmentUploader),
54 new syncer::FakeAttachmentUploader), 55 scoped_ptr<syncer::AttachmentDownloader>(
55 scoped_ptr<syncer::AttachmentDownloader>( 56 new syncer::FakeAttachmentDownloader),
56 new syncer::FakeAttachmentDownloader), 57 NULL) {
57 NULL) {
58 } 58 }
59 59
60 MockAttachmentService::~MockAttachmentService() { 60 MockAttachmentService::~MockAttachmentService() {
61 } 61 }
62 62
63 void MockAttachmentService::StoreAttachments( 63 void MockAttachmentService::StoreAttachments(
64 const syncer::AttachmentList& attachments, 64 const syncer::AttachmentList& attachments,
65 const StoreCallback& callback) { 65 const StoreCallback& callback) {
66 attachment_lists_.push_back(attachments); 66 attachment_lists_.push_back(attachments);
67 AttachmentServiceImpl::StoreAttachments(attachments, callback); 67 AttachmentServiceImpl::StoreAttachments(attachments, callback);
(...skipping 12 matching lines...) Expand all
80 : attachment_service_(attachment_service.Pass()) {} 80 : attachment_service_(attachment_service.Pass()) {}
81 81
82 virtual base::WeakPtr<syncer::SyncableService> GetSyncableServiceForType( 82 virtual base::WeakPtr<syncer::SyncableService> GetSyncableServiceForType(
83 syncer::ModelType type) OVERRIDE { 83 syncer::ModelType type) OVERRIDE {
84 // Shouldn't be called for this test. 84 // Shouldn't be called for this test.
85 NOTREACHED(); 85 NOTREACHED();
86 return base::WeakPtr<syncer::SyncableService>(); 86 return base::WeakPtr<syncer::SyncableService>();
87 } 87 }
88 88
89 virtual scoped_ptr<syncer::AttachmentService> CreateAttachmentService( 89 virtual scoped_ptr<syncer::AttachmentService> CreateAttachmentService(
90 const scoped_refptr<syncer::AttachmentStore>& attachment_store,
90 const syncer::UserShare& user_share, 91 const syncer::UserShare& user_share,
91 syncer::AttachmentService::Delegate* delegate) OVERRIDE { 92 syncer::AttachmentService::Delegate* delegate) OVERRIDE {
92 EXPECT_TRUE(attachment_service_ != NULL); 93 EXPECT_TRUE(attachment_service_ != NULL);
93 return attachment_service_.Pass(); 94 return attachment_service_.Pass();
94 } 95 }
95 96
96 private: 97 private:
97 scoped_ptr<syncer::AttachmentService> attachment_service_; 98 scoped_ptr<syncer::AttachmentService> attachment_service_;
98 }; 99 };
99 100
(...skipping 10 matching lines...) Expand all
110 111
111 virtual void SetUp() OVERRIDE { 112 virtual void SetUp() OVERRIDE {
112 test_user_share_.SetUp(); 113 test_user_share_.SetUp();
113 syncer::ModelTypeSet types = syncer::ProtocolTypes(); 114 syncer::ModelTypeSet types = syncer::ProtocolTypes();
114 for (syncer::ModelTypeSet::Iterator iter = types.First(); iter.Good(); 115 for (syncer::ModelTypeSet::Iterator iter = types.First(); iter.Good();
115 iter.Inc()) { 116 iter.Inc()) {
116 syncer::TestUserShare::CreateRoot(iter.Get(), 117 syncer::TestUserShare::CreateRoot(iter.Get(),
117 test_user_share_.user_share()); 118 test_user_share_.user_share());
118 } 119 }
119 test_user_share_.encryption_handler()->Init(); 120 test_user_share_.encryption_handler()->Init();
121 scoped_refptr<syncer::AttachmentStore> attachment_store(
122 new syncer::FakeAttachmentStore(base::MessageLoopProxy::current()));
123
120 scoped_ptr<MockAttachmentService> mock_attachment_service( 124 scoped_ptr<MockAttachmentService> mock_attachment_service(
121 new MockAttachmentService); 125 new MockAttachmentService(attachment_store));
122 // GenericChangeProcessor takes ownership of the AttachmentService, but we 126 // GenericChangeProcessor takes ownership of the AttachmentService, but we
123 // need to have a pointer to it so we can see that it was used properly. 127 // need to have a pointer to it so we can see that it was used properly.
124 // Take a pointer and trust that GenericChangeProcessor does not prematurely 128 // Take a pointer and trust that GenericChangeProcessor does not prematurely
125 // destroy it. 129 // destroy it.
126 mock_attachment_service_ = mock_attachment_service.get(); 130 mock_attachment_service_ = mock_attachment_service.get();
127 sync_factory_.reset(new MockSyncApiComponentFactory( 131 sync_factory_.reset(new MockSyncApiComponentFactory(
128 mock_attachment_service.PassAs<syncer::AttachmentService>())); 132 mock_attachment_service.PassAs<syncer::AttachmentService>()));
129 change_processor_.reset( 133 change_processor_.reset(
130 new GenericChangeProcessor(&data_type_error_handler_, 134 new GenericChangeProcessor(&data_type_error_handler_,
131 syncable_service_ptr_factory_.GetWeakPtr(), 135 syncable_service_ptr_factory_.GetWeakPtr(),
132 merge_result_ptr_factory_.GetWeakPtr(), 136 merge_result_ptr_factory_.GetWeakPtr(),
133 test_user_share_.user_share(), 137 test_user_share_.user_share(),
134 sync_factory_.get())); 138 sync_factory_.get(),
139 attachment_store));
135 } 140 }
136 141
137 virtual void TearDown() OVERRIDE { 142 virtual void TearDown() OVERRIDE {
138 mock_attachment_service_ = NULL; 143 mock_attachment_service_ = NULL;
139 test_user_share_.TearDown(); 144 test_user_share_.TearDown();
140 } 145 }
141 146
142 void BuildChildNodes(int n) { 147 void BuildChildNodes(int n) {
143 syncer::WriteTransaction trans(FROM_HERE, user_share()); 148 syncer::WriteTransaction trans(FROM_HERE, user_share());
144 syncer::ReadNode root(&trans); 149 syncer::ReadNode root(&trans);
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 syncer::ReadNode node(&read_transaction); 418 syncer::ReadNode node(&read_transaction);
414 ASSERT_EQ(node.InitByClientTagLookup(syncer::PREFERENCES, tag), 419 ASSERT_EQ(node.InitByClientTagLookup(syncer::PREFERENCES, tag),
415 syncer::BaseNode::INIT_OK); 420 syncer::BaseNode::INIT_OK);
416 syncer::AttachmentIdList attachment_ids = node.GetAttachmentIds(); 421 syncer::AttachmentIdList attachment_ids = node.GetAttachmentIds();
417 EXPECT_EQ(1U, attachment_ids.size()); 422 EXPECT_EQ(1U, attachment_ids.size());
418 } 423 }
419 424
420 } // namespace 425 } // namespace
421 426
422 } // namespace sync_driver 427 } // namespace sync_driver
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698