OLD | NEW |
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/internal_api/public/attachments/attachment_service_proxy.h" | 5 #include "sync/internal_api/public/attachments/attachment_service_proxy.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/memory/ref_counted_memory.h" | 8 #include "base/memory/ref_counted_memory.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 public base::NonThreadSafe { | 27 public base::NonThreadSafe { |
28 public: | 28 public: |
29 StubAttachmentService() : call_count_(0), weak_ptr_factory_(this) { | 29 StubAttachmentService() : call_count_(0), weak_ptr_factory_(this) { |
30 // DetachFromThread because we will be constructed in one thread and | 30 // DetachFromThread because we will be constructed in one thread and |
31 // used/destroyed in another. | 31 // used/destroyed in another. |
32 DetachFromThread(); | 32 DetachFromThread(); |
33 } | 33 } |
34 | 34 |
35 virtual ~StubAttachmentService() {} | 35 virtual ~StubAttachmentService() {} |
36 | 36 |
37 virtual AttachmentStore* GetStore() OVERRIDE { return NULL; } | 37 virtual AttachmentStore* GetStore() override { return NULL; } |
38 | 38 |
39 virtual void GetOrDownloadAttachments(const AttachmentIdList& attachment_ids, | 39 virtual void GetOrDownloadAttachments(const AttachmentIdList& attachment_ids, |
40 const GetOrDownloadCallback& callback) | 40 const GetOrDownloadCallback& callback) |
41 OVERRIDE { | 41 override { |
42 CalledOnValidThread(); | 42 CalledOnValidThread(); |
43 Increment(); | 43 Increment(); |
44 scoped_ptr<AttachmentMap> attachments(new AttachmentMap()); | 44 scoped_ptr<AttachmentMap> attachments(new AttachmentMap()); |
45 base::MessageLoop::current()->PostTask( | 45 base::MessageLoop::current()->PostTask( |
46 FROM_HERE, | 46 FROM_HERE, |
47 base::Bind(callback, | 47 base::Bind(callback, |
48 AttachmentService::GET_UNSPECIFIED_ERROR, | 48 AttachmentService::GET_UNSPECIFIED_ERROR, |
49 base::Passed(&attachments))); | 49 base::Passed(&attachments))); |
50 } | 50 } |
51 | 51 |
52 virtual void DropAttachments(const AttachmentIdList& attachment_ids, | 52 virtual void DropAttachments(const AttachmentIdList& attachment_ids, |
53 const DropCallback& callback) OVERRIDE { | 53 const DropCallback& callback) override { |
54 CalledOnValidThread(); | 54 CalledOnValidThread(); |
55 Increment(); | 55 Increment(); |
56 base::MessageLoop::current()->PostTask( | 56 base::MessageLoop::current()->PostTask( |
57 FROM_HERE, base::Bind(callback, AttachmentService::DROP_SUCCESS)); | 57 FROM_HERE, base::Bind(callback, AttachmentService::DROP_SUCCESS)); |
58 } | 58 } |
59 | 59 |
60 virtual void UploadAttachments( | 60 virtual void UploadAttachments( |
61 const AttachmentIdSet& attachments_ids) OVERRIDE { | 61 const AttachmentIdSet& attachments_ids) override { |
62 CalledOnValidThread(); | 62 CalledOnValidThread(); |
63 Increment(); | 63 Increment(); |
64 } | 64 } |
65 | 65 |
66 virtual base::WeakPtr<AttachmentService> AsWeakPtr() { | 66 virtual base::WeakPtr<AttachmentService> AsWeakPtr() { |
67 return weak_ptr_factory_.GetWeakPtr(); | 67 return weak_ptr_factory_.GetWeakPtr(); |
68 } | 68 } |
69 | 69 |
70 // Return the number of method invocations. | 70 // Return the number of method invocations. |
71 int GetCallCount() const { | 71 int GetCallCount() const { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 callback_get_or_download = | 103 callback_get_or_download = |
104 base::Bind(&AttachmentServiceProxyTest::IncrementGetOrDownload, | 104 base::Bind(&AttachmentServiceProxyTest::IncrementGetOrDownload, |
105 base::Unretained(this)); | 105 base::Unretained(this)); |
106 callback_drop = base::Bind(&AttachmentServiceProxyTest::IncrementDrop, | 106 callback_drop = base::Bind(&AttachmentServiceProxyTest::IncrementDrop, |
107 base::Unretained(this)); | 107 base::Unretained(this)); |
108 count_callback_get_or_download = 0; | 108 count_callback_get_or_download = 0; |
109 count_callback_drop = 0; | 109 count_callback_drop = 0; |
110 } | 110 } |
111 | 111 |
112 virtual void TearDown() | 112 virtual void TearDown() |
113 OVERRIDE { | 113 override { |
114 // We must take care to call the stub's destructor on the stub_thread | 114 // We must take care to call the stub's destructor on the stub_thread |
115 // because that's the thread to which its WeakPtrs are bound. | 115 // because that's the thread to which its WeakPtrs are bound. |
116 if (stub) { | 116 if (stub) { |
117 stub_thread->message_loop()->DeleteSoon(FROM_HERE, stub.release()); | 117 stub_thread->message_loop()->DeleteSoon(FROM_HERE, stub.release()); |
118 WaitForStubThread(); | 118 WaitForStubThread(); |
119 } | 119 } |
120 stub_thread->Stop(); | 120 stub_thread->Stop(); |
121 } | 121 } |
122 | 122 |
123 // a GetOrDownloadCallback | 123 // a GetOrDownloadCallback |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 // Now that the wrapped object has been destroyed, call again and see that we | 200 // Now that the wrapped object has been destroyed, call again and see that we |
201 // don't crash and the count remains the same. | 201 // don't crash and the count remains the same. |
202 proxy->GetOrDownloadAttachments(AttachmentIdList(), callback_get_or_download); | 202 proxy->GetOrDownloadAttachments(AttachmentIdList(), callback_get_or_download); |
203 WaitForStubThread(); | 203 WaitForStubThread(); |
204 WaitForStubThread(); | 204 WaitForStubThread(); |
205 loop.RunUntilIdle(); | 205 loop.RunUntilIdle(); |
206 EXPECT_EQ(1, count_callback_get_or_download); | 206 EXPECT_EQ(1, count_callback_get_or_download); |
207 } | 207 } |
208 | 208 |
209 } // namespace syncer | 209 } // namespace syncer |
OLD | NEW |