blob: 36dd2f26e73fc2a75e368ff3af643be94b34c923 [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#include "chrome/browser/extensions/api/system_display/system_display_api.h"
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +00006
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +01007#include "base/memory/scoped_ptr.h"
8#include "chrome/common/extensions/manifest_handlers/kiosk_enabled_info.h"
9
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000010namespace extensions {
11
Ben Murdochca12bfa2013-07-23 11:17:05 +010012using api::system_display::DisplayUnitInfo;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000013
Ben Murdochca12bfa2013-07-23 11:17:05 +010014namespace SetDisplayProperties = api::system_display::SetDisplayProperties;
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +010015
Ben Murdochca12bfa2013-07-23 11:17:05 +010016bool SystemDisplayGetInfoFunction::RunImpl() {
Ben Murdochbb1529c2013-08-08 10:24:53 +010017 DisplayInfoProvider::Get()->RequestInfo(
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +010018 base::Bind(
Ben Murdochca12bfa2013-07-23 11:17:05 +010019 &SystemDisplayGetInfoFunction::OnGetDisplayInfoCompleted,
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +010020 this));
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000021 return true;
22}
23
Ben Murdochca12bfa2013-07-23 11:17:05 +010024void SystemDisplayGetInfoFunction::OnGetDisplayInfoCompleted(
Ben Murdoch7dbb3d52013-07-17 14:55:54 +010025 bool success) {
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +010026 if (success) {
Ben Murdochca12bfa2013-07-23 11:17:05 +010027 results_ = api::system_display::GetInfo::Results::Create(
Ben Murdochbb1529c2013-08-08 10:24:53 +010028 DisplayInfoProvider::Get()->display_info());
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +010029 } else {
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000030 SetError("Error occurred when querying display information.");
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +010031 }
32 SendResponse(success);
33}
34
Ben Murdochca12bfa2013-07-23 11:17:05 +010035bool SystemDisplaySetDisplayPropertiesFunction::RunImpl() {
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +010036#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 Murdochbb1529c2013-08-08 10:24:53 +010047 DisplayInfoProvider::Get()->SetInfo(params->id, params->info,
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +010048 base::Bind(
Ben Murdochca12bfa2013-07-23 11:17:05 +010049 &SystemDisplaySetDisplayPropertiesFunction::OnPropertiesSet,
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +010050 this));
51 return true;
52#endif
53}
54
Ben Murdochca12bfa2013-07-23 11:17:05 +010055void SystemDisplaySetDisplayPropertiesFunction::OnPropertiesSet(
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +010056 bool success, const std::string& error) {
57 if (!success)
58 SetError(error);
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000059 SendResponse(success);
60}
61
62} // namespace extensions