tree: ed1328eae6687fdfe55dbebec92a8a9d856ad9a4 [path history] [tgz]
  1. android/
  2. BUILD.gn
  3. channels_states.cc
  4. channels_states.h
  5. DEPS
  6. fake_invalidation_handler.cc
  7. fake_invalidation_handler.h
  8. fake_invalidation_service.cc
  9. fake_invalidation_service.h
  10. fcm_invalidation_listener.cc
  11. fcm_invalidation_listener.h
  12. fcm_invalidation_listener_unittest.cc
  13. fcm_invalidation_service.cc
  14. fcm_invalidation_service.h
  15. fcm_invalidation_service_base.cc
  16. fcm_invalidation_service_base.h
  17. fcm_invalidation_service_unittest.cc
  18. fcm_network_handler.cc
  19. fcm_network_handler.h
  20. fcm_network_handler_unittests.cc
  21. fcm_sync_network_channel.cc
  22. fcm_sync_network_channel.h
  23. invalidation_logger.cc
  24. invalidation_logger.h
  25. invalidation_logger_observer.h
  26. invalidation_logger_unittest.cc
  27. invalidation_prefs.cc
  28. invalidation_prefs.h
  29. invalidation_service_test_template.cc
  30. invalidation_service_test_template.h
  31. invalidation_service_util.cc
  32. invalidation_service_util.h
  33. invalidation_switches.cc
  34. invalidation_switches.h
  35. invalidation_test_util.cc
  36. invalidation_test_util.h
  37. invalidator.cc
  38. invalidator_registrar_with_memory.cc
  39. invalidator_registrar_with_memory.h
  40. invalidator_registrar_with_memory_unittest.cc
  41. mock_ack_handler.cc
  42. mock_ack_handler.h
  43. per_user_topic_subscription_manager.cc
  44. per_user_topic_subscription_manager.h
  45. per_user_topic_subscription_manager_unittest.cc
  46. per_user_topic_subscription_request.cc
  47. per_user_topic_subscription_request.h
  48. per_user_topic_subscription_request_unittest.cc
  49. profile_identity_provider.cc
  50. profile_identity_provider.h
  51. profile_invalidation_provider.cc
  52. profile_invalidation_provider.h
  53. README.md
  54. single_object_invalidation_set_unittest.cc
  55. status.cc
  56. status.h
  57. topic_invalidation_map_test_util.cc
  58. topic_invalidation_map_test_util.h
  59. topic_invalidation_map_unittest.cc
  60. unacked_invalidation_set.cc
  61. unacked_invalidation_set.h
  62. unacked_invalidation_set_unittest.cc
components/invalidation/impl/README.md

Invalidations Component

Introduction

Let‘s start with an example. On Chrome OS there exists a concept called “policy” - one can think of them as dynamic flags that change Chrome’s behaviour. They are changed on the Admin Panel from where they get propagated to Chrome OS devices. There is a scheduled “poll job” that fetches those policies every N hours, but preferably we would like to have the latest policy in matter of minutes/seconds. We could shorten the polling interval to 1 minute, but that would put a very high unnecessary load on the servers. To solve this problem we introduce a concept called “invalidation” where the server notifies the devices when their policy changes and then they fetch the new policy - note that this way the devices only fetch the policy when needed.

Invalidation Service - the word comes from cache invalidation. Imagine you have a database which has some objects in it. Cache is just a quick access copy of those objects. When an object changes in the database so should the copy of that object in cache.

If we consider the client device as a cache then whenever some object changes in the server, so should the copy of this object in the client device. All the invalidation related interaction between client device and server is done through Invalidation Service.

An Invalidation (a message to invalidate some object) is sent and received using a publish/subscribe service. In practice, this is Firebase Cloud Messaging (FCM, see firebase.google.com/docs/cloud-messaging or go/fcm) and Fandango (see go/fandango).

In general the whole thing looks as follows: Invalidations component UML


Terminology

  • InstanceID: An identifier for “a specific app installed on a specific device”. The term comes from GMSCore on Android. Here, an “app” is a client of invalidations, such as Sync, Drive, or Policy. It's just a mostly random string of 8 bytes, created by Chrome.
  • Registration: As in “registering with FCM”; means making an InstanceID known to the FCM server. The result of registering is an InstanceID token (note that this is different from an InstanceID).
  • Topic: A “namespace” or “channel” of messages that clients can subscribe to. For Sync, they correspond to data types. A topic can be either private (i.e. GAIA-keyed) or public. For private topics, a unique ID derived from the user's GAIA ID is appended to the topic name to make it unique (though this is an implementation detail which is hidden from clients).
  • Subscription: As in “subscribing to a topic”, i.e. telling the server that this client (identified by InstanceID token) is interested in a given topic.
  • ProjectID (aka SenderID): An ID from the Google Cloud Platform console that identifies a client of invalidations (such as Sync, Drive, or Policy). E.g. for Sync its value is kInvalidationGCMSenderId. Note that (as opposed to InstanceID) this is constant across all users and Chrome instances.

Classes

InvalidationHandler

An InvalidationHandler is a client (receiver) of Invalidations. Every feature that wants to receive Invalidations needs to implement an InvalidationHandler and register it with InvalidationService (see below). InvalidationHandler has the following methods (the list is not exhaustive):

  • OnIncomingInvalidation is called from InvalidationService to notify about incoming Invalidation messages.
  • GetOwnerName must return a unique name for this InvalidationHandler.

InvalidationService

InvalidationService is the main entry point for clients of the Invalidations system. This is where an InvalidationHandler registers/unregisters itself, and where it registers the Topics it is interested in. When a message arrives, InvalidationService calls OnIncomingInvalidation for the receiving InvalidationHandler.

InvalidationService provides the following methods (the list is not exhaustive):

  • RegisterInvalidationHandler allows an InvalidationHandler to register itself as a observer for Invalidations. InvalidationService will only dispatch messages to registered handlers.
  • UpdateInterestedTopics allows InvalidationHandler to change the set of Topics it is interested in.
  • UnregisterInvalidationHandler lets an InvalidationHandler unregister itself again, after which it stops receiving Invalidations.

An InvalidationService instance is usually tied to a profile (via ProfileInvalidationProviderFactory), but on ChromeOS there is also a device-scoped instance, managed by AffiliatedInvalidationServiceProvider (used for device policies, which must apply even before any user is signed in).


FCMInvalidationService

FCMInvalidationService is the only real (non-test) implementation of InvalidationService, using FCM+Fandango as its publish/subscribe service. It delegates most of the work to InvalidatorRegistrarWithMemory and FCMInvalidationListener.


InvalidatorRegistrarWithMemory

InvalidatorRegistrarWithMemory maintains the mapping between Topics and InvalidationHandlers. When a message arrives via FCMInvalidationListener, InvalidatorRegistrarWithMemory dispatches that message (invalidation) to the appropriate InvalidationHandler.

InvalidatorRegistrarWithMemory also persists the set of Topics per handler, to avoid redundant re-subscriptions after every Chrome restart.


FCMInvalidationListener

FCMInvalidationListener gets the list of interesting Topics from FCMInvalidationService. It passes the Topics to PerUserTopicSubscriptionManager (see below) for subscription/unsubscription, receives Invalidation messages from FCMNetworkHandler, and passes Invalidations for the interesting Topics back to FCMInvalidationService.


PerUserTopicSubscriptionManager

PerUserTopicSubscriptionManager manages subscriptions to Topics, sending subscription or unsubscriptions requests to the server as necessary. It persists the set of subscribed Topics in prefs to avoid redundant re-subscriptions after Chrome restarts.


FCMNetworkHandler

FCMNetworkHandler is responsible for communication via GCM channel. It provides the following functionality:

  • Retrieves the InstanceID token required for the subscription. When this token is received, it is passed to PerUserTopicSubscriptionManager which subscribes to Topics with the given token.
  • Receives messages from GCM driver and passes them up to FCMInvalidationListener, where they are converted to Invalidations.