| 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 14 matching lines...) Expand all Loading... |
| 25 // its methods are invoked. | 25 // its methods are invoked. |
| 26 class StubAttachmentService : public AttachmentService, | 26 class StubAttachmentService : public AttachmentService, |
| 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 ~StubAttachmentService() override {} |
| 36 | 36 |
| 37 virtual AttachmentStore* GetStore() override { return NULL; } | 37 AttachmentStore* GetStore() override { return NULL; } |
| 38 | 38 |
| 39 virtual void GetOrDownloadAttachments(const AttachmentIdList& attachment_ids, | 39 void GetOrDownloadAttachments( |
| 40 const GetOrDownloadCallback& callback) | 40 const AttachmentIdList& attachment_ids, |
| 41 override { | 41 const GetOrDownloadCallback& callback) 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 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 void UploadAttachments(const AttachmentIdSet& attachments_ids) override { |
| 61 const AttachmentIdSet& attachments_ids) override { | |
| 62 CalledOnValidThread(); | 61 CalledOnValidThread(); |
| 63 Increment(); | 62 Increment(); |
| 64 } | 63 } |
| 65 | 64 |
| 66 virtual base::WeakPtr<AttachmentService> AsWeakPtr() { | 65 virtual base::WeakPtr<AttachmentService> AsWeakPtr() { |
| 67 return weak_ptr_factory_.GetWeakPtr(); | 66 return weak_ptr_factory_.GetWeakPtr(); |
| 68 } | 67 } |
| 69 | 68 |
| 70 // Return the number of method invocations. | 69 // Return the number of method invocations. |
| 71 int GetCallCount() const { | 70 int GetCallCount() const { |
| (...skipping 128 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 | 199 // Now that the wrapped object has been destroyed, call again and see that we |
| 201 // don't crash and the count remains the same. | 200 // don't crash and the count remains the same. |
| 202 proxy->GetOrDownloadAttachments(AttachmentIdList(), callback_get_or_download); | 201 proxy->GetOrDownloadAttachments(AttachmentIdList(), callback_get_or_download); |
| 203 WaitForStubThread(); | 202 WaitForStubThread(); |
| 204 WaitForStubThread(); | 203 WaitForStubThread(); |
| 205 loop.RunUntilIdle(); | 204 loop.RunUntilIdle(); |
| 206 EXPECT_EQ(1, count_callback_get_or_download); | 205 EXPECT_EQ(1, count_callback_get_or_download); |
| 207 } | 206 } |
| 208 | 207 |
| 209 } // namespace syncer | 208 } // namespace syncer |
| OLD | NEW |