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_impl.h" | 5 #include "sync/internal_api/public/attachments/attachment_service_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.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/run_loop.h" | 10 #include "base/run_loop.h" |
11 #include "base/timer/mock_timer.h" | 11 #include "base/timer/mock_timer.h" |
| 12 #include "sync/internal_api/public/attachments/attachment_util.h" |
12 #include "sync/internal_api/public/attachments/fake_attachment_downloader.h" | 13 #include "sync/internal_api/public/attachments/fake_attachment_downloader.h" |
13 #include "sync/internal_api/public/attachments/fake_attachment_uploader.h" | 14 #include "sync/internal_api/public/attachments/fake_attachment_uploader.h" |
14 #include "testing/gmock/include/gmock/gmock-matchers.h" | 15 #include "testing/gmock/include/gmock/gmock-matchers.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
16 | 17 |
17 namespace syncer { | 18 namespace syncer { |
18 | 19 |
19 namespace { | 20 namespace { |
20 | 21 |
21 class MockAttachmentStore : public AttachmentStore, | 22 class MockAttachmentStore : public AttachmentStore, |
(...skipping 26 matching lines...) Expand all Loading... |
48 AttachmentIdList ids = read_ids.back(); | 49 AttachmentIdList ids = read_ids.back(); |
49 read_callbacks.pop_back(); | 50 read_callbacks.pop_back(); |
50 read_ids.pop_back(); | 51 read_ids.pop_back(); |
51 | 52 |
52 scoped_ptr<AttachmentMap> attachments(new AttachmentMap()); | 53 scoped_ptr<AttachmentMap> attachments(new AttachmentMap()); |
53 scoped_ptr<AttachmentIdList> unavailable_attachments( | 54 scoped_ptr<AttachmentIdList> unavailable_attachments( |
54 new AttachmentIdList()); | 55 new AttachmentIdList()); |
55 for (AttachmentIdList::const_iterator iter = ids.begin(); iter != ids.end(); | 56 for (AttachmentIdList::const_iterator iter = ids.begin(); iter != ids.end(); |
56 ++iter) { | 57 ++iter) { |
57 if (local_attachments.find(*iter) != local_attachments.end()) { | 58 if (local_attachments.find(*iter) != local_attachments.end()) { |
58 Attachment attachment = Attachment::CreateWithId(*iter, data); | 59 uint32_t crc32c = ComputeCrc32c(data); |
| 60 Attachment attachment = |
| 61 Attachment::CreateFromParts(*iter, data, crc32c); |
59 attachments->insert(std::make_pair(*iter, attachment)); | 62 attachments->insert(std::make_pair(*iter, attachment)); |
60 } else { | 63 } else { |
61 unavailable_attachments->push_back(*iter); | 64 unavailable_attachments->push_back(*iter); |
62 } | 65 } |
63 } | 66 } |
64 Result result = | 67 Result result = |
65 unavailable_attachments->empty() ? SUCCESS : UNSPECIFIED_ERROR; | 68 unavailable_attachments->empty() ? SUCCESS : UNSPECIFIED_ERROR; |
66 | 69 |
67 base::MessageLoop::current()->PostTask( | 70 base::MessageLoop::current()->PostTask( |
68 FROM_HERE, | 71 FROM_HERE, |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 download_requests.insert(std::make_pair(id, callback)); | 108 download_requests.insert(std::make_pair(id, callback)); |
106 } | 109 } |
107 | 110 |
108 // Multiple requests to download will be active at the same time. | 111 // Multiple requests to download will be active at the same time. |
109 // RespondToDownload should respond to only one of them. | 112 // RespondToDownload should respond to only one of them. |
110 void RespondToDownload(const AttachmentId& id, const DownloadResult& result) { | 113 void RespondToDownload(const AttachmentId& id, const DownloadResult& result) { |
111 ASSERT_TRUE(download_requests.find(id) != download_requests.end()); | 114 ASSERT_TRUE(download_requests.find(id) != download_requests.end()); |
112 scoped_ptr<Attachment> attachment; | 115 scoped_ptr<Attachment> attachment; |
113 if (result == DOWNLOAD_SUCCESS) { | 116 if (result == DOWNLOAD_SUCCESS) { |
114 scoped_refptr<base::RefCountedString> data = new base::RefCountedString(); | 117 scoped_refptr<base::RefCountedString> data = new base::RefCountedString(); |
115 attachment.reset(new Attachment(Attachment::CreateWithId(id, data))); | 118 uint32_t crc32c = ComputeCrc32c(data); |
| 119 attachment.reset( |
| 120 new Attachment(Attachment::CreateFromParts(id, data, crc32c))); |
116 } | 121 } |
117 base::MessageLoop::current()->PostTask( | 122 base::MessageLoop::current()->PostTask( |
118 FROM_HERE, | 123 FROM_HERE, |
119 base::Bind(download_requests[id], result, base::Passed(&attachment))); | 124 base::Bind(download_requests[id], result, base::Passed(&attachment))); |
120 | 125 |
121 download_requests.erase(id); | 126 download_requests.erase(id); |
122 } | 127 } |
123 | 128 |
124 std::map<AttachmentId, DownloadCallback> download_requests; | 129 std::map<AttachmentId, DownloadCallback> download_requests; |
125 | 130 |
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
548 net::NetworkChangeNotifier::NotifyObserversOfNetworkChangeForTests( | 553 net::NetworkChangeNotifier::NotifyObserversOfNetworkChangeForTests( |
549 net::NetworkChangeNotifier::CONNECTION_WIFI); | 554 net::NetworkChangeNotifier::CONNECTION_WIFI); |
550 RunLoop(); | 555 RunLoop(); |
551 | 556 |
552 // No longer in backoff. | 557 // No longer in backoff. |
553 ASSERT_TRUE(mock_timer()->IsRunning()); | 558 ASSERT_TRUE(mock_timer()->IsRunning()); |
554 ASSERT_EQ(base::TimeDelta(), mock_timer()->GetCurrentDelay()); | 559 ASSERT_EQ(base::TimeDelta(), mock_timer()->GetCurrentDelay()); |
555 } | 560 } |
556 | 561 |
557 } // namespace syncer | 562 } // namespace syncer |
OLD | NEW |