app/core/ContactPushSource.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "ContactPushSource.h" | ||
| 2 | |||
| 3 | #include "ContactSyncCoordinator.h" | ||
| 4 | #include "data/ContactStore.h" | ||
| 5 | |||
| 6 | #include <QLoggingCategory> | ||
| 7 | |||
| 8 | Q_DECLARE_LOGGING_CATEGORY(lcDavPush) | ||
| 9 | |||
| 10 | 823 | ContactPushSource::ContactPushSource(ContactSyncCoordinator *contacts, QObject *parent) | |
| 11 |
1/1✓ Branch 4 → 5 taken 823 times.
|
823 | : DavPushSource(parent), m_contacts(contacts) { |
| 12 | 823 | m_clock.start(); | |
| 13 |
1/1✓ Branch 8 → 9 taken 823 times.
|
823 | connect(contacts, &ContactSyncCoordinator::pushOffersRead, this, &DavPushSource::discovered); |
| 14 |
1/1✓ Branch 10 → 11 taken 823 times.
|
823 | connect(contacts, &ContactSyncCoordinator::booksSynced, this, &DavPushSource::syncFinished); |
| 15 |
1/1✓ Branch 12 → 13 taken 823 times.
|
823 | connect(contacts, &ContactSyncCoordinator::booksRunStarted, this, &DavPushSource::batchStarted); |
| 16 |
1/1✓ Branch 14 → 15 taken 823 times.
|
823 | connect(&m_fallbackTimer, &QTimer::timeout, this, &ContactPushSource::pollFallback); |
| 17 | 823 | } | |
| 18 | |||
| 19 | 365 | QList<DavPushSourceCollection> ContactPushSource::collections(const QString &accountId) const { | |
| 20 | 365 | QList<DavPushSourceCollection> result; | |
| 21 |
5/5✓ Branch 2 → 3 taken 365 times.
✓ Branch 3 → 4 taken 365 times.
✓ Branch 4 → 5 taken 365 times.
✓ Branch 37 → 6 taken 166 times.
✓ Branch 37 → 38 taken 365 times.
|
531 | for (const QString &path : ContactSyncCoordinator::selectedBooks(accountId)) { |
| 22 |
3/5✓ Branch 8 → 9 taken 166 times.
✗ Branch 8 → 15 not taken.
✓ Branch 10 → 11 taken 166 times.
✓ Branch 11 → 12 taken 166 times.
✗ Branch 11 → 15 not taken.
|
166 | const auto book = m_contacts->store() && m_contacts->store()->isOpen() ? m_contacts->store()->book(accountId, path) |
| 23 |
1/1✓ Branch 13 → 14 taken 166 times.
|
166 | : std::nullopt; |
| 24 |
5/6✓ Branch 21 → 22 taken 6 times.
✓ Branch 21 → 24 taken 1 time.
✓ Branch 27 → 28 taken 7 times.
✓ Branch 27 → 31 taken 159 times.
✗ Branch 29 → 30 not taken.
✓ Branch 29 → 31 taken 7 times.
|
339 | result.append({path, book && !book->displayName.isEmpty() ? book->displayName : path, book && book->readOnly}); |
| 25 | 531 | } | |
| 26 | 365 | return result; | |
| 27 | 339 | } | |
| 28 | |||
| 29 | 94 | int ContactPushSource::intervalMinutes() const { | |
| 30 | 94 | return ContactSyncCoordinator::configuredIntervalMinutes(); | |
| 31 | } | ||
| 32 | |||
| 33 | 1 | void ContactPushSource::requestSync(const QString &accountId, const QStringList &paths, unsigned reasons) { | |
| 34 | 1 | m_contacts->syncBooks(accountId, paths, reasons); | |
| 35 | 1 | } | |
| 36 | |||
| 37 | 1 | void ContactPushSource::requestAll(unsigned reasons) { | |
| 38 | 1 | m_contacts->syncAll(reasons); | |
| 39 | 1 | } | |
| 40 | |||
| 41 | 1 | QString ContactPushSource::storedToken(const QString &accountId, const QString &path) const { | |
| 42 | 1 | return m_contacts->bookSyncToken(accountId, path); | |
| 43 | } | ||
| 44 | |||
| 45 | 821 | void ContactPushSource::setPushDontNotifyProvider(std::function<QString(const QString &, const QString &)> provider) { | |
| 46 | 821 | m_contacts->setPushDontNotifyProvider(std::move(provider)); | |
| 47 | 821 | } | |
| 48 | |||
| 49 | 7 | void ContactPushSource::setFallback(const QString &accountId, bool failing) { | |
| 50 |
2/2✓ Branch 2 → 3 taken 2 times.
✓ Branch 2 → 8 taken 5 times.
|
7 | if (!failing) { |
| 51 | 2 | m_fallbackUntil.remove(accountId); | |
| 52 |
1/2✓ Branch 5 → 6 taken 2 times.
✗ Branch 5 → 7 not taken.
|
2 | if (m_fallbackUntil.isEmpty()) m_fallbackTimer.stop(); |
| 53 | 2 | return; | |
| 54 | } | ||
| 55 | // S106-077: only a RUNNING window absorbs a new failure streak. An expired | ||
| 56 | // one is kept for the status display; a second streak re-arms it (it used | ||
| 57 | // to return here, and the books polled at the normal interval while the | ||
| 58 | // status said "in fallback"). | ||
| 59 | 5 | if (const auto it = m_fallbackUntil.constFind(accountId); | |
| 60 |
6/6✓ Branch 11 → 12 taken 2 times.
✓ Branch 11 → 16 taken 3 times.
✓ Branch 14 → 15 taken 1 time.
✓ Branch 14 → 16 taken 1 time.
✓ Branch 17 → 18 taken 1 time.
✓ Branch 17 → 19 taken 4 times.
|
5 | it != m_fallbackUntil.constEnd() && m_clock.elapsed() < *it) |
| 61 | 1 | return; | |
| 62 |
6/6✓ Branch 19 → 20 taken 4 times.
✓ Branch 23 → 24 taken 4 times.
✓ Branch 24 → 25 taken 4 times.
✓ Branch 25 → 26 taken 4 times.
✓ Branch 29 → 21 taken 4 times.
✓ Branch 29 → 30 taken 4 times.
|
8 | qCInfo(lcDavPush) << "Address book fallback polling for" << accountId; |
| 63 |
1/1✓ Branch 31 → 32 taken 4 times.
|
4 | m_fallbackUntil.insert(accountId, m_clock.elapsed() + m_timing.fallbackWindowMs); |
| 64 |
1/1✓ Branch 33 → 34 taken 4 times.
|
4 | m_contacts->syncBooks(accountId, {}, DavSyncReasonRecovery); // one immediate catch-up |
| 65 |
2/2✓ Branch 36 → 37 taken 3 times.
✓ Branch 36 → 38 taken 1 time.
|
4 | if (!m_fallbackTimer.isActive()) m_fallbackTimer.start(m_timing.fallbackPollMs); |
| 66 | } | ||
| 67 | |||
| 68 | 98 | bool ContactPushSource::inFallback(const QString &accountId) const { | |
| 69 | 98 | return m_fallbackUntil.contains(accountId); | |
| 70 | } | ||
| 71 | |||
| 72 | 105 | bool ContactPushSource::syncRunning(const QString &) const { | |
| 73 | 105 | return m_contacts->syncing(); | |
| 74 | } | ||
| 75 | |||
| 76 | 6 | void ContactPushSource::pollFallback() { | |
| 77 | 6 | const qint64 now = m_clock.elapsed(); | |
| 78 |
3/3✓ Branch 3 → 4 taken 6 times.
✓ Branch 16 → 5 taken 6 times.
✓ Branch 16 → 17 taken 6 times.
|
12 | for (auto it = m_fallbackUntil.begin(); it != m_fallbackUntil.end();) { |
| 79 |
2/2✓ Branch 6 → 7 taken 1 time.
✓ Branch 6 → 9 taken 5 times.
|
6 | if (now >= it.value()) { |
| 80 | // The window ended: the normal interval applies again (still "in | ||
| 81 | // fallback" for the status until push is healthy). | ||
| 82 | 1 | ++it; | |
| 83 | 1 | continue; | |
| 84 | } | ||
| 85 |
1/1✓ Branch 11 → 12 taken 5 times.
|
5 | m_contacts->syncBooks(it.key(), {}, DavSyncReasonPoll); |
| 86 | 5 | ++it; | |
| 87 | } | ||
| 88 | 6 | bool active = false; | |
| 89 |
5/6✓ Branch 21 → 22 taken 6 times.
✗ Branch 21 → 23 not taken.
✓ Branch 22 → 23 taken 5 times.
✓ Branch 22 → 24 taken 1 time.
✓ Branch 27 → 20 taken 6 times.
✓ Branch 27 → 28 taken 6 times.
|
12 | for (const qint64 until : std::as_const(m_fallbackUntil)) active = active || now < until; |
| 90 |
2/2✓ Branch 28 → 29 taken 1 time.
✓ Branch 28 → 30 taken 5 times.
|
6 | if (!active) m_fallbackTimer.stop(); |
| 91 | 6 | } | |
| 92 |