monitor_finder_mac.h revision a1401311d1ab56c4ed0a474bd38c108f75cb0cd9
1// Copyright 2014 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#ifndef CHROME_BROWSER_RENDERER_HOST_PEPPER_MONITOR_FINDER_MAC_H_ 6#define CHROME_BROWSER_RENDERER_HOST_PEPPER_MONITOR_FINDER_MAC_H_ 7 8#include <ApplicationServices/ApplicationServices.h> 9 10#include "base/memory/ref_counted.h" 11#include "base/synchronization/lock.h" 12 13namespace chrome { 14 15// MonitorFinder maps a RenderFrameHost to the display ID on which the widget 16// is painting. This class operates on the IO thread while the RenderFrameHost 17// is on the UI thread, so the value returned by GetMonitor() may be 0 until 18// the information can be retrieved asynchronously. 19class MonitorFinder : public base::RefCountedThreadSafe<MonitorFinder> { 20 public: 21 MonitorFinder(int process_id, int render_frame_id); 22 23 // Gets the native display ID for the <process_id, render_frame_id> tuple. 24 int64_t GetMonitor(); 25 26 // Checks if the given |monitor_id| represents a built-in display. 27 static bool IsMonitorBuiltIn(int64_t monitor_id); 28 29 private: 30 friend class base::RefCountedThreadSafe<MonitorFinder>; 31 ~MonitorFinder(); 32 33 // Method run on the UI thread to get the display information. 34 void FetchMonitorFromWidget(); 35 36 const int process_id_; 37 const int render_frame_id_; 38 39 base::Lock mutex_; // Protects the two members below. 40 // Whether one request to FetchMonitorFromWidget() has been made already. 41 bool request_sent_; 42 // The native display ID for the RenderFrameHost. 43 CGDirectDisplayID display_id_; 44 45 DISALLOW_COPY_AND_ASSIGN(MonitorFinder); 46}; 47 48} // namespace chrome 49 50#endif // CHROME_BROWSER_RENDERER_HOST_PEPPER_MONITOR_FINDER_H_ 51