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