blob: ac9c654e88e776236a6b0ff19d113eb4739f9af5 [file] [log] [blame]
Ben Murdochca12bfa2013-07-23 11:17:05 +01001// Copyright 2013 The Chromium Authors. All rights reserved.
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +00002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Ben Murdochca12bfa2013-07-23 11:17:05 +01005#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)2a99a7e2013-03-28 15:31:22 +00007
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +01008#include <string>
9
Ben Murdochbb1529c2013-08-08 10:24:53 +010010#include "base/lazy_instance.h"
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000011#include "chrome/browser/extensions/api/system_info/system_info_provider.h"
Ben Murdochca12bfa2013-07-23 11:17:05 +010012#include "chrome/common/extensions/api/system_display.h"
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000013
14namespace extensions {
15
16typedef std::vector<linked_ptr<
Ben Murdochca12bfa2013-07-23 11:17:05 +010017 api::system_display::DisplayUnitInfo> > DisplayInfo;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000018
Ben Murdochbb1529c2013-08-08 10:24:53 +010019class DisplayInfoProvider : public SystemInfoProvider {
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000020 public:
Ben Murdoch7dbb3d52013-07-17 14:55:54 +010021 typedef base::Callback<void(bool success)>
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +010022 RequestInfoCallback;
23 typedef base::Callback<void(bool success, const std::string& error)>
24 SetInfoCallback;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000025
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +010026 // Gets a DisplayInfoProvider instance.
Ben Murdochbb1529c2013-08-08 10:24:53 +010027 static DisplayInfoProvider* Get();
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +010028
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 Murdochca12bfa2013-07-23 11:17:05 +010043 const api::system_display::DisplayProperties& info,
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +010044 const SetInfoCallback& callback);
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000045
Ben Murdoch7dbb3d52013-07-17 14:55:54 +010046 const DisplayInfo& display_info() const;
47
Ben Murdochbb1529c2013-08-08 10:24:53 +010048 static void InitializeForTesting(scoped_refptr<DisplayInfoProvider> provider);
49
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000050 protected:
Ben Murdochbb1529c2013-08-08 10:24:53 +010051 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)7d4cd472013-06-19 11:58:07 +010065 // The implementation is platform specific.
Ben Murdoch7dbb3d52013-07-17 14:55:54 +010066 virtual bool QueryInfo() OVERRIDE;
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +010067
Ben Murdochbb1529c2013-08-08 10:24:53 +010068 static base::LazyInstance<scoped_refptr<DisplayInfoProvider> > provider_;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000069
70 DISALLOW_COPY_AND_ASSIGN(DisplayInfoProvider);
71};
72
73} // namespace extensions
74
Ben Murdochca12bfa2013-07-23 11:17:05 +010075#endif // CHROME_BROWSER_EXTENSIONS_API_SYSTEM_DISPLAY_DISPLAY_INFO_PROVIDER_H_