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

Side by Side Diff: sync/internal_api/attachments/attachment_service_impl_unittest.cc

Issue 710073003: Store attachment crc in AttachmentStore (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 6 years, 1 month 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 "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
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 crc = ComputeCrc32c(data);
maniscalco 2014/11/11 00:44:54 crc -> crc32c (and elsewhere in this file)
pavely 2014/11/11 22:27:15 Done.
60 Attachment attachment = Attachment::RestoreExisting(*iter, data, crc);
59 attachments->insert(std::make_pair(*iter, attachment)); 61 attachments->insert(std::make_pair(*iter, attachment));
60 } else { 62 } else {
61 unavailable_attachments->push_back(*iter); 63 unavailable_attachments->push_back(*iter);
62 } 64 }
63 } 65 }
64 Result result = 66 Result result =
65 unavailable_attachments->empty() ? SUCCESS : UNSPECIFIED_ERROR; 67 unavailable_attachments->empty() ? SUCCESS : UNSPECIFIED_ERROR;
66 68
67 base::MessageLoop::current()->PostTask( 69 base::MessageLoop::current()->PostTask(
68 FROM_HERE, 70 FROM_HERE,
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 download_requests.insert(std::make_pair(id, callback)); 107 download_requests.insert(std::make_pair(id, callback));
106 } 108 }
107 109
108 // Multiple requests to download will be active at the same time. 110 // Multiple requests to download will be active at the same time.
109 // RespondToDownload should respond to only one of them. 111 // RespondToDownload should respond to only one of them.
110 void RespondToDownload(const AttachmentId& id, const DownloadResult& result) { 112 void RespondToDownload(const AttachmentId& id, const DownloadResult& result) {
111 ASSERT_TRUE(download_requests.find(id) != download_requests.end()); 113 ASSERT_TRUE(download_requests.find(id) != download_requests.end());
112 scoped_ptr<Attachment> attachment; 114 scoped_ptr<Attachment> attachment;
113 if (result == DOWNLOAD_SUCCESS) { 115 if (result == DOWNLOAD_SUCCESS) {
114 scoped_refptr<base::RefCountedString> data = new base::RefCountedString(); 116 scoped_refptr<base::RefCountedString> data = new base::RefCountedString();
115 attachment.reset(new Attachment(Attachment::CreateWithId(id, data))); 117 uint32_t crc = ComputeCrc32c(data);
118 attachment.reset(
119 new Attachment(Attachment::RestoreExisting(id, data, crc)));
116 } 120 }
117 base::MessageLoop::current()->PostTask( 121 base::MessageLoop::current()->PostTask(
118 FROM_HERE, 122 FROM_HERE,
119 base::Bind(download_requests[id], result, base::Passed(&attachment))); 123 base::Bind(download_requests[id], result, base::Passed(&attachment)));
120 124
121 download_requests.erase(id); 125 download_requests.erase(id);
122 } 126 }
123 127
124 std::map<AttachmentId, DownloadCallback> download_requests; 128 std::map<AttachmentId, DownloadCallback> download_requests;
125 129
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 net::NetworkChangeNotifier::NotifyObserversOfNetworkChangeForTests( 552 net::NetworkChangeNotifier::NotifyObserversOfNetworkChangeForTests(
549 net::NetworkChangeNotifier::CONNECTION_WIFI); 553 net::NetworkChangeNotifier::CONNECTION_WIFI);
550 RunLoop(); 554 RunLoop();
551 555
552 // No longer in backoff. 556 // No longer in backoff.
553 ASSERT_TRUE(mock_timer()->IsRunning()); 557 ASSERT_TRUE(mock_timer()->IsRunning());
554 ASSERT_EQ(base::TimeDelta(), mock_timer()->GetCurrentDelay()); 558 ASSERT_EQ(base::TimeDelta(), mock_timer()->GetCurrentDelay());
555 } 559 }
556 560
557 } // namespace syncer 561 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698