| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/extensions/api/system_private/system_private_api.h" | 5 #include "chrome/browser/extensions/api/system_private/system_private_api.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 ->BroadcastEventToRenderers(histogram_value, event_name, | 63 ->BroadcastEventToRenderers(histogram_value, event_name, |
| 64 std::move(list_args), GURL()); | 64 std::move(list_args), GURL()); |
| 65 } | 65 } |
| 66 | 66 |
| 67 } // namespace | 67 } // namespace |
| 68 | 68 |
| 69 namespace extensions { | 69 namespace extensions { |
| 70 | 70 |
| 71 namespace system_private = api::system_private; | 71 namespace system_private = api::system_private; |
| 72 | 72 |
| 73 bool SystemPrivateGetIncognitoModeAvailabilityFunction::RunSync() { | 73 ExtensionFunction::ResponseAction |
| 74 PrefService* prefs = GetProfile()->GetPrefs(); | 74 SystemPrivateGetIncognitoModeAvailabilityFunction::Run() { |
| 75 PrefService* prefs = |
| 76 Profile::FromBrowserContext(browser_context())->GetPrefs(); |
| 75 int value = prefs->GetInteger(prefs::kIncognitoModeAvailability); | 77 int value = prefs->GetInteger(prefs::kIncognitoModeAvailability); |
| 76 EXTENSION_FUNCTION_VALIDATE( | 78 EXTENSION_FUNCTION_VALIDATE( |
| 77 value >= 0 && | 79 value >= 0 && |
| 78 value < static_cast<int>(arraysize(kIncognitoModeAvailabilityStrings))); | 80 value < static_cast<int>(arraysize(kIncognitoModeAvailabilityStrings))); |
| 79 SetResult(base::MakeUnique<base::StringValue>( | 81 return RespondNow(OneArgument(base::MakeUnique<base::StringValue>( |
| 80 kIncognitoModeAvailabilityStrings[value])); | 82 kIncognitoModeAvailabilityStrings[value]))); |
| 81 return true; | |
| 82 } | 83 } |
| 83 | 84 |
| 84 bool SystemPrivateGetUpdateStatusFunction::RunSync() { | 85 ExtensionFunction::ResponseAction SystemPrivateGetUpdateStatusFunction::Run() { |
| 85 std::string state; | 86 std::string state; |
| 86 double download_progress = 0; | 87 double download_progress = 0; |
| 87 #if defined(OS_CHROMEOS) | 88 #if defined(OS_CHROMEOS) |
| 88 // With UpdateEngineClient, we can provide more detailed information about | 89 // With UpdateEngineClient, we can provide more detailed information about |
| 89 // system updates on ChromeOS. | 90 // system updates on ChromeOS. |
| 90 const chromeos::UpdateEngineClient::Status status = | 91 const chromeos::UpdateEngineClient::Status status = |
| 91 chromeos::DBusThreadManager::Get()->GetUpdateEngineClient()-> | 92 chromeos::DBusThreadManager::Get()->GetUpdateEngineClient()-> |
| 92 GetLastStatus(); | 93 GetLastStatus(); |
| 93 // |download_progress| is set to 1 after download finishes | 94 // |download_progress| is set to 1 after download finishes |
| 94 // (i.e. verify, finalize and need-reboot phase) to indicate the progress | 95 // (i.e. verify, finalize and need-reboot phase) to indicate the progress |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 break; | 129 break; |
| 129 } | 130 } |
| 130 #else | 131 #else |
| 131 if (UpgradeDetector::GetInstance()->notify_upgrade()) { | 132 if (UpgradeDetector::GetInstance()->notify_upgrade()) { |
| 132 state = kNeedRestartState; | 133 state = kNeedRestartState; |
| 133 download_progress = 1; | 134 download_progress = 1; |
| 134 } else { | 135 } else { |
| 135 state = kNotAvailableState; | 136 state = kNotAvailableState; |
| 136 } | 137 } |
| 137 #endif | 138 #endif |
| 139 |
| 138 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 140 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
| 139 dict->SetString(kStateKey, state); | 141 dict->SetString(kStateKey, state); |
| 140 dict->SetDouble(kDownloadProgressKey, download_progress); | 142 dict->SetDouble(kDownloadProgressKey, download_progress); |
| 141 SetResult(std::move(dict)); | 143 return RespondNow(OneArgument(std::move(dict))); |
| 142 | |
| 143 return true; | |
| 144 } | 144 } |
| 145 | 145 |
| 146 bool SystemPrivateGetApiKeyFunction::RunSync() { | 146 ExtensionFunction::ResponseAction SystemPrivateGetApiKeyFunction::Run() { |
| 147 SetResult(base::MakeUnique<base::StringValue>(google_apis::GetAPIKey())); | 147 return RespondNow(OneArgument( |
| 148 return true; | 148 base::MakeUnique<base::StringValue>(google_apis::GetAPIKey()))); |
| 149 } | 149 } |
| 150 | 150 |
| 151 void DispatchVolumeChangedEvent(double volume, bool is_volume_muted) { | 151 void DispatchVolumeChangedEvent(double volume, bool is_volume_muted) { |
| 152 base::DictionaryValue* dict = new base::DictionaryValue(); | 152 base::DictionaryValue* dict = new base::DictionaryValue(); |
| 153 dict->SetDouble(kVolumeKey, volume); | 153 dict->SetDouble(kVolumeKey, volume); |
| 154 dict->SetBoolean(kIsVolumeMutedKey, is_volume_muted); | 154 dict->SetBoolean(kIsVolumeMutedKey, is_volume_muted); |
| 155 DispatchEvent(extensions::events::SYSTEM_PRIVATE_ON_VOLUME_CHANGED, | 155 DispatchEvent(extensions::events::SYSTEM_PRIVATE_ON_VOLUME_CHANGED, |
| 156 system_private::OnVolumeChanged::kEventName, dict); | 156 system_private::OnVolumeChanged::kEventName, dict); |
| 157 } | 157 } |
| 158 | 158 |
| 159 void DispatchBrightnessChangedEvent(int brightness, bool user_initiated) { | 159 void DispatchBrightnessChangedEvent(int brightness, bool user_initiated) { |
| 160 base::DictionaryValue* dict = new base::DictionaryValue(); | 160 base::DictionaryValue* dict = new base::DictionaryValue(); |
| 161 dict->SetInteger(kBrightnessKey, brightness); | 161 dict->SetInteger(kBrightnessKey, brightness); |
| 162 dict->SetBoolean(kUserInitiatedKey, user_initiated); | 162 dict->SetBoolean(kUserInitiatedKey, user_initiated); |
| 163 DispatchEvent(extensions::events::SYSTEM_PRIVATE_ON_BRIGHTNESS_CHANGED, | 163 DispatchEvent(extensions::events::SYSTEM_PRIVATE_ON_BRIGHTNESS_CHANGED, |
| 164 system_private::OnBrightnessChanged::kEventName, dict); | 164 system_private::OnBrightnessChanged::kEventName, dict); |
| 165 } | 165 } |
| 166 | 166 |
| 167 void DispatchScreenUnlockedEvent() { | 167 void DispatchScreenUnlockedEvent() { |
| 168 DispatchEvent(extensions::events::SYSTEM_PRIVATE_ON_SCREEN_UNLOCKED, | 168 DispatchEvent(extensions::events::SYSTEM_PRIVATE_ON_SCREEN_UNLOCKED, |
| 169 system_private::OnScreenUnlocked::kEventName, NULL); | 169 system_private::OnScreenUnlocked::kEventName, NULL); |
| 170 } | 170 } |
| 171 | 171 |
| 172 void DispatchWokeUpEvent() { | 172 void DispatchWokeUpEvent() { |
| 173 DispatchEvent(extensions::events::SYSTEM_PRIVATE_ON_WOKE_UP, | 173 DispatchEvent(extensions::events::SYSTEM_PRIVATE_ON_WOKE_UP, |
| 174 system_private::OnWokeUp::kEventName, NULL); | 174 system_private::OnWokeUp::kEventName, NULL); |
| 175 } | 175 } |
| 176 | 176 |
| 177 } // namespace extensions | 177 } // namespace extensions |
| OLD | NEW |