• Bing Xue's avatar
    Connect to NameOwnerChanged signal when setting callback · 55502d8b
    Bing Xue authored
    In ObjectManager, when ConnectToNameOwnerChangedSignal is called the first time,
    we could have already missed the NameOwnerChanged signal if we get a value from
    UpdateNameOwnerAndBlock. This means NameOwnerChanged callbacks will
    never be called until that service restarts. In ObjectManager we run
    into this problem:
    
    1. ObjectManager::SetupMatchRuleAndFilter is called, calling
    bus_->GetServiceOwnerAndBlock shows empty service name owner.
    
    2. ObjectManager::OnSetupManagerRuleAndFilterComplete callback will call
    object_proxy_->ConnectToSignal, which in turn calls
    ConnectToNameOwnerChangedSignal the first time. At this point,
    UpdateNameOwnerAndBlock calling bus_->GetServiceOwnerAndBlock returns the
    current name owner of the service, this means the NameOwnerChanged signal
    is already sent on system bus.
    
    3. As a result, ObjectManager::NameOwnerChanged is never called while
    the service is already online. This in turn causes GetManagedObject to
    never be called, and the object manager interface never added.
    
    See detailed sample logs in b/138416411.
    
    This CL adds the following:
    
    1. Make SetNameOwnerChangedCallback run
    ConnectToNameOwnerChangedSignal when called. Since ObjectManager calls
    SetNameOwnerChangedCallback before posting SetupMatchRuleAndFilter (in which
    ObjectManager attempts to get the service name owner through a blocking call),
    this removes the time gap described above that causes lost signal.
    
    2. Make dbus thread the only writer to |service_name_owner_|, given that
    connecting to the NameOwnerChanged signal right away in ObjectManager
    ctor causes potential data race in writing to |service_name_owner_| in
    both NameOwnerChanged (on origin thread) and SetupMatchRuleAndFilter (on
    dbus thread).
    
    BUG=b:138416411
    TEST=Manually on device.
    
    
    Change-Id: Ie95a5b7b303637acadebda151cc478e52b6a1af5
    Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1733111
    Commit-Queue: Bing Xue <bingxue@google.com>
    Auto-Submit: Bing Xue <bingxue@google.com>
    Reviewed-by: default avatarRyo Hashimoto <hashimoto@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#684392}
    55502d8b
object_manager.h 15.9 KB