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 | #include "chrome/browser/extensions/api/system_display/system_display_api.h" |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 6 | |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 7 | #include "base/memory/scoped_ptr.h" |
| 8 | #include "chrome/common/extensions/manifest_handlers/kiosk_enabled_info.h" |
| 9 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 10 | namespace extensions { |
| 11 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 12 | using api::system_display::DisplayUnitInfo; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 13 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 14 | namespace SetDisplayProperties = api::system_display::SetDisplayProperties; |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 15 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 16 | bool SystemDisplayGetInfoFunction::RunImpl() { |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 17 | DisplayInfoProvider::Get()->RequestInfo( |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 18 | base::Bind( |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 19 | &SystemDisplayGetInfoFunction::OnGetDisplayInfoCompleted, |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 20 | this)); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 21 | return true; |
| 22 | } |
| 23 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 24 | void SystemDisplayGetInfoFunction::OnGetDisplayInfoCompleted( |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 25 | bool success) { |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 26 | if (success) { |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 27 | results_ = api::system_display::GetInfo::Results::Create( |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 28 | DisplayInfoProvider::Get()->display_info()); |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 29 | } else { |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 30 | SetError("Error occurred when querying display information."); |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 31 | } |
| 32 | SendResponse(success); |
| 33 | } |
| 34 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 35 | bool SystemDisplaySetDisplayPropertiesFunction::RunImpl() { |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 36 | #if !defined(OS_CHROMEOS) |
| 37 | SetError("Function available only on ChromeOS."); |
| 38 | return false; |
| 39 | #else |
| 40 | if (!KioskEnabledInfo::IsKioskEnabled(GetExtension())) { |
| 41 | SetError("The extension needs to be kiosk enabled to use the function."); |
| 42 | return false; |
| 43 | } |
| 44 | |
| 45 | scoped_ptr<SetDisplayProperties::Params> params( |
| 46 | SetDisplayProperties::Params::Create(*args_)); |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 47 | DisplayInfoProvider::Get()->SetInfo(params->id, params->info, |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 48 | base::Bind( |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 49 | &SystemDisplaySetDisplayPropertiesFunction::OnPropertiesSet, |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 50 | this)); |
| 51 | return true; |
| 52 | #endif |
| 53 | } |
| 54 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 55 | void SystemDisplaySetDisplayPropertiesFunction::OnPropertiesSet( |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 56 | bool success, const std::string& error) { |
| 57 | if (!success) |
| 58 | SetError(error); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 59 | SendResponse(success); |
| 60 | } |
| 61 | |
| 62 | } // namespace extensions |