-
Notifications
You must be signed in to change notification settings - Fork 519
/
NotificationManager.h
78 lines (64 loc) · 3.06 KB
/
NotificationManager.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright 2012 Viewfinder. All rights reserved.
// Author: Spencer Kimball.
#ifndef VIEWFINDER_NOTIFICATION_MANAGER_H
#define VIEWFINDER_NOTIFICATION_MANAGER_H
#import "Callback.h"
#import "DB.h"
#import "InvalidateMetadata.pb.h"
#import "ScopedPtr.h"
#import "WallTime.h"
class AppState;
class NotificationSelection;
class QueryNotificationsResponse;
class NotificationManager {
public:
NotificationManager(AppState* state);
~NotificationManager();
// Application received a remote APNs notification message.
void RemoteNotification(const string& message);
// Processes the results of call to query_notifications. The last
// query notification key is updated, and if necessary, the
// low-water mark for notifications with min_required_version set
// too high for this client to understand. Invokes the callbacks in
// the ProcessNotificationsCallback set under normal conditions. If
// a nuclear, all-out invalidation is specified, or if a gap in the
// notification sequence is detected, internal query state is fully
// reset and the callbacks in NuclearInvalidationCallback are invoked.
//
// If "process" is false, the notification process callbacks are not
// invoked. This is the case when querying notifications to find the
// high water mark at the start of rebuilding full asset state.
void ProcessQueryNotifications(const QueryNotificationsResponse& p,
const NotificationSelection& cs,
bool process, const DBHandle& updates);
// Validates queried notifications.
void Validate(const NotificationSelection& s, const DBHandle& updates);
// Invalidates notification selection so that new notifications are
// queried. If applicable, augments or creates the
// NotificationSelection which indicates which notifications are
// considered invalid due to a server response with
// min_required_version too high for the client to understand.
void Invalidate(const DBHandle& updates);
// Gets the current notification selection. Returns true if the
// notification selection is invalidated and requires re-querying;
// false otherwise.
bool GetInvalidation(NotificationSelection* cs);
// Callback set for processing query notifications.
// Used by PhotoManager and ContactManager.
typedef CallbackSet2<const QueryNotificationsResponse&, const DBHandle&> ProcessNotificationsCallback;
ProcessNotificationsCallback* process_notifications() { return &process_notifications_; }
// Callback set for resetting query state.
// Used by PhotoManager, ContactManager, & NetworkManager.
typedef CallbackSet1<const DBHandle&> NuclearInvalidationCallback;
NuclearInvalidationCallback* nuclear_invalidations() { return &nuclear_invalidations_; }
private:
void CommonInit();
private:
AppState* state_;
WallTime last_query_time_;
string query_notifications_last_key_;
NotificationSelection notification_selection_;
ProcessNotificationsCallback process_notifications_;
NuclearInvalidationCallback nuclear_invalidations_;
};
#endif // VIEWFINDER_NOTIFICATION_MANAGER_H