Home | History | Annotate | Download | only in system_display
      1 // Copyright 2013 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_EXTENSIONS_API_SYSTEM_DISPLAY_DISPLAY_INFO_PROVIDER_H_
      6 #define CHROME_BROWSER_EXTENSIONS_API_SYSTEM_DISPLAY_DISPLAY_INFO_PROVIDER_H_
      7 
      8 #include <string>
      9 
     10 #include "base/lazy_instance.h"
     11 #include "chrome/browser/extensions/api/system_info/system_info_provider.h"
     12 #include "chrome/common/extensions/api/system_display.h"
     13 
     14 namespace extensions {
     15 
     16 typedef std::vector<linked_ptr<
     17     api::system_display::DisplayUnitInfo> > DisplayInfo;
     18 
     19 class DisplayInfoProvider : public SystemInfoProvider {
     20  public:
     21   typedef base::Callback<void(bool success)>
     22       RequestInfoCallback;
     23   typedef base::Callback<void(bool success, const std::string& error)>
     24       SetInfoCallback;
     25 
     26   // Gets a DisplayInfoProvider instance.
     27   static DisplayInfoProvider* Get();
     28 
     29   // Starts request for the display info, redirecting the request to a worker
     30   // thread if needed (using SystemInfoProvider<DisplayInfo>::StartQuery()).
     31   // The callback will be called asynchronously.
     32   // The implementation is platform specific.
     33   void RequestInfo(const RequestInfoCallback& callback);
     34 
     35   // Updates the display parameters for a display with the provided id.
     36   // The parameters are updated according to content of |info|. After the
     37   // display is updated, callback is called with the success status, and error
     38   // message. If the method succeeds, the error message is empty.
     39   // The callback will be called asynchronously.
     40   // This functionality is exposed only on ChromeOS.
     41   virtual void SetInfo(
     42       const std::string& display_id,
     43       const api::system_display::DisplayProperties& info,
     44       const SetInfoCallback& callback);
     45 
     46   const DisplayInfo& display_info() const;
     47 
     48   static void InitializeForTesting(scoped_refptr<DisplayInfoProvider> provider);
     49 
     50  protected:
     51   DisplayInfoProvider();
     52   virtual ~DisplayInfoProvider();
     53 
     54   // The last information filled up by QueryInfo and is accessed on multiple
     55   // threads, but the whole class is being guarded by SystemInfoProvider base
     56   // class.
     57   //
     58   // |info_| is accessed on the UI thread while |is_waiting_for_completion_| is
     59   // false and on the sequenced worker pool while |is_waiting_for_completion_|
     60   // is true.
     61   DisplayInfo info_;
     62 
     63  private:
     64   // Overriden from SystemInfoProvider.
     65   // The implementation is platform specific.
     66   virtual bool QueryInfo() OVERRIDE;
     67 
     68   static base::LazyInstance<scoped_refptr<DisplayInfoProvider> > provider_;
     69 
     70   DISALLOW_COPY_AND_ASSIGN(DisplayInfoProvider);
     71 };
     72 
     73 }  // namespace extensions
     74 
     75 #endif  // CHROME_BROWSER_EXTENSIONS_API_SYSTEM_DISPLAY_DISPLAY_INFO_PROVIDER_H_
     76