Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors. All rights reserved. |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 5 | #ifndef CHROME_BROWSER_EXTENSIONS_API_SYSTEM_DISPLAY_DISPLAY_INFO_PROVIDER_H_ |
| 6 | #define CHROME_BROWSER_EXTENSIONS_API_SYSTEM_DISPLAY_DISPLAY_INFO_PROVIDER_H_ |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 7 | |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 8 | #include <string> |
| 9 | |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 10 | #include "base/lazy_instance.h" |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 11 | #include "chrome/browser/extensions/api/system_info/system_info_provider.h" |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 12 | #include "chrome/common/extensions/api/system_display.h" |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 13 | |
| 14 | namespace extensions { |
| 15 | |
| 16 | typedef std::vector<linked_ptr< |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 17 | api::system_display::DisplayUnitInfo> > DisplayInfo; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 18 | |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 19 | class DisplayInfoProvider : public SystemInfoProvider { |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 20 | public: |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 21 | typedef base::Callback<void(bool success)> |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 22 | RequestInfoCallback; |
| 23 | typedef base::Callback<void(bool success, const std::string& error)> |
| 24 | SetInfoCallback; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 25 | |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 26 | // Gets a DisplayInfoProvider instance. |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 27 | static DisplayInfoProvider* Get(); |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 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, |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 43 | const api::system_display::DisplayProperties& info, |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 44 | const SetInfoCallback& callback); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 45 | |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 46 | const DisplayInfo& display_info() const; |
| 47 | |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 48 | static void InitializeForTesting(scoped_refptr<DisplayInfoProvider> provider); |
| 49 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 50 | protected: |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 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. |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 65 | // The implementation is platform specific. |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 66 | virtual bool QueryInfo() OVERRIDE; |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 67 | |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 68 | static base::LazyInstance<scoped_refptr<DisplayInfoProvider> > provider_; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 69 | |
| 70 | DISALLOW_COPY_AND_ASSIGN(DisplayInfoProvider); |
| 71 | }; |
| 72 | |
| 73 | } // namespace extensions |
| 74 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 75 | #endif // CHROME_BROWSER_EXTENSIONS_API_SYSTEM_DISPLAY_DISPLAY_INFO_PROVIDER_H_ |