Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(503)

Issue 670623002: Change base::TickClock to a ref counted class. (Closed)

Created:
6 years, 2 months ago by rkc
Modified:
6 years, 2 months ago
CC:
chromium-reviews, sadrul, nkostylev+watch_chromium.org, hguihot+watch_chromium.org, stevenjb+watch_chromium.org, miu+watch_chromium.org, extensions-reviews_chromium.org, imcheng+watch_chromium.org, jam, posciak+watch_chromium.org, darin-cc_chromium.org, kalyank, erikwright+watch_chromium.org, hubbe+watch_chromium.org, mikhal+watch_chromium.org, tdresser+watch_chromium.org, jasonroberts+watch_google.com, feature-media-reviews_chromium.org, oshima+watch_chromium.org, chromium-apps-reviews_chromium.org, hclam+watch_chromium.org, avayvod+watch_chromium.org, mcasas+watch_chromium.org, pwestin+watch_google.com, ben+ash_chromium.org, mkwst+moarreviews-renderer_chromium.org, wjia+watch_chromium.org, davemoore+watch_chromium.org
Base URL:
https://chromium.googlesource.com/chromium/src.git@audio_redesign
Project:
chromium
Visibility:
Public.

Description

Change base::TickClock to a ref counted class. Typically when testing a class which uses the current clock, we replace calls to base::Time::Now() with our own TickClock. This allows us to test various situations by controlling the time that is visible to our code. The usual way to do this is by keeping a scoped_ptr to a TickClock and set it to the default tick clock on construction of our object. When we replace the clock for testing our previous clock gets freed and the new clock takes its place. This clock is freed when our object finally dies. This model already has the issue with losing the pointer to our clock since we lose ownership to the class we give it to; but this is mitigated in the code by holding on to a pointer of the scoper that we pass to the set_clock_for_testing method and call Advance on that pointer. This problem becomes much worse when you have several objects that use the current time, that need to function synchronously with each other. There are a few bad options to go with here, a.) Create one Clock, pass it to all the objects, and somehow put in a hack telling the objects that they aren't supposed to delete this clock. Otherwise, all the objects will try to delete the clock and cause a crash or none of them will delete it, causing a leak. Managing who should free the clock can get very tricky and error prone when several different objects get involved. b.) Use several clocks, and move them all in tadem. This can get really tricky if you have objects that own other objects that need to share a clock (as is required in my case). Now you need to set the clock for the parent object, then reach into the object and pull out the instance of the child and give that child another clock. Even though refpointers are avoided like the plague in Chrome, this seems to be a very valid use case for them. This is an object that needs to be shared among one more more objects who may or may not have any lifetime relationships with each other. The natural thought is the performance implication of using refptrs instead of raw/scoped ptrs. To start with, most implementations of this were already using scopers, so the performance difference there isn't super huge. Second and more importantly, the performance sensitive aspect of a clock is when we get the current time/ticks. This with a refptr is exactly the same as a scoper and in release builds, possibly identical to raw pointers too. The overhead added is during the construction, deletion and passing around - most of the last will be done in tests, hence any performance impact of this change will be negligible to none. Sorry for the long essay, but I presume that people would have strong opionions on this, so just putting down why I think this needs to be done preemptively :) Since this is not a mechanical change, I do need owners to see if I have changed their code over correctly. Most of this was changing scoped_ptrs to scoped_refptrs but not all. There were some changes that were fairly involved and should be reviewed in depth. OWNERs reviews requested, mark: base/test/simple_test_tick_clock.h base/time/default_tick_clock.h base/time/tick_clock.h dalecurtis: chrome/browser/media/cast_transport_host_filter.cc chrome/browser/media/cast_transport_host_filter.h chrome/renderer/media/cast_session_delegate.cc content/browser/media/audio_stream_monitor.cc content/browser/media/audio_stream_monitor.h content/browser/media/audio_stream_monitor_unittest.cc content/renderer/media/render_media_log.cc content/renderer/media/render_media_log.h media/base/wall_clock_time_source.cc media/base/wall_clock_time_source.h media/cast/cast_environment.cc media/cast/cast_environment.h media/cast/test/skewed_tick_clock.h media/filters/pipeline_integration_test_base.h media/filters/video_frame_scheduler_impl.cc media/filters/video_frame_scheduler_impl.h wez: extensions/browser/api/cast_channel/cast_channel_api.cc extensions/browser/api/cast_channel/logger.cc extensions/browser/api/cast_channel/logger.h zea: components/network_time/network_time_tracker.cc components/network_time/network_time_tracker.h components/network_time/network_time_tracker_unittest.cc xiyuan: chrome/browser/chromeos/system/automatic_reboot_manager.cc chrome/browser/chromeos/system/automatic_reboot_manager.h chrome/browser/chromeos/system/automatic_reboot_manager_unittest.cc jhawkins: chrome/browser/browser_process_impl.cc chrome/browser/browser_process_platform_part_chromeos.cc jennyz: ash/system/chromeos/session/logout_confirmation_controller.cc ash/system/chromeos/session/logout_confirmation_controller.h ash/system/chromeos/session/logout_confirmation_controller_unittest.cc flackr: ash/wm/maximize_mode/maximize_mode_controller.cc ash/wm/maximize_mode/maximize_mode_controller.h derat: ui/display/chromeos/x11/native_display_event_dispatcher_x11.cc ui/display/chromeos/x11/native_display_event_dispatcher_x11.h sadrul: ui/events/test/event_generator.cc ui/events/test/event_generator.h R=dalecurtis@chromium.org, derat@chromium.org, flackr@chromium.org, jennyz@chromium.org, jhawkins@chromium.org, mark@chromium.org, sadrul@chromium.org, wez@chromium.org, xiyuan@chromium.org, zea@chromium.org BUG=None.

Patch Set 1 #

Total comments: 2

Patch Set 2 : #

Total comments: 2

Patch Set 3 : y #

Unified diffs Side-by-side diffs Delta from patch set Stats (+206 lines, -92 lines) Patch
M ash/system/chromeos/session/logout_confirmation_controller.h View 1 2 chunks +2 lines, -2 lines 0 comments Download
M ash/system/chromeos/session/logout_confirmation_controller.cc View 1 1 chunk +2 lines, -2 lines 0 comments Download
M ash/system/chromeos/session/logout_confirmation_controller_unittest.cc View 1 chunk +2 lines, -2 lines 0 comments Download
M ash/wm/maximize_mode/maximize_mode_controller.h View 1 2 chunks +2 lines, -2 lines 0 comments Download
M ash/wm/maximize_mode/maximize_mode_controller.cc View 1 1 chunk +3 lines, -3 lines 0 comments Download
M base/test/simple_test_tick_clock.h View 2 chunks +2 lines, -1 line 0 comments Download
M base/time/default_tick_clock.h View 1 chunk +3 lines, -2 lines 0 comments Download
M base/time/tick_clock.h View 2 chunks +6 lines, -3 lines 0 comments Download
M chrome/browser/browser_process_impl.cc View 1 chunk +1 line, -1 line 0 comments Download
M chrome/browser/browser_process_platform_part_chromeos.cc View 1 chunk +1 line, -1 line 0 comments Download
M chrome/browser/chromeos/system/automatic_reboot_manager.h View 1 2 chunks +2 lines, -2 lines 0 comments Download
M chrome/browser/chromeos/system/automatic_reboot_manager.cc View 1 1 chunk +2 lines, -2 lines 0 comments Download
M chrome/browser/chromeos/system/automatic_reboot_manager_unittest.cc View 1 chunk +2 lines, -1 line 0 comments Download
M chrome/browser/media/cast_transport_host_filter.h View 2 chunks +5 lines, -2 lines 0 comments Download
M chrome/browser/media/cast_transport_host_filter.cc View 3 chunks +5 lines, -2 lines 0 comments Download
M chrome/renderer/media/cast_session_delegate.cc View 1 chunk +1 line, -1 line 0 comments Download
M components/copresence/handlers/audio/audio_directive_handler.h View 2 chunks +4 lines, -1 line 0 comments Download
M components/copresence/handlers/audio/audio_directive_handler.cc View 1 chunk +15 lines, -1 line 0 comments Download
M components/copresence/handlers/audio/audio_directive_handler_unittest.cc View 2 chunks +63 lines, -1 line 0 comments Download
M components/copresence/handlers/audio/audio_directive_list.h View 3 chunks +4 lines, -1 line 0 comments Download
M components/copresence/handlers/audio/audio_directive_list.cc View 1 chunk +7 lines, -0 lines 0 comments Download
M components/copresence/timed_map.h View 2 chunks +3 lines, -3 lines 0 comments Download
M components/copresence/timed_map_unittest.cc View 1 chunk +3 lines, -3 lines 0 comments Download
M components/network_time/network_time_tracker.h View 3 chunks +3 lines, -3 lines 0 comments Download
M components/network_time/network_time_tracker.cc View 1 chunk +4 lines, -3 lines 0 comments Download
M components/network_time/network_time_tracker_unittest.cc View 2 chunks +3 lines, -2 lines 0 comments Download
M content/browser/media/audio_stream_monitor.h View 1 2 chunks +7 lines, -4 lines 0 comments Download
M content/browser/media/audio_stream_monitor.cc View 1 chunk +1 line, -1 line 0 comments Download
M content/browser/media/audio_stream_monitor_unittest.cc View 3 chunks +7 lines, -6 lines 0 comments Download
M content/renderer/media/render_media_log.h View 1 1 chunk +2 lines, -2 lines 0 comments Download
M content/renderer/media/render_media_log.cc View 1 1 chunk +2 lines, -2 lines 0 comments Download
M extensions/browser/api/cast_channel/cast_channel_api.cc View 1 chunk +1 line, -1 line 0 comments Download
M extensions/browser/api/cast_channel/logger.h View 1 2 chunks +2 lines, -2 lines 0 comments Download
M extensions/browser/api/cast_channel/logger.cc View 1 1 chunk +3 lines, -3 lines 0 comments Download
M media/base/wall_clock_time_source.h View 1 2 chunks +3 lines, -3 lines 0 comments Download
M media/base/wall_clock_time_source.cc View 1 1 chunk +2 lines, -2 lines 0 comments Download
M media/cast/cast_environment.h View 2 chunks +3 lines, -3 lines 0 comments Download
M media/cast/cast_environment.cc View 1 chunk +4 lines, -3 lines 0 comments Download
M media/cast/test/skewed_tick_clock.h View 1 chunk +2 lines, -0 lines 0 comments Download
M media/filters/pipeline_integration_test_base.h View 1 chunk +3 lines, -1 line 0 comments Download
M media/filters/video_frame_scheduler_impl.h View 1 2 chunks +2 lines, -2 lines 0 comments Download
M media/filters/video_frame_scheduler_impl.cc View 1 1 chunk +2 lines, -2 lines 0 comments Download
M ui/display/chromeos/x11/native_display_event_dispatcher_x11.h View 1 2 chunks +2 lines, -2 lines 0 comments Download
M ui/display/chromeos/x11/native_display_event_dispatcher_x11.cc View 1 2 1 chunk +2 lines, -2 lines 0 comments Download
M ui/events/test/event_generator.h View 1 3 chunks +3 lines, -2 lines 0 comments Download
M ui/events/test/event_generator.cc View 1 1 chunk +3 lines, -2 lines 0 comments Download

Messages

Total messages: 10 (1 generated)
rkc
6 years, 2 months ago (2014-10-21 01:06:46 UTC) #1
Daniel Erat
(i don't have an opinion on the change to base) https://codereview.chromium.org/670623002/diff/1/ui/display/chromeos/x11/native_display_event_dispatcher_x11.cc File ui/display/chromeos/x11/native_display_event_dispatcher_x11.cc (right): https://codereview.chromium.org/670623002/diff/1/ui/display/chromeos/x11/native_display_event_dispatcher_x11.cc#newcode103 ...
6 years, 2 months ago (2014-10-21 16:30:10 UTC) #2
rkc
https://codereview.chromium.org/670623002/diff/1/ui/display/chromeos/x11/native_display_event_dispatcher_x11.cc File ui/display/chromeos/x11/native_display_event_dispatcher_x11.cc (right): https://codereview.chromium.org/670623002/diff/1/ui/display/chromeos/x11/native_display_event_dispatcher_x11.cc#newcode103 ui/display/chromeos/x11/native_display_event_dispatcher_x11.cc:103: tick_clock_.swap(tick_clock); On 2014/10/21 16:30:10, Daniel Erat wrote: > why ...
6 years, 2 months ago (2014-10-21 16:54:42 UTC) #3
Daniel Erat
https://codereview.chromium.org/670623002/diff/20001/ui/display/chromeos/x11/native_display_event_dispatcher_x11.cc File ui/display/chromeos/x11/native_display_event_dispatcher_x11.cc (right): https://codereview.chromium.org/670623002/diff/20001/ui/display/chromeos/x11/native_display_event_dispatcher_x11.cc#newcode103 ui/display/chromeos/x11/native_display_event_dispatcher_x11.cc:103: tick_clock_.swap(tick_clock); thanks, but i think the swap() got missed ...
6 years, 2 months ago (2014-10-21 17:01:28 UTC) #4
miu
Adding myself as media/cast reviewer. Rahul: Have you considered using a proxy instead? Meaning, a ...
6 years, 2 months ago (2014-10-21 17:28:30 UTC) #6
rkc
On 2014/10/21 17:28:30, miu wrote: > Adding myself as media/cast reviewer. > > Rahul: Have ...
6 years, 2 months ago (2014-10-21 18:28:45 UTC) #7
rkc
https://codereview.chromium.org/670623002/diff/20001/ui/display/chromeos/x11/native_display_event_dispatcher_x11.cc File ui/display/chromeos/x11/native_display_event_dispatcher_x11.cc (right): https://codereview.chromium.org/670623002/diff/20001/ui/display/chromeos/x11/native_display_event_dispatcher_x11.cc#newcode103 ui/display/chromeos/x11/native_display_event_dispatcher_x11.cc:103: tick_clock_.swap(tick_clock); On 2014/10/21 17:01:27, Daniel Erat wrote: > thanks, ...
6 years, 2 months ago (2014-10-21 18:29:02 UTC) #8
Mark Mentovai
I think that if you’ve found a way to do this in a more isolated ...
6 years, 2 months ago (2014-10-22 16:30:39 UTC) #9
rkc
6 years, 2 months ago (2014-10-22 20:04:15 UTC) #10
On 2014/10/22 16:30:39, Mark Mentovai wrote:
> I think that if you’ve found a way to do this in a more isolated fashion
> (<crxref style="background-image:
url(chrome-extension://ppnlfijacbhfpjgkafbeiaklmgoljooo/res/type/codereview.png);">https://codereview.chromium.org/665353002/</crxref>),
that’s probably a better way to
> go. We shouldn’t have to impose this on everyone or add to base’s complexity
if
> there’s only one downstream user of the feature.

Makes sense. Closing for now.

Powered by Google App Engine
This is Rietveld 408576698