OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/chromeos/gdata/gdata_contacts_service_stub.h" | 5 #include "chrome/browser/chromeos/gdata/gdata_contacts_service_stub.h" |
6 | 6 |
7 #include "chrome/browser/chromeos/contacts/contact.pb.h" | 7 #include "chrome/browser/chromeos/contacts/contact.pb.h" |
8 #include "chrome/browser/chromeos/contacts/contact_test_util.h" | 8 #include "chrome/browser/chromeos/contacts/contact_test_util.h" |
9 #include "chrome/browser/chromeos/gdata/gdata_util.h" | 9 #include "chrome/browser/chromeos/gdata/gdata_util.h" |
10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
11 | 11 |
12 using content::BrowserThread; | 12 using content::BrowserThread; |
13 | 13 |
14 namespace gdata { | 14 namespace gdata { |
15 | 15 |
16 GDataContactsServiceStub::GDataContactsServiceStub() | 16 GDataContactsServiceStub::GDataContactsServiceStub() |
17 : download_should_succeed_(true) { | 17 : num_download_requests_(0), |
| 18 download_should_succeed_(true) { |
18 } | 19 } |
19 | 20 |
20 GDataContactsServiceStub::~GDataContactsServiceStub() { | 21 GDataContactsServiceStub::~GDataContactsServiceStub() { |
21 } | 22 } |
22 | 23 |
23 void GDataContactsServiceStub::SetContacts( | 24 void GDataContactsServiceStub::SetContacts( |
24 const contacts::ContactPointers& contacts, | 25 const contacts::ContactPointers& contacts, |
25 const base::Time& expected_min_update_time) { | 26 const base::Time& expected_min_update_time) { |
26 contacts::test::CopyContacts(contacts, &contacts_); | 27 contacts::test::CopyContacts(contacts, &contacts_); |
27 expected_min_update_time_ = expected_min_update_time; | 28 expected_min_update_time_ = expected_min_update_time; |
28 } | 29 } |
29 | 30 |
30 void GDataContactsServiceStub::Initialize() { | 31 void GDataContactsServiceStub::Initialize() { |
31 } | 32 } |
32 | 33 |
33 void GDataContactsServiceStub::DownloadContacts( | 34 void GDataContactsServiceStub::DownloadContacts( |
34 SuccessCallback success_callback, | 35 SuccessCallback success_callback, |
35 FailureCallback failure_callback, | 36 FailureCallback failure_callback, |
36 const base::Time& min_update_time) { | 37 const base::Time& min_update_time) { |
37 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 38 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 39 num_download_requests_++; |
38 | 40 |
39 if (!download_should_succeed_) { | 41 if (!download_should_succeed_) { |
40 failure_callback.Run(); | 42 failure_callback.Run(); |
41 return; | 43 return; |
42 } | 44 } |
43 | 45 |
44 if (min_update_time != expected_min_update_time_) { | 46 if (min_update_time != expected_min_update_time_) { |
45 LOG(ERROR) << "Actual minimum update time (" | 47 LOG(ERROR) << "Actual minimum update time (" |
46 << util::FormatTimeAsString(min_update_time) << ") " | 48 << util::FormatTimeAsString(min_update_time) << ") " |
47 << "differed from expected (" | 49 << "differed from expected (" |
48 << util::FormatTimeAsString(expected_min_update_time_) | 50 << util::FormatTimeAsString(expected_min_update_time_) |
49 << "); not returning any contacts"; | 51 << "); not returning any contacts"; |
50 failure_callback.Run(); | 52 failure_callback.Run(); |
51 return; | 53 return; |
52 } | 54 } |
53 | 55 |
54 scoped_ptr<ScopedVector<contacts::Contact> > contacts( | 56 scoped_ptr<ScopedVector<contacts::Contact> > contacts( |
55 new ScopedVector<contacts::Contact>()); | 57 new ScopedVector<contacts::Contact>()); |
56 contacts::test::CopyContacts(contacts_, contacts.get()); | 58 contacts::test::CopyContacts(contacts_, contacts.get()); |
57 success_callback.Run(contacts.Pass()); | 59 success_callback.Run(contacts.Pass()); |
58 } | 60 } |
59 | 61 |
60 } // namespace contacts | 62 } // namespace contacts |
OLD | NEW |