tree: a9f0ef32e703411019098252b7856ab401c4a74e [path history] [tgz]
  1. android/
  2. keep_alive/
  3. avatar_menu.cc
  4. avatar_menu.h
  5. avatar_menu_browsertest.cc
  6. avatar_menu_desktop.cc
  7. avatar_menu_observer.h
  8. bookmark_model_loaded_observer.cc
  9. bookmark_model_loaded_observer.h
  10. BUILD.gn
  11. chrome_browser_main_extra_parts_profiles.cc
  12. chrome_browser_main_extra_parts_profiles.h
  13. chrome_version_service.cc
  14. chrome_version_service.h
  15. COMMON_METADATA
  16. delete_profile_helper.cc
  17. delete_profile_helper.h
  18. delete_profile_helper_browsertest.cc
  19. DEPS
  20. DIR_METADATA
  21. force_safe_search_policy_handler.cc
  22. force_safe_search_policy_handler.h
  23. force_youtube_safety_mode_policy_handler.cc
  24. force_youtube_safety_mode_policy_handler.h
  25. gaia_info_update_service.cc
  26. gaia_info_update_service.h
  27. gaia_info_update_service_factory.cc
  28. gaia_info_update_service_factory.h
  29. gaia_info_update_service_unittest.cc
  30. guest_mode_policy_handler.cc
  31. guest_mode_policy_handler.h
  32. guest_mode_policy_handler_unittest.cc
  33. guest_profile_creation_logger.cc
  34. guest_profile_creation_logger.h
  35. guest_profile_creation_logger_unittest.cc
  36. host_zoom_map_browsertest.cc
  37. incognito_helpers.cc
  38. incognito_helpers.h
  39. incognito_mode_policy_handler.cc
  40. incognito_mode_policy_handler.h
  41. incognito_mode_policy_handler_unittest.cc
  42. incognito_profile_containment_browsertest.cc
  43. nuke_profile_directory_utils.cc
  44. nuke_profile_directory_utils.h
  45. off_the_record_profile_impl.cc
  46. off_the_record_profile_impl.h
  47. OWNERS
  48. pref_service_builder_utils.cc
  49. pref_service_builder_utils.h
  50. profile.cc
  51. profile.h
  52. profile_activity_metrics_recorder.cc
  53. profile_activity_metrics_recorder.h
  54. profile_activity_metrics_recorder_browsertest.cc
  55. profile_activity_metrics_recorder_unittest.cc
  56. profile_android.cc
  57. profile_android.h
  58. profile_attributes_entry.cc
  59. profile_attributes_entry.h
  60. profile_attributes_init_params.cc
  61. profile_attributes_init_params.h
  62. profile_attributes_storage.cc
  63. profile_attributes_storage.h
  64. profile_attributes_storage_observer.h
  65. profile_attributes_storage_unittest.cc
  66. profile_avatar_downloader.cc
  67. profile_avatar_downloader.h
  68. profile_avatar_icon_util.cc
  69. profile_avatar_icon_util.h
  70. profile_avatar_icon_util_unittest.cc
  71. profile_browsertest.cc
  72. profile_browsertest_android.cc
  73. profile_destroyer.cc
  74. profile_destroyer.h
  75. profile_destroyer_unittest.cc
  76. profile_downloader.cc
  77. profile_downloader.h
  78. profile_downloader_delegate.h
  79. profile_downloader_unittest.cc
  80. profile_impl.cc
  81. profile_impl.h
  82. profile_io_data.cc
  83. profile_io_data.h
  84. profile_key.cc
  85. profile_key.h
  86. profile_key_android.cc
  87. profile_key_android.h
  88. profile_keyed_service_browsertest.cc
  89. profile_keyed_service_factory.cc
  90. profile_keyed_service_factory.h
  91. profile_keyed_service_factory.md
  92. profile_keyed_service_factory_unittest.cc
  93. profile_list_desktop.cc
  94. profile_list_desktop.h
  95. profile_list_desktop_browsertest.cc
  96. profile_list_desktop_unittest.cc
  97. profile_manager.cc
  98. profile_manager.h
  99. profile_manager_android.cc
  100. profile_manager_android.h
  101. profile_manager_browsertest.cc
  102. profile_manager_observer.h
  103. profile_manager_unittest.cc
  104. profile_metrics.cc
  105. profile_metrics.h
  106. profile_observer.h
  107. profile_selections.cc
  108. profile_selections.h
  109. profile_selections_unittest.cc
  110. profile_shortcut_manager.cc
  111. profile_shortcut_manager.h
  112. profile_shortcut_manager_browsertest_win.cc
  113. profile_shortcut_manager_stub.cc
  114. profile_shortcut_manager_unittest_win.cc
  115. profile_shortcut_manager_win.cc
  116. profile_shortcut_manager_win.h
  117. profile_statistics.cc
  118. profile_statistics.h
  119. profile_statistics_aggregator.cc
  120. profile_statistics_aggregator.h
  121. profile_statistics_browsertest.cc
  122. profile_statistics_common.cc
  123. profile_statistics_common.h
  124. profile_statistics_factory.cc
  125. profile_statistics_factory.h
  126. profile_statistics_unittest.cc
  127. profile_test_util.cc
  128. profile_test_util.h
  129. profile_testing_helper.cc
  130. profile_testing_helper.h
  131. profile_window.cc
  132. profile_window.h
  133. profile_window_browsertest.cc
  134. profiles_state.cc
  135. profiles_state.h
  136. profiles_state_unittest.cc
  137. README.md
  138. refcounted_profile_keyed_service_factory.cc
  139. refcounted_profile_keyed_service_factory.h
  140. renderer_updater.cc
  141. renderer_updater.h
  142. renderer_updater_factory.cc
  143. renderer_updater_factory.h
  144. reporting_util.cc
  145. reporting_util.h
  146. sql_init_error_message_ids.cc
  147. sql_init_error_message_ids.h
  148. storage_partition_descriptor.h
chrome/browser/profiles/README.md

Managing lifetime of a Profile

KeyedService::Shutdown

If a KeyedService owns objects that depend on the lifetime of its Profile then it needs to ensure that these objects are destroyed before the Profile is destroyed (e.g. content::WebContents need to be be destroyed before their Profile is destroyed). This can be done by overriding KeyedService::Shutdown - this method will be called before the Profile object is destroyed.

ScopedProfileKeepAlive

Typically, closing the last Browser window associated with a Profile will start tearing down the Profile. This is undesirable if there are content::WebContents associated with that Profile in standalone (i.e. non-Browser) windows that shouldn't go away without an explicit user action to close such a window. In such cases, Profile destruction can be postponed by holding ScopedProfileKeepAlive.

ScopedProfileKeepAlive is a strong reference to a Profile object. It is very similar to ScopedKeepAlive, which is for the browser process.

BrowserContextKeyedServiceShutdownNotifierFactory

If an object is not a KeyedService, but still needs to react to destruction of a specific KeyedService, then it can do so using BrowserContextKeyedServiceShutdownNotifierFactory.

For example, extensions::ExtensionURLLoaderFactory is owned by its remote mojo client (i.e. it is not a KeyedService) but it still wants to avoid processing further chrome-extension:// resource requests after Profile destruction. This is done by registering ExtensionURLLoaderFactory::OnBrowserContextDestroyed to be called when extension-related keyed services get destroyed.

Only when necessary: ProfileObserver::OnProfileWillBeDestroyed

If you really need to directly listen for Profile destruction you can use ProfileObserver::OnProfileWillBeDestroyed, but in general if you need this, it‘s a bad sign, as it means that you’re using a feature that is not properly encapsulated in a keyed service.