blob: e953c3c3102155c7a091ae6d8335396456c2830f (
plain)
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
79
80
81
82
83
84
85
86
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// An implementation of SyncNotifier that wraps InvalidationNotifier
// on its own thread.
#ifndef SYNC_NOTIFIER_NON_BLOCKING_INVALIDATION_NOTIFIER_H_
#define SYNC_NOTIFIER_NON_BLOCKING_INVALIDATION_NOTIFIER_H_
#pragma once
#include <string>
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
#include "jingle/notifier/base/notifier_options.h"
#include "sync/internal_api/public/util/weak_handle.h"
#include "sync/notifier/invalidation_state_tracker.h"
#include "sync/notifier/sync_notifier.h"
#include "sync/notifier/sync_notifier_observer.h"
namespace base {
class SingleThreadTaskRunner;
} // namespace base
namespace syncer {
class NonBlockingInvalidationNotifier
: public SyncNotifier,
// SyncNotifierObserver to "observe" our Core via WeakHandle.
public SyncNotifierObserver {
public:
// |invalidation_state_tracker| must be initialized.
NonBlockingInvalidationNotifier(
const notifier::NotifierOptions& notifier_options,
const InvalidationVersionMap& initial_max_invalidation_versions,
const std::string& initial_invalidation_state,
const syncer::WeakHandle<InvalidationStateTracker>&
invalidation_state_tracker,
const std::string& client_info);
virtual ~NonBlockingInvalidationNotifier();
// SyncNotifier implementation.
virtual void AddObserver(SyncNotifierObserver* observer) OVERRIDE;
virtual void RemoveObserver(SyncNotifierObserver* observer) OVERRIDE;
virtual void SetUniqueId(const std::string& unique_id) OVERRIDE;
virtual void SetStateDeprecated(const std::string& state) OVERRIDE;
virtual void UpdateCredentials(
const std::string& email, const std::string& token) OVERRIDE;
virtual void UpdateEnabledTypes(
syncable::ModelTypeSet enabled_types) OVERRIDE;
virtual void SendNotification(
syncable::ModelTypeSet changed_types) OVERRIDE;
// SyncNotifierObserver implementation.
virtual void OnNotificationsEnabled() OVERRIDE;
virtual void OnNotificationsDisabled(
NotificationsDisabledReason reason) OVERRIDE;
virtual void OnIncomingNotification(
const syncable::ModelTypePayloadMap& type_payloads,
IncomingNotificationSource source) OVERRIDE;
private:
class Core;
base::WeakPtrFactory<NonBlockingInvalidationNotifier> weak_ptr_factory_;
// Our observers (which must live on the parent thread).
ObserverList<SyncNotifierObserver> observers_;
// The real guts of NonBlockingInvalidationNotifier, which allows
// this class to live completely on the parent thread.
scoped_refptr<Core> core_;
scoped_refptr<base::SingleThreadTaskRunner> parent_task_runner_;
scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_;
DISALLOW_COPY_AND_ASSIGN(NonBlockingInvalidationNotifier);
};
} // namespace syncer
#endif // SYNC_NOTIFIER_NON_BLOCKING_INVALIDATION_NOTIFIER_H_
|