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
3 // found in the LICENSE file.
5 #include "chrome/browser/feedback/system_logs/log_sources/chrome_internal_log_source.h"
7 #include "base/json/json_string_value_serializer.h"
8 #include "base/prefs/pref_service.h"
9 #include "base/sys_info.h"
10 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h"
12 #include "chrome/browser/profiles/profile_manager.h"
13 #include "chrome/browser/sync/profile_sync_service.h"
14 #include "chrome/browser/sync/profile_sync_service_factory.h"
15 #include "chrome/common/channel_info.h"
16 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_names.h"
17 #include "components/sync_driver/about_sync_util.h"
18 #include "content/public/browser/browser_thread.h"
19 #include "extensions/browser/extension_registry.h"
20 #include "extensions/common/extension.h"
21 #include "extensions/common/extension_set.h"
24 #include "base/win/win_util.h"
29 const char kSyncDataKey
[] = "about_sync_data";
30 const char kExtensionsListKey
[] = "extensions";
31 const char kDataReductionProxyKey
[] = "data_reduction_proxy";
32 const char kChromeVersionTag
[] = "CHROME VERSION";
33 #if !defined(OS_CHROMEOS)
34 const char kOsVersionTag
[] = "OS VERSION";
37 const char kUsbKeyboardDetected
[] = "usb_keyboard_detected";
42 namespace system_logs
{
44 ChromeInternalLogSource::ChromeInternalLogSource()
45 : SystemLogsSource("ChromeInternal") {
48 ChromeInternalLogSource::~ChromeInternalLogSource() {
51 void ChromeInternalLogSource::Fetch(const SysLogsSourceCallback
& callback
) {
52 DCHECK_CURRENTLY_ON(content::BrowserThread::UI
);
53 DCHECK(!callback
.is_null());
55 SystemLogsResponse response
;
57 response
[kChromeVersionTag
] = chrome::GetVersionString();
59 #if !defined(OS_CHROMEOS)
60 // On ChromeOS, this will be pulled in from the LSB_RELEASE.
61 std::string os_version
= base::SysInfo::OperatingSystemName() + ": " +
62 base::SysInfo::OperatingSystemVersion();
63 response
[kOsVersionTag
] = os_version
;
66 PopulateSyncLogs(&response
);
67 PopulateExtensionInfoLogs(&response
);
68 PopulateDataReductionProxyLogs(&response
);
70 PopulateUsbKeyboardDetected(&response
);
73 if (ProfileManager::GetLastUsedProfile()->IsChild())
74 response
["account_type"] = "child";
76 callback
.Run(&response
);
79 void ChromeInternalLogSource::PopulateSyncLogs(SystemLogsResponse
* response
) {
80 // We are only interested in sync logs for the primary user profile.
81 Profile
* profile
= ProfileManager::GetPrimaryUserProfile();
83 !ProfileSyncServiceFactory::GetInstance()->HasProfileSyncService(profile
))
86 ProfileSyncService
* service
=
87 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile
);
88 scoped_ptr
<base::DictionaryValue
> sync_logs(
89 sync_ui_util::ConstructAboutInformation(
90 service
, service
->signin(), chrome::GetChannel()));
92 // Remove identity section.
93 base::ListValue
* details
= NULL
;
94 sync_logs
->GetList(kDetailsKey
, &details
);
97 for (base::ListValue::iterator it
= details
->begin();
98 it
!= details
->end(); ++it
) {
99 base::DictionaryValue
* dict
= NULL
;
100 if ((*it
)->GetAsDictionary(&dict
)) {
102 dict
->GetString("title", &title
);
103 if (title
== kIdentityTitle
) {
104 details
->Erase(it
, NULL
);
110 // Add sync logs to logs.
111 std::string sync_logs_string
;
112 JSONStringValueSerializer
serializer(&sync_logs_string
);
113 serializer
.Serialize(*sync_logs
.get());
115 (*response
)[kSyncDataKey
] = sync_logs_string
;
118 void ChromeInternalLogSource::PopulateExtensionInfoLogs(
119 SystemLogsResponse
* response
) {
120 if (!ChromeMetricsServiceAccessor::IsCrashReportingEnabled())
123 Profile
* primary_profile
=
124 g_browser_process
->profile_manager()->GetPrimaryUserProfile();
125 if (!primary_profile
)
128 extensions::ExtensionRegistry
* extension_registry
=
129 extensions::ExtensionRegistry::Get(primary_profile
);
130 std::string extensions_list
;
131 for (const scoped_refptr
<const extensions::Extension
>& extension
:
132 extension_registry
->enabled_extensions()) {
133 if (extensions_list
.empty()) {
134 extensions_list
= extension
->name();
136 extensions_list
+= ",\n" + extension
->name();
139 if (!extensions_list
.empty())
140 extensions_list
+= "\n";
142 if (!extensions_list
.empty())
143 (*response
)[kExtensionsListKey
] = extensions_list
;
146 void ChromeInternalLogSource::PopulateDataReductionProxyLogs(
147 SystemLogsResponse
* response
) {
148 PrefService
* prefs
= ProfileManager::GetActiveUserProfile()->GetPrefs();
149 bool is_data_reduction_proxy_enabled
= prefs
->HasPrefPath(
150 data_reduction_proxy::prefs::kDataReductionProxyEnabled
) &&
152 data_reduction_proxy::prefs::kDataReductionProxyEnabled
);
153 (*response
)[kDataReductionProxyKey
] = is_data_reduction_proxy_enabled
?
154 "enabled" : "disabled";
158 void ChromeInternalLogSource::PopulateUsbKeyboardDetected(
159 SystemLogsResponse
* response
) {
161 bool result
= base::win::IsKeyboardPresentOnSlate(&reason
);
162 (*response
)[kUsbKeyboardDetected
] = result
? "Keyboard Detected:\n" :
164 (*response
)[kUsbKeyboardDetected
] += reason
;
168 } // namespace system_logs