blob: cc133bdf1cd5df5486aa689110be617686b720a8 (
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
|
// 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.
#ifndef CHROME_BROWSER_SYNC_GLUE_CHROME_SYNC_NOTIFICATION_BRIDGE_H_
#define CHROME_BROWSER_SYNC_GLUE_CHROME_SYNC_NOTIFICATION_BRIDGE_H_
#include "base/compiler_specific.h"
#include "base/memory/ref_counted.h"
#include "base/observer_list_threadsafe.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "sync/internal_api/public/base/model_type.h"
class Profile;
namespace syncer {
class SyncNotifierObserver;
} // namespace
namespace browser_sync {
// A thread-safe bridge for chrome events that can trigger sync notifications.
// Listens to NOTIFICATION_SYNC_REFRESH_LOCAL and
// NOTIFICATION_SYNC_REFRESH_REMOTE and triggers each observer's
// OnIncomingNotification method on these notifications.
// Note: Notifications are expected to arrive on the UI thread, but observers
// may live on any thread.
class ChromeSyncNotificationBridge : public content::NotificationObserver {
public:
explicit ChromeSyncNotificationBridge(const Profile* profile);
virtual ~ChromeSyncNotificationBridge();
// Must be called on UI thread.
void UpdateEnabledTypes(const syncer::ModelTypeSet enabled_types);
// These can be called on any thread.
virtual void AddObserver(syncer::SyncNotifierObserver* observer);
virtual void RemoveObserver(syncer::SyncNotifierObserver* observer);
// NotificationObserver implementation. Called on UI thread.
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
private:
content::NotificationRegistrar registrar_;
syncer::ModelTypeSet enabled_types_;
// Because [Add/Remove]Observer can be called from any thread, we need a
// thread-safe observerlist.
scoped_refptr<ObserverListThreadSafe<syncer::SyncNotifierObserver> >
observers_;
};
} // namespace browser_sync
#endif // CHROME_BROWSER_SYNC_GLUE_CHROME_SYNC_NOTIFICATION_BRIDGE_H_
|