| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/feedback/system_logs/log_sources/chrome_internal_log_so
urce.h" | 5 #include "chrome/browser/feedback/system_logs/log_sources/chrome_internal_log_so
urce.h" |
| 6 | 6 |
| 7 #include "base/json/json_string_value_serializer.h" | 7 #include "base/json/json_string_value_serializer.h" |
| 8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "base/sys_info.h" | 9 #include "base/sys_info.h" |
| 10 #include "base/task_scheduler/post_task.h" | 10 #include "base/task_scheduler/post_task.h" |
| 11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
| 12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
| 13 #include "chrome/browser/google/google_brand.h" | 13 #include "chrome/browser/google/google_brand.h" |
| 14 #include "chrome/browser/profiles/profile_manager.h" | 14 #include "chrome/browser/profiles/profile_manager.h" |
| 15 #include "chrome/browser/sync/profile_sync_service_factory.h" | 15 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 16 #include "chrome/common/channel_info.h" | 16 #include "chrome/common/channel_info.h" |
| 17 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
| 18 #include "components/browser_sync/profile_sync_service.h" | 18 #include "components/browser_sync/profile_sync_service.h" |
| 19 #include "components/prefs/pref_service.h" | 19 #include "components/prefs/pref_service.h" |
| 20 #include "components/sync/driver/about_sync_util.h" | 20 #include "components/sync/driver/about_sync_util.h" |
| 21 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
| 22 #include "extensions/browser/api/power/power_api.h" | 22 #include "extensions/browser/api/power/power_api.h" |
| 23 #include "extensions/browser/extension_registry.h" | 23 #include "extensions/browser/extension_registry.h" |
| 24 #include "extensions/common/api/power.h" | 24 #include "extensions/common/api/power.h" |
| 25 #include "extensions/common/extension.h" | 25 #include "extensions/common/extension.h" |
| 26 #include "extensions/common/extension_set.h" | 26 #include "extensions/common/extension_set.h" |
| 27 | 27 |
| 28 #if defined(OS_CHROMEOS) | 28 #if defined(OS_CHROMEOS) |
| 29 #include "chrome/browser/chromeos/arc/arc_util.h" |
| 29 #include "chrome/browser/metrics/chromeos_metrics_provider.h" | 30 #include "chrome/browser/metrics/chromeos_metrics_provider.h" |
| 30 #include "chromeos/system/statistics_provider.h" | 31 #include "chromeos/system/statistics_provider.h" |
| 31 #include "chromeos/system/version_loader.h" | 32 #include "chromeos/system/version_loader.h" |
| 32 #endif | 33 #endif |
| 33 | 34 |
| 34 #if defined(OS_WIN) | 35 #if defined(OS_WIN) |
| 35 #include "base/win/win_util.h" | 36 #include "base/win/win_util.h" |
| 36 #endif | 37 #endif |
| 37 | 38 |
| 38 namespace system_logs { | 39 namespace system_logs { |
| 39 | 40 |
| 40 namespace { | 41 namespace { |
| 41 | 42 |
| 42 constexpr char kSyncDataKey[] = "about_sync_data"; | 43 constexpr char kSyncDataKey[] = "about_sync_data"; |
| 43 constexpr char kExtensionsListKey[] = "extensions"; | 44 constexpr char kExtensionsListKey[] = "extensions"; |
| 44 constexpr char kPowerApiListKey[] = "chrome.power extensions"; | 45 constexpr char kPowerApiListKey[] = "chrome.power extensions"; |
| 45 constexpr char kDataReductionProxyKey[] = "data_reduction_proxy"; | 46 constexpr char kDataReductionProxyKey[] = "data_reduction_proxy"; |
| 46 constexpr char kChromeVersionTag[] = "CHROME VERSION"; | 47 constexpr char kChromeVersionTag[] = "CHROME VERSION"; |
| 47 #if defined(OS_CHROMEOS) | 48 #if defined(OS_CHROMEOS) |
| 48 constexpr char kChromeOsFirmwareVersion[] = "CHROMEOS_FIRMWARE_VERSION"; | 49 constexpr char kChromeOsFirmwareVersion[] = "CHROMEOS_FIRMWARE_VERSION"; |
| 49 constexpr char kChromeEnrollmentTag[] = "ENTERPRISE_ENROLLED"; | 50 constexpr char kChromeEnrollmentTag[] = "ENTERPRISE_ENROLLED"; |
| 50 constexpr char kHWIDKey[] = "HWID"; | 51 constexpr char kHWIDKey[] = "HWID"; |
| 51 constexpr char kSettingsKey[] = "settings"; | 52 constexpr char kSettingsKey[] = "settings"; |
| 52 constexpr char kLocalStateSettingsResponseKey[] = "Local State: settings"; | 53 constexpr char kLocalStateSettingsResponseKey[] = "Local State: settings"; |
| 54 constexpr char kArcStatusKey[] = "CHROMEOS_ARC_STATUS"; |
| 53 #else | 55 #else |
| 54 constexpr char kOsVersionTag[] = "OS VERSION"; | 56 constexpr char kOsVersionTag[] = "OS VERSION"; |
| 55 #endif | 57 #endif |
| 56 #if defined(OS_WIN) | 58 #if defined(OS_WIN) |
| 57 constexpr char kUsbKeyboardDetected[] = "usb_keyboard_detected"; | 59 constexpr char kUsbKeyboardDetected[] = "usb_keyboard_detected"; |
| 58 constexpr char kIsEnrolledToDomain[] = "enrolled_to_domain"; | 60 constexpr char kIsEnrolledToDomain[] = "enrolled_to_domain"; |
| 59 constexpr char kInstallerBrandCode[] = "installer_brand_code"; | 61 constexpr char kInstallerBrandCode[] = "installer_brand_code"; |
| 60 #endif | 62 #endif |
| 61 | 63 |
| 62 #if defined(OS_CHROMEOS) | 64 #if defined(OS_CHROMEOS) |
| (...skipping 18 matching lines...) Expand all Loading... |
| 81 | 83 |
| 82 chromeos::system::StatisticsProvider* stats = | 84 chromeos::system::StatisticsProvider* stats = |
| 83 chromeos::system::StatisticsProvider::GetInstance(); | 85 chromeos::system::StatisticsProvider::GetInstance(); |
| 84 DCHECK(stats); | 86 DCHECK(stats); |
| 85 | 87 |
| 86 // Get the HWID. | 88 // Get the HWID. |
| 87 std::string hwid; | 89 std::string hwid; |
| 88 if (!stats->GetMachineStatistic(chromeos::system::kHardwareClassKey, &hwid)) | 90 if (!stats->GetMachineStatistic(chromeos::system::kHardwareClassKey, &hwid)) |
| 89 VLOG(1) << "Couldn't get machine statistic 'hardware_class'."; | 91 VLOG(1) << "Couldn't get machine statistic 'hardware_class'."; |
| 90 else | 92 else |
| 91 (*response)[kHWIDKey] = hwid; | 93 response->emplace(kHWIDKey, hwid); |
| 92 | 94 |
| 93 // Get the firmware version. | 95 // Get the firmware version. |
| 94 (*response)[kChromeOsFirmwareVersion] = | 96 response->emplace(kChromeOsFirmwareVersion, |
| 95 chromeos::version_loader::GetFirmware(); | 97 chromeos::version_loader::GetFirmware()); |
| 96 } | 98 } |
| 97 #endif | 99 #endif |
| 98 | 100 |
| 99 } // namespace | 101 } // namespace |
| 100 | 102 |
| 101 ChromeInternalLogSource::ChromeInternalLogSource() | 103 ChromeInternalLogSource::ChromeInternalLogSource() |
| 102 : SystemLogsSource("ChromeInternal") { | 104 : SystemLogsSource("ChromeInternal") { |
| 103 } | 105 } |
| 104 | 106 |
| 105 ChromeInternalLogSource::~ChromeInternalLogSource() { | 107 ChromeInternalLogSource::~ChromeInternalLogSource() { |
| 106 } | 108 } |
| 107 | 109 |
| 108 void ChromeInternalLogSource::Fetch(const SysLogsSourceCallback& callback) { | 110 void ChromeInternalLogSource::Fetch(const SysLogsSourceCallback& callback) { |
| 109 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 111 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 110 DCHECK(!callback.is_null()); | 112 DCHECK(!callback.is_null()); |
| 111 | 113 |
| 112 std::unique_ptr<SystemLogsResponse> response(new SystemLogsResponse()); | 114 std::unique_ptr<SystemLogsResponse> response(new SystemLogsResponse()); |
| 113 | 115 |
| 114 (*response)[kChromeVersionTag] = chrome::GetVersionString(); | 116 response->emplace(kChromeVersionTag, chrome::GetVersionString()); |
| 115 | 117 |
| 116 #if defined(OS_CHROMEOS) | 118 #if defined(OS_CHROMEOS) |
| 117 (*response)[kChromeEnrollmentTag] = GetEnrollmentStatusString(); | 119 response->emplace(kChromeEnrollmentTag, GetEnrollmentStatusString()); |
| 118 #else | 120 #else |
| 119 // On ChromeOS, this will be pulled in from the LSB_RELEASE. | 121 // On ChromeOS, this will be pulled in from the LSB_RELEASE. |
| 120 std::string os_version = base::SysInfo::OperatingSystemName() + ": " + | 122 std::string os_version = base::SysInfo::OperatingSystemName() + ": " + |
| 121 base::SysInfo::OperatingSystemVersion(); | 123 base::SysInfo::OperatingSystemVersion(); |
| 122 (*response)[kOsVersionTag] = os_version; | 124 response->emplace(kOsVersionTag, os_version); |
| 123 #endif | 125 #endif |
| 124 | 126 |
| 125 PopulateSyncLogs(response.get()); | 127 PopulateSyncLogs(response.get()); |
| 126 PopulateExtensionInfoLogs(response.get()); | 128 PopulateExtensionInfoLogs(response.get()); |
| 127 PopulatePowerApiLogs(response.get()); | 129 PopulatePowerApiLogs(response.get()); |
| 128 PopulateDataReductionProxyLogs(response.get()); | 130 PopulateDataReductionProxyLogs(response.get()); |
| 129 #if defined(OS_WIN) | 131 #if defined(OS_WIN) |
| 130 PopulateUsbKeyboardDetected(response.get()); | 132 PopulateUsbKeyboardDetected(response.get()); |
| 131 PopulateEnrolledToDomain(response.get()); | 133 PopulateEnrolledToDomain(response.get()); |
| 132 PopulateInstallerBrandCode(response.get()); | 134 PopulateInstallerBrandCode(response.get()); |
| 133 #endif | 135 #endif |
| 134 | 136 |
| 135 if (ProfileManager::GetLastUsedProfile()->IsChild()) | 137 if (ProfileManager::GetLastUsedProfile()->IsChild()) |
| 136 (*response)["account_type"] = "child"; | 138 response->emplace("account_type", "child"); |
| 137 | 139 |
| 138 #if defined(OS_CHROMEOS) | 140 #if defined(OS_CHROMEOS) |
| 139 PopulateLocalStateSettings(response.get()); | 141 PopulateLocalStateSettings(response.get()); |
| 140 | 142 |
| 143 // Store ARC enabled status. |
| 144 response->emplace(kArcStatusKey, arc::IsArcPlayStoreEnabledForProfile( |
| 145 ProfileManager::GetLastUsedProfile()) |
| 146 ? "enabled" |
| 147 : "disabled"); |
| 148 |
| 141 // Get the entries that should be retrieved on the blocking pool and invoke | 149 // Get the entries that should be retrieved on the blocking pool and invoke |
| 142 // the callback later when done. | 150 // the callback later when done. |
| 143 SystemLogsResponse* response_ptr = response.release(); | 151 SystemLogsResponse* response_ptr = response.release(); |
| 144 base::PostTaskWithTraitsAndReply( | 152 base::PostTaskWithTraitsAndReply( |
| 145 FROM_HERE, {base::MayBlock(), base::TaskPriority::BACKGROUND}, | 153 FROM_HERE, {base::MayBlock(), base::TaskPriority::BACKGROUND}, |
| 146 base::Bind(&GetEntriesAsync, response_ptr), | 154 base::Bind(&GetEntriesAsync, response_ptr), |
| 147 base::Bind(callback, base::Owned(response_ptr))); | 155 base::Bind(callback, base::Owned(response_ptr))); |
| 148 #else | 156 #else |
| 149 // On other platforms, we're done. Invoke the callback. | 157 // On other platforms, we're done. Invoke the callback. |
| 150 callback.Run(response.get()); | 158 callback.Run(response.get()); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 180 break; | 188 break; |
| 181 } | 189 } |
| 182 } | 190 } |
| 183 } | 191 } |
| 184 | 192 |
| 185 // Add sync logs to logs. | 193 // Add sync logs to logs. |
| 186 std::string sync_logs_string; | 194 std::string sync_logs_string; |
| 187 JSONStringValueSerializer serializer(&sync_logs_string); | 195 JSONStringValueSerializer serializer(&sync_logs_string); |
| 188 serializer.Serialize(*sync_logs.get()); | 196 serializer.Serialize(*sync_logs.get()); |
| 189 | 197 |
| 190 (*response)[kSyncDataKey] = sync_logs_string; | 198 response->emplace(kSyncDataKey, sync_logs_string); |
| 191 } | 199 } |
| 192 | 200 |
| 193 void ChromeInternalLogSource::PopulateExtensionInfoLogs( | 201 void ChromeInternalLogSource::PopulateExtensionInfoLogs( |
| 194 SystemLogsResponse* response) { | 202 SystemLogsResponse* response) { |
| 195 Profile* primary_profile = | 203 Profile* primary_profile = |
| 196 g_browser_process->profile_manager()->GetPrimaryUserProfile(); | 204 g_browser_process->profile_manager()->GetPrimaryUserProfile(); |
| 197 if (!primary_profile) | 205 if (!primary_profile) |
| 198 return; | 206 return; |
| 199 | 207 |
| 200 extensions::ExtensionRegistry* extension_registry = | 208 extensions::ExtensionRegistry* extension_registry = |
| 201 extensions::ExtensionRegistry::Get(primary_profile); | 209 extensions::ExtensionRegistry::Get(primary_profile); |
| 202 std::string extensions_list; | 210 std::string extensions_list; |
| 203 for (const scoped_refptr<const extensions::Extension>& extension : | 211 for (const scoped_refptr<const extensions::Extension>& extension : |
| 204 extension_registry->enabled_extensions()) { | 212 extension_registry->enabled_extensions()) { |
| 205 // Format the list as: | 213 // Format the list as: |
| 206 // "extension_id" : "extension_name" : "extension_version". | 214 // "extension_id" : "extension_name" : "extension_version". |
| 207 | 215 |
| 208 // Work around the anonymizer tool recognizing some versions as IPv4s. | 216 // Work around the anonymizer tool recognizing some versions as IPv4s. |
| 209 // Replaces dots "." by underscores "_". | 217 // Replaces dots "." by underscores "_". |
| 210 // We shouldn't change the anonymizer tool as it is working as intended; it | 218 // We shouldn't change the anonymizer tool as it is working as intended; it |
| 211 // must err on the side of safety. | 219 // must err on the side of safety. |
| 212 std::string version; | 220 std::string version; |
| 213 base::ReplaceChars(extension->VersionString(), ".", "_", &version); | 221 base::ReplaceChars(extension->VersionString(), ".", "_", &version); |
| 214 extensions_list += extension->id() + " : " + extension->name() + | 222 extensions_list += extension->id() + " : " + extension->name() + |
| 215 " : version " + version + "\n"; | 223 " : version " + version + "\n"; |
| 216 } | 224 } |
| 217 | 225 |
| 218 if (!extensions_list.empty()) | 226 if (!extensions_list.empty()) |
| 219 (*response)[kExtensionsListKey] = extensions_list; | 227 response->emplace(kExtensionsListKey, extensions_list); |
| 220 } | 228 } |
| 221 | 229 |
| 222 void ChromeInternalLogSource::PopulatePowerApiLogs( | 230 void ChromeInternalLogSource::PopulatePowerApiLogs( |
| 223 SystemLogsResponse* response) { | 231 SystemLogsResponse* response) { |
| 224 std::string info; | 232 std::string info; |
| 225 for (auto* profile : | 233 for (auto* profile : |
| 226 g_browser_process->profile_manager()->GetLoadedProfiles()) { | 234 g_browser_process->profile_manager()->GetLoadedProfiles()) { |
| 227 for (const auto& it : | 235 for (const auto& it : |
| 228 extensions::PowerAPI::Get(profile)->extension_levels()) { | 236 extensions::PowerAPI::Get(profile)->extension_levels()) { |
| 229 if (!info.empty()) | 237 if (!info.empty()) |
| 230 info += ",\n"; | 238 info += ",\n"; |
| 231 info += it.first + ": " + extensions::api::power::ToString(it.second); | 239 info += it.first + ": " + extensions::api::power::ToString(it.second); |
| 232 } | 240 } |
| 233 } | 241 } |
| 234 | 242 |
| 235 if (!info.empty()) | 243 if (!info.empty()) |
| 236 (*response)[kPowerApiListKey] = info; | 244 response->emplace(kPowerApiListKey, info); |
| 237 } | 245 } |
| 238 | 246 |
| 239 void ChromeInternalLogSource::PopulateDataReductionProxyLogs( | 247 void ChromeInternalLogSource::PopulateDataReductionProxyLogs( |
| 240 SystemLogsResponse* response) { | 248 SystemLogsResponse* response) { |
| 241 PrefService* prefs = ProfileManager::GetActiveUserProfile()->GetPrefs(); | 249 PrefService* prefs = ProfileManager::GetActiveUserProfile()->GetPrefs(); |
| 242 bool is_data_reduction_proxy_enabled = | 250 bool is_data_reduction_proxy_enabled = |
| 243 prefs->HasPrefPath(prefs::kDataSaverEnabled) && | 251 prefs->HasPrefPath(prefs::kDataSaverEnabled) && |
| 244 prefs->GetBoolean(prefs::kDataSaverEnabled); | 252 prefs->GetBoolean(prefs::kDataSaverEnabled); |
| 245 (*response)[kDataReductionProxyKey] = is_data_reduction_proxy_enabled ? | 253 response->emplace(kDataReductionProxyKey, |
| 246 "enabled" : "disabled"; | 254 is_data_reduction_proxy_enabled ? "enabled" : "disabled"); |
| 247 } | 255 } |
| 248 | 256 |
| 249 #if defined(OS_CHROMEOS) | 257 #if defined(OS_CHROMEOS) |
| 250 void ChromeInternalLogSource::PopulateLocalStateSettings( | 258 void ChromeInternalLogSource::PopulateLocalStateSettings( |
| 251 SystemLogsResponse* response) { | 259 SystemLogsResponse* response) { |
| 252 // Extract the "settings" entry in the local state and serialize back to | 260 // Extract the "settings" entry in the local state and serialize back to |
| 253 // a string. | 261 // a string. |
| 254 std::unique_ptr<base::DictionaryValue> local_state = | 262 std::unique_ptr<base::DictionaryValue> local_state = |
| 255 g_browser_process->local_state()->GetPreferenceValues( | 263 g_browser_process->local_state()->GetPreferenceValues( |
| 256 PrefService::EXCLUDE_DEFAULTS); | 264 PrefService::EXCLUDE_DEFAULTS); |
| 257 const base::DictionaryValue* local_state_settings = nullptr; | 265 const base::DictionaryValue* local_state_settings = nullptr; |
| 258 if (!local_state->GetDictionary(kSettingsKey, &local_state_settings)) { | 266 if (!local_state->GetDictionary(kSettingsKey, &local_state_settings)) { |
| 259 VLOG(1) << "Failed to extract the settings entry from Local State."; | 267 VLOG(1) << "Failed to extract the settings entry from Local State."; |
| 260 return; | 268 return; |
| 261 } | 269 } |
| 262 std::string serialized_settings; | 270 std::string serialized_settings; |
| 263 JSONStringValueSerializer serializer(&serialized_settings); | 271 JSONStringValueSerializer serializer(&serialized_settings); |
| 264 if (!serializer.Serialize(*local_state_settings)) | 272 if (!serializer.Serialize(*local_state_settings)) |
| 265 return; | 273 return; |
| 266 | 274 |
| 267 (*response)[kLocalStateSettingsResponseKey] = serialized_settings; | 275 response->emplace(kLocalStateSettingsResponseKey, serialized_settings); |
| 268 } | 276 } |
| 269 #endif // defined(OS_CHROMEOS) | 277 #endif // defined(OS_CHROMEOS) |
| 270 | 278 |
| 271 #if defined(OS_WIN) | 279 #if defined(OS_WIN) |
| 272 void ChromeInternalLogSource::PopulateUsbKeyboardDetected( | 280 void ChromeInternalLogSource::PopulateUsbKeyboardDetected( |
| 273 SystemLogsResponse* response) { | 281 SystemLogsResponse* response) { |
| 274 std::string reason; | 282 std::string reason; |
| 275 bool result = base::win::IsKeyboardPresentOnSlate(&reason); | 283 bool result = base::win::IsKeyboardPresentOnSlate(&reason); |
| 276 (*response)[kUsbKeyboardDetected] = result ? "Keyboard Detected:\n" : | 284 reason.insert(0, result ? "Keyboard Detected:\n" : "No Keyboard:\n"); |
| 277 "No Keyboard:\n"; | 285 response->emplace(kUsbKeyboardDetected, reason); |
| 278 (*response)[kUsbKeyboardDetected] += reason; | |
| 279 } | 286 } |
| 280 | 287 |
| 281 void ChromeInternalLogSource::PopulateEnrolledToDomain( | 288 void ChromeInternalLogSource::PopulateEnrolledToDomain( |
| 282 SystemLogsResponse* response) { | 289 SystemLogsResponse* response) { |
| 283 (*response)[kIsEnrolledToDomain] = base::win::IsEnrolledToDomain() | 290 response->emplace(kIsEnrolledToDomain, base::win::IsEnrolledToDomain() |
| 284 ? "Enrolled to domain" | 291 ? "Enrolled to domain" |
| 285 : "Not enrolled to domain"; | 292 : "Not enrolled to domain"); |
| 286 } | 293 } |
| 287 | 294 |
| 288 void ChromeInternalLogSource::PopulateInstallerBrandCode( | 295 void ChromeInternalLogSource::PopulateInstallerBrandCode( |
| 289 SystemLogsResponse* response) { | 296 SystemLogsResponse* response) { |
| 290 std::string brand; | 297 std::string brand; |
| 291 google_brand::GetBrand(&brand); | 298 google_brand::GetBrand(&brand); |
| 292 (*response)[kInstallerBrandCode] = | 299 response->emplace(kInstallerBrandCode, |
| 293 brand.empty() ? "Unknown brand code" : brand; | 300 brand.empty() ? "Unknown brand code" : brand); |
| 294 } | 301 } |
| 295 #endif | 302 #endif |
| 296 | 303 |
| 297 } // namespace system_logs | 304 } // namespace system_logs |
| OLD | NEW |