 +      finalize = display_stream_wrappers_.empty();
 +    }
 +    if (finalize) {
-       delete this;
++      delete this;
 +    }
    }
  

+  DisplayStreamManager() : rw_lock_(RWLockWrapper::CreateRWLock()) {}
+  RWLockWrapper* GetLock() {return rw_lock_.get();};
 
-    if (ready_for_self_destruction_ && display_stream_wrappers_.empty())
+  int GetUniqueId() {
+    WriteLockScoped scoped_display_stream_manager_lock(*rw_lock_);
+    return ++unique_id_generator_;

 
  private:
   struct DisplayStreamWrapper {
@@ -81,6 +107,7 @@ class DisplayStreamManager {
   std::map<int, DisplayStreamWrapper> display_stream_wrappers_;
   int unique_id_generator_ = 0;
   bool ready_for_self_destruction_ = false;
+  std::unique_ptr<RWLockWrapper> rw_lock_;
 };
 
 namespace {
@@ -507,8 +534,6 @@ bool ScreenCapturerMac::RegisterRefreshAndMoveHandlers() {
         return;
       }
 
-      if (manager->ShouldIgnoreUpdates()) return;
-
       // Only pay attention to frame updates.
       if (status != kCGDisplayStreamFrameStatusFrameComplete) return;
 
@@ -518,7 +543,12 @@ bool ScreenCapturerMac::RegisterRefreshAndMoveHandlers() {
       if (count != 0) {
         // According to CGDisplayStream.h, it's safe to call
         // CGDisplayStreamStop() from within the callback.
-        ScreenRefresh(count, rects, display_origin);
+        manager->GetLock()->AcquireLockShared();
+        bool screen_capturer_mac_invalidated = manager->ShouldIgnoreUpdates();
+        if (!screen_capturer_mac_invalidated) {
+          ScreenRefresh(count, rects, display_origin);
+        }
+        manager->GetLock()->ReleaseLockShared();
       }
     };
 
