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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_SYNC_GLUE_ANDROID_INVALIDATOR_BRIDGE_H_
6 #define CHROME_BROWSER_SYNC_GLUE_ANDROID_INVALIDATOR_BRIDGE_H_
8 #include "base/compiler_specific.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/sequenced_task_runner.h"
11 #include "content/public/browser/notification_observer.h"
12 #include "content/public/browser/notification_registrar.h"
13 #include "sync/notifier/invalidator.h"
18 class InvalidationHandler
;
21 namespace browser_sync
{
23 // A bridge that converts Chrome events on the UI thread to sync
24 // notifications on the sync task runner.
26 // Listens to NOTIFICATION_SYNC_REFRESH_REMOTE (on the UI thread) and triggers
27 // each observer's OnIncomingNotification method on these notifications (on the
28 // sync task runner). Android clients receive invalidations through this
29 // mechanism exclusively, hence the name.
30 class AndroidInvalidatorBridge
31 : public content::NotificationObserver
, syncer::Invalidator
{
33 // Must be created and destroyed on the UI thread.
34 AndroidInvalidatorBridge(
35 const Profile
* profile
,
36 const scoped_refptr
<base::SequencedTaskRunner
>& sync_task_runner
);
37 virtual ~AndroidInvalidatorBridge();
39 // Must be called on the UI thread while the sync task runner is still
40 // around. No other member functions on the sync thread may be called after
42 void StopForShutdown();
44 // Invalidator implementation. Must be called on the sync task runner.
45 virtual void RegisterHandler(syncer::InvalidationHandler
* handler
) OVERRIDE
;
46 virtual void UpdateRegisteredIds(syncer::InvalidationHandler
* handler
,
47 const syncer::ObjectIdSet
& ids
) OVERRIDE
;
48 virtual void UnregisterHandler(syncer::InvalidationHandler
* handler
) OVERRIDE
;
49 virtual void Acknowledge(const invalidation::ObjectId
& id
,
50 const syncer::AckHandle
& ack_handle
) OVERRIDE
;
51 virtual syncer::InvalidatorState
GetInvalidatorState() const OVERRIDE
;
53 // The following members of the Invalidator interface are not applicable to
54 // this invalidator and are implemented as no-ops.
55 virtual void UpdateCredentials(
56 const std::string
& email
, const std::string
& token
) OVERRIDE
;
57 virtual void SendInvalidation(
58 const syncer::ObjectIdInvalidationMap
& invalidation_map
) OVERRIDE
;
60 bool IsHandlerRegisteredForTest(
61 syncer::InvalidationHandler
* handler
) const;
62 syncer::ObjectIdSet
GetRegisteredIdsForTest(
63 syncer::InvalidationHandler
* handler
) const;
65 // NotificationObserver implementation. Called on UI thread.
66 virtual void Observe(int type
,
67 const content::NotificationSource
& source
,
68 const content::NotificationDetails
& details
) OVERRIDE
;
71 // Inner class to hold all the bits used on |sync_task_runner_|.
74 const scoped_refptr
<base::SequencedTaskRunner
> sync_task_runner_
;
76 // Created on the UI thread, used only on |sync_task_runner_|.
77 const scoped_refptr
<Core
> core_
;
79 // Used only on the UI thread.
80 content::NotificationRegistrar registrar_
;
83 } // namespace browser_sync
85 #endif // CHROME_BROWSER_SYNC_GLUE_ANDROID_INVALIDATOR_BRIDGE_H_