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/values.h" | 11 #include "base/values.h" |
11 #include "build/build_config.h" | 12 #include "build/build_config.h" |
12 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
13 #include "chrome/browser/extensions/event_router_forwarder.h" | 14 #include "chrome/browser/extensions/event_router_forwarder.h" |
14 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/common/extensions/api/system_private.h" | 16 #include "chrome/common/extensions/api/system_private.h" |
16 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
17 #include "components/prefs/pref_service.h" | 18 #include "components/prefs/pref_service.h" |
18 #include "google_apis/google_api_keys.h" | 19 #include "google_apis/google_api_keys.h" |
19 | 20 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 namespace extensions { | 69 namespace extensions { |
69 | 70 |
70 namespace system_private = api::system_private; | 71 namespace system_private = api::system_private; |
71 | 72 |
72 bool SystemPrivateGetIncognitoModeAvailabilityFunction::RunSync() { | 73 bool SystemPrivateGetIncognitoModeAvailabilityFunction::RunSync() { |
73 PrefService* prefs = GetProfile()->GetPrefs(); | 74 PrefService* prefs = GetProfile()->GetPrefs(); |
74 int value = prefs->GetInteger(prefs::kIncognitoModeAvailability); | 75 int value = prefs->GetInteger(prefs::kIncognitoModeAvailability); |
75 EXTENSION_FUNCTION_VALIDATE( | 76 EXTENSION_FUNCTION_VALIDATE( |
76 value >= 0 && | 77 value >= 0 && |
77 value < static_cast<int>(arraysize(kIncognitoModeAvailabilityStrings))); | 78 value < static_cast<int>(arraysize(kIncognitoModeAvailabilityStrings))); |
78 SetResult(new base::StringValue(kIncognitoModeAvailabilityStrings[value])); | 79 SetResult(base::MakeUnique<base::StringValue>( |
| 80 kIncognitoModeAvailabilityStrings[value])); |
79 return true; | 81 return true; |
80 } | 82 } |
81 | 83 |
82 bool SystemPrivateGetUpdateStatusFunction::RunSync() { | 84 bool SystemPrivateGetUpdateStatusFunction::RunSync() { |
83 std::string state; | 85 std::string state; |
84 double download_progress = 0; | 86 double download_progress = 0; |
85 #if defined(OS_CHROMEOS) | 87 #if defined(OS_CHROMEOS) |
86 // With UpdateEngineClient, we can provide more detailed information about | 88 // With UpdateEngineClient, we can provide more detailed information about |
87 // system updates on ChromeOS. | 89 // system updates on ChromeOS. |
88 const chromeos::UpdateEngineClient::Status status = | 90 const chromeos::UpdateEngineClient::Status status = |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 break; | 128 break; |
127 } | 129 } |
128 #else | 130 #else |
129 if (UpgradeDetector::GetInstance()->notify_upgrade()) { | 131 if (UpgradeDetector::GetInstance()->notify_upgrade()) { |
130 state = kNeedRestartState; | 132 state = kNeedRestartState; |
131 download_progress = 1; | 133 download_progress = 1; |
132 } else { | 134 } else { |
133 state = kNotAvailableState; | 135 state = kNotAvailableState; |
134 } | 136 } |
135 #endif | 137 #endif |
136 base::DictionaryValue* dict = new base::DictionaryValue(); | 138 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
137 dict->SetString(kStateKey, state); | 139 dict->SetString(kStateKey, state); |
138 dict->SetDouble(kDownloadProgressKey, download_progress); | 140 dict->SetDouble(kDownloadProgressKey, download_progress); |
139 SetResult(dict); | 141 SetResult(std::move(dict)); |
140 | 142 |
141 return true; | 143 return true; |
142 } | 144 } |
143 | 145 |
144 bool SystemPrivateGetApiKeyFunction::RunSync() { | 146 bool SystemPrivateGetApiKeyFunction::RunSync() { |
145 SetResult(new base::StringValue(google_apis::GetAPIKey())); | 147 SetResult(base::MakeUnique<base::StringValue>(google_apis::GetAPIKey())); |
146 return true; | 148 return true; |
147 } | 149 } |
148 | 150 |
149 void DispatchVolumeChangedEvent(double volume, bool is_volume_muted) { | 151 void DispatchVolumeChangedEvent(double volume, bool is_volume_muted) { |
150 base::DictionaryValue* dict = new base::DictionaryValue(); | 152 base::DictionaryValue* dict = new base::DictionaryValue(); |
151 dict->SetDouble(kVolumeKey, volume); | 153 dict->SetDouble(kVolumeKey, volume); |
152 dict->SetBoolean(kIsVolumeMutedKey, is_volume_muted); | 154 dict->SetBoolean(kIsVolumeMutedKey, is_volume_muted); |
153 DispatchEvent(extensions::events::SYSTEM_PRIVATE_ON_VOLUME_CHANGED, | 155 DispatchEvent(extensions::events::SYSTEM_PRIVATE_ON_VOLUME_CHANGED, |
154 system_private::OnVolumeChanged::kEventName, dict); | 156 system_private::OnVolumeChanged::kEventName, dict); |
155 } | 157 } |
(...skipping 10 matching lines...) Expand all Loading... |
166 DispatchEvent(extensions::events::SYSTEM_PRIVATE_ON_SCREEN_UNLOCKED, | 168 DispatchEvent(extensions::events::SYSTEM_PRIVATE_ON_SCREEN_UNLOCKED, |
167 system_private::OnScreenUnlocked::kEventName, NULL); | 169 system_private::OnScreenUnlocked::kEventName, NULL); |
168 } | 170 } |
169 | 171 |
170 void DispatchWokeUpEvent() { | 172 void DispatchWokeUpEvent() { |
171 DispatchEvent(extensions::events::SYSTEM_PRIVATE_ON_WOKE_UP, | 173 DispatchEvent(extensions::events::SYSTEM_PRIVATE_ON_WOKE_UP, |
172 system_private::OnWokeUp::kEventName, NULL); | 174 system_private::OnWokeUp::kEventName, NULL); |
173 } | 175 } |
174 | 176 |
175 } // namespace extensions | 177 } // namespace extensions |
OLD | NEW |