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

Issue 2953483002: [GRC] Coordination Unit Graph Observer V3 (Closed)

Created:
3 years, 6 months ago by matthalp
Modified:
3 years, 6 months ago
CC:
chromium-reviews, ducbui, fmeawad, nduca, shaseley
Target Ref:
refs/heads/master
Project:
chromium
Visibility:
Public.

Description

[GRC] Coordination Unit Graph Observer V3* This is a temporary landing place for: https://codereview.chromium.org/2942403002 R=*oysteine@chromium.org,*lpy@chromium.org,zhenw@chromium.org BUG=724306

Patch Set 1 #

Patch Set 2 : Address review feedback #

Total comments: 7

Messages

Total messages: 13 (7 generated)
matthalp
3 years, 6 months ago (2017-06-20 19:03:30 UTC) #8
lpy
awesome! Thanks for cleaning it up! Overall it l-g to me, just a nit and ...
3 years, 6 months ago (2017-06-20 19:53:46 UTC) #9
oystein (OOO til 10th of July)
lg2m with minors https://codereview.chromium.org/2953483002/diff/20001/services/resource_coordinator/coordination_unit/coordination_unit_graph_observer_unittest.cc File services/resource_coordinator/coordination_unit/coordination_unit_graph_observer_unittest.cc (right): https://codereview.chromium.org/2953483002/diff/20001/services/resource_coordinator/coordination_unit/coordination_unit_graph_observer_unittest.cc#newcode108 services/resource_coordinator/coordination_unit/coordination_unit_graph_observer_unittest.cc:108: EXPECT_EQ(0u, coordination_unit_manager().observers().size()); nit: EXPECT_TRUE(.empty()); https://codereview.chromium.org/2953483002/diff/20001/services/resource_coordinator/coordination_unit/coordination_unit_manager.cc File ...
3 years, 6 months ago (2017-06-20 20:21:07 UTC) #10
lpy
> Minor API nit: As discussed in the meeting, I think it's slightly cleaner to ...
3 years, 6 months ago (2017-06-20 20:47:25 UTC) #11
matthalp
I have addressed lpy and oysteine's feedback. However, I have pushed the code back to ...
3 years, 6 months ago (2017-06-20 20:56:09 UTC) #12
oystein (OOO til 10th of July)
3 years, 6 months ago (2017-06-20 21:06:36 UTC) #13
On 2017/06/20 at 20:47:25, lpy wrote:
> > Minor API nit: As discussed in the meeting, I think it's slightly cleaner to
> > separate the event callbacks from the "should I observe X" virtual which
always
> > gets called.
> > 
> > so:
> > virtual bool ShouldObserve(cu) = 0;
> > virtual void OnCoordinationUnitCreated(cu) {};
> 
> It's not clear to me it's cleaner. Will ShouldObserve(cu) be called by
CUManager? If yes we will end up with code like:
> 
> CUManager::OnCoordinationUnitCreated(cu) {
>   for (auto& observer : observers_) {
>     if (observer->ShouldObserve(cu)) {
>       observer->OnCoordinationUnitCreated(cu);
>     }
>   }
> }
> 
> CUManager::OnCoordinationUnitWillBeDestroyed(cu) {
>   for (auto& observer : observers_) {
>     if (observer->ShouldObserve(cu)) {
>       observer->OnCoordinationUnitWillBeDestroyed(cu);
>     }
>   }
> }
> 
> Do I understand correctly?

Not quite:
CUManager::AddObserversToCoordinationUnit(cu) {
   for (auto& observer : observers_) {
      if (observer->ShouldObserve(cu))
         cu->AddObserver(observer);
   }

   cu->OnCoordinationUnitCreated();
}

CoordinationUnitImpl::OnCoordinationUnitCreated() {
  for (auto& observer : observers_) {
    observer.OnCoordinationUnitCreated(this);
  }
}

CoordinationUnitImpl::~CoordinationUnitImpl() {
  // This could be done on an OnCoordinationUnitDestroyed step prior to
destruction if we want to avoid destructor ordering issues.
  for (auto& observer : observers_) {
    observer.OnCoordinationUnitWillBeDestroyed(this);
  }
}


The benefit is that the observers are already all set up when
OnCoordinationUnitCreated() is called, so it separates construction from events.

Not a big deal either way though, it just also feels like a slightly more easily
readable API for observer implementors rather than:
// The observer needs to implement this to register itself as an observer with
the CU to receive any further events.
virtual void AddObserversToCoordinationUnit() = 0;

Powered by Google App Engine
This is Rietveld 408576698