tree: 20ac89417453b38ab5e2c9644d6e09337e8e3d16 [path history] [tgz]
  1. android/
  2. BUILD.gn
  3. channels_states.cc
  4. channels_states.h
  5. deprecated_invalidator_registrar.cc
  6. deprecated_invalidator_registrar.h
  7. deprecated_invalidator_registrar_unittest.cc
  8. DEPS
  9. fake_invalidation_handler.cc
  10. fake_invalidation_handler.h
  11. fake_invalidation_service.cc
  12. fake_invalidation_service.h
  13. fake_invalidation_state_tracker.cc
  14. fake_invalidation_state_tracker.h
  15. fake_invalidator.cc
  16. fake_invalidator.h
  17. fake_invalidator_unittest.cc
  18. fake_system_resources.cc
  19. fake_system_resources.h
  20. fcm_invalidation_listener.cc
  21. fcm_invalidation_listener.h
  22. fcm_invalidation_listener_unittest.cc
  23. fcm_invalidation_service.cc
  24. fcm_invalidation_service.h
  25. fcm_invalidation_service_base.cc
  26. fcm_invalidation_service_base.h
  27. fcm_invalidation_service_unittest.cc
  28. fcm_network_handler.cc
  29. fcm_network_handler.h
  30. fcm_network_handler_unittests.cc
  31. fcm_sync_network_channel.cc
  32. fcm_sync_network_channel.h
  33. gcm_invalidation_bridge.cc
  34. gcm_invalidation_bridge.h
  35. gcm_invalidation_bridge_unittest.cc
  36. gcm_network_channel.cc
  37. gcm_network_channel.h
  38. gcm_network_channel_delegate.h
  39. gcm_network_channel_unittest.cc
  40. invalidation_listener.h
  41. invalidation_logger.cc
  42. invalidation_logger.h
  43. invalidation_logger_observer.h
  44. invalidation_logger_unittest.cc
  45. invalidation_notifier.cc
  46. invalidation_notifier.h
  47. invalidation_notifier_unittest.cc
  48. invalidation_prefs.cc
  49. invalidation_prefs.h
  50. invalidation_service_android.cc
  51. invalidation_service_android.h
  52. invalidation_service_android_unittest.cc
  53. invalidation_service_test_template.cc
  54. invalidation_service_test_template.h
  55. invalidation_service_util.cc
  56. invalidation_service_util.h
  57. invalidation_state_tracker.cc
  58. invalidation_state_tracker.h
  59. invalidation_switches.cc
  60. invalidation_switches.h
  61. invalidation_test_util.cc
  62. invalidation_test_util.h
  63. invalidator.cc
  64. invalidator.h
  65. invalidator_registrar_with_memory.cc
  66. invalidator_registrar_with_memory.h
  67. invalidator_registrar_with_memory_unittest.cc
  68. invalidator_storage.cc
  69. invalidator_storage.h
  70. invalidator_storage_unittest.cc
  71. invalidator_test_template.cc
  72. invalidator_test_template.h
  73. mock_ack_handler.cc
  74. mock_ack_handler.h
  75. network_channel.h
  76. non_blocking_invalidator.cc
  77. non_blocking_invalidator.h
  78. non_blocking_invalidator_unittest.cc
  79. notifier_reason_util.cc
  80. notifier_reason_util.h
  81. object_id_invalidation_map_test_util.cc
  82. object_id_invalidation_map_test_util.h
  83. object_id_invalidation_map_unittest.cc
  84. per_user_topic_registration_manager.cc
  85. per_user_topic_registration_manager.h
  86. per_user_topic_registration_manager_unittest.cc
  87. per_user_topic_registration_request.cc
  88. per_user_topic_registration_request.h
  89. per_user_topic_registration_request_unittest.cc
  90. profile_identity_provider.cc
  91. profile_identity_provider.h
  92. profile_invalidation_provider.cc
  93. profile_invalidation_provider.h
  94. push_client_channel.cc
  95. push_client_channel.h
  96. push_client_channel_unittest.cc
  97. README.md
  98. registration_manager.cc
  99. registration_manager.h
  100. registration_manager_unittest.cc
  101. single_object_invalidation_set_unittest.cc
  102. state_writer.h
  103. status.cc
  104. status.h
  105. sync_invalidation_listener.cc
  106. sync_invalidation_listener.h
  107. sync_invalidation_listener_unittest.cc
  108. sync_system_resources.cc
  109. sync_system_resources.h
  110. sync_system_resources_unittest.cc
  111. ticl_invalidation_service.cc
  112. ticl_invalidation_service.h
  113. ticl_invalidation_service_unittest.cc
  114. unacked_invalidation_set.cc
  115. unacked_invalidation_set.h
  116. unacked_invalidation_set_test_util.cc
  117. unacked_invalidation_set_test_util.h
  118. 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.

Invalidation (message to invalidate some object) is sent and received using a publish/subscribe service. We have a couple of those publish/subscribe services, some of which are Tango - go/tango and Fandango - go/fandango.

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


InvalidationHandler

InvalidationHandler - is a client of InvalidationService (see below). Everyone who wants to use InvalidationService to receive Invalidation (notification of change in some object) needs to implement InvalidationHandler to receive those messages. InvalidationHandler has the following methods (the list is not full):

  • OnIncomingInvalidation - is called from InvalidationService to notify about incoming Invalidation.

At the end of documentation, one can find the additional material for adding InvalidationHandler.


InvalidationService

Class InvalidationService is just an interface which provides the following methods (the list is not exhaustive).

  • RegisterInvalidationHandler - allows InvalidationHandler to register itself as a observer for Invalidations. InvalidationService will only dispatch messages to registered handlers.

  • UpdateRegisteredInvalidationIds - allows InvalidationHandler to change the ids of Objects it is interested in receiving Invalidations for.

  • UnregisterInvalidationHandler - when InvalidationHandler unregisters it stops receiving Invalidations.


FCMInvalidationService

FCMInvalidationService - is the implementation of InvalidationService that uses Fandango as its publish/subscribe service.

FCMInvalidationService is the main entry point for InvalidationHandler. This is where InvalidationHandler registers/unregisters itself in InvalidationService, and registers Objects to invalidate. When a message comes, FCMInvalidationService calls OnIncomingInvalidation for the receiving InvalidationHandler.

Actually FCMInvalidationService just provides the abstraction above for InvalidationHandler, while in fact it just manages InvalidatorRegistrarWithMemory and FCMInvalidationListener, who do the actual work.


InvalidatorRegistrarWithMemory

InvalidatorRegistrarWithMemory stores registered InvalidationHandlers, stores objects to invalidate and stores mapping between objects and InvalidationHandlers to know which InvalidationHandlers are interested in which objects. When a message comes from FCMInvalidationListener, InvalidatorRegistrarWithMemory dispatches that message (Invalidation) to the receiving InvalidationHandler.


FCMInvalidationListener

FCMInvalidationListener just gets the list of topics to subscribe from FCMInvalidationService, and when FCMInvalidationListener receives Invalidations on those topics, it just passes them up to FCMInvalidationService.

And again the description above is just a good abstraction of FCMInvalidationListener for FCMInvalidationService, while in fact FCMInvalidationListener manages PerUserTopicRegistrationManager and FCMNetworkHandler who do the actual work.


PerUserTopicRegistrationManager

PerUserTopicRegistrationManager manages subscriptions to topics. Topics in this case are objects we are interested in invalidating.


FCMNetworkHandler

FCMNetworkHandler is the class responsible for communication via GCM channel. Provides the following functionality:

  • Retrieves the auth token required for the subscription. When this token is received, it is passed to PerUserTopicRegistrationManager which subscribes to topics with the given auth token.

  • Receives messages from GCM driver and passes them up to FCMInvalidationListener, where they are converted to Invalidations.


TiclInvalidationService (deprecated)

TiclInvalidationService - is the implementation of InvalidationService that uses Tango as its publish/subscribe service.


For those who want to add InvalidationHandler

Public vs. Private topics

FCMInvalidationService has a different registration process for public and private topics. When registering with a public topic, publish/subscribe service will fan out all outgoing messages to all devices subscribed to this topic. For example: If a device subscribes to “DeviceGuestModeEnabled” public topic all instances subscribed to this topic will receive all outgoing messages addressed to topic “DeviceGuestModeEnabled”. But if 2 devices with different InstanceID subscribe to private topic “BOOKMARK”, they will receive different set of messages addressed to pair (“BOOKMARK”, InstanceID) respectively.

Project Id

In the UML diagram above there are 3 classes that inherit from InvalidationHandler:

  • SyncEngineImpl

  • CloudPolicyInvalidator

  • DriveNotificationManager

There is a notion of SenderId which is different for every InvalidationHandler. SenderId is used when registering to topics, to receive a topic of a particular sender. So for example server side logic of CloudPolicy posts messages using SenderId of “1013309121859”, and client side logic which is CloudPolicyInvalidator should register to topics using the SenderId “1013309121859”.

InvalidationService for profile and for device

Usually InvalidationService is bound to a profile which can be spinned up using ProfileInvalidationProviderFactory, but sometimes there is no profile as in the special case of CloudPolicyInvalidator. CloudPolicyInvalidator is interested in receiving Invalidations on policies. Chrome OS team defines 2 types of policies - User and Device. Device policies should be received even when there is no one signed in to a Chrome OS device, thus there is no profile. For this reason there is a special class AffiliatedInvalidationServiceProvider which spawns InvalidationService even when there is no profile.