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/about_sync_util.h"
14 #include "chrome/browser/sync/profile_sync_service_factory.h"
15 #include "chrome/common/chrome_version_info.h"
16 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_names.h"
17 #include "content/public/browser/browser_thread.h"
18 #include "extensions/browser/extension_registry.h"
19 #include "extensions/common/extension.h"
20 #include "extensions/common/extension_set.h"
25 const char kSyncDataKey
[] = "about_sync_data";
26 const char kExtensionsListKey
[] = "extensions";
27 const char kDataReductionProxyKey
[] = "data_reduction_proxy";
28 const char kChromeVersionTag
[] = "CHROME VERSION";
29 #if !defined(OS_CHROMEOS)
30 const char kOsVersionTag
[] = "OS VERSION";
35 namespace system_logs
{
37 ChromeInternalLogSource::ChromeInternalLogSource()
38 : SystemLogsSource("ChromeInternal") {
41 ChromeInternalLogSource::~ChromeInternalLogSource() {
44 void ChromeInternalLogSource::Fetch(const SysLogsSourceCallback
& callback
) {
45 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI
));
46 DCHECK(!callback
.is_null());
48 SystemLogsResponse response
;
50 chrome::VersionInfo version_info
;
51 response
[kChromeVersionTag
] = version_info
.CreateVersionString();
53 #if !defined(OS_CHROMEOS)
54 // On ChromeOS, this will be pulled in from the LSB_RELEASE.
55 std::string os_version
= base::SysInfo::OperatingSystemName() + ": " +
56 base::SysInfo::OperatingSystemVersion();
57 response
[kOsVersionTag
] = os_version
;
60 PopulateSyncLogs(&response
);
61 PopulateExtensionInfoLogs(&response
);
62 PopulateDataReductionProxyLogs(&response
);
64 callback
.Run(&response
);
67 void ChromeInternalLogSource::PopulateSyncLogs(SystemLogsResponse
* response
) {
68 // We are only interested in sync logs for the primary user profile.
69 Profile
* profile
= ProfileManager::GetPrimaryUserProfile();
71 !ProfileSyncServiceFactory::GetInstance()->HasProfileSyncService(profile
))
74 ProfileSyncService
* service
=
75 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile
);
76 scoped_ptr
<base::DictionaryValue
> sync_logs(
77 sync_ui_util::ConstructAboutInformation(service
));
79 // Remove identity section.
80 base::ListValue
* details
= NULL
;
81 sync_logs
->GetList(kDetailsKey
, &details
);
84 for (base::ListValue::iterator it
= details
->begin();
85 it
!= details
->end(); ++it
) {
86 base::DictionaryValue
* dict
= NULL
;
87 if ((*it
)->GetAsDictionary(&dict
)) {
89 dict
->GetString("title", &title
);
90 if (title
== kIdentityTitle
) {
91 details
->Erase(it
, NULL
);
97 // Add sync logs to logs.
98 std::string sync_logs_string
;
99 JSONStringValueSerializer
serializer(&sync_logs_string
);
100 serializer
.Serialize(*sync_logs
.get());
102 (*response
)[kSyncDataKey
] = sync_logs_string
;
105 void ChromeInternalLogSource::PopulateExtensionInfoLogs(
106 SystemLogsResponse
* response
) {
107 if (!ChromeMetricsServiceAccessor::IsCrashReportingEnabled())
110 Profile
* primary_profile
=
111 g_browser_process
->profile_manager()->GetPrimaryUserProfile();
112 if (!primary_profile
)
115 extensions::ExtensionRegistry
* extension_registry
=
116 extensions::ExtensionRegistry::Get(primary_profile
);
117 std::string extensions_list
;
118 for (const scoped_refptr
<const extensions::Extension
>& extension
:
119 extension_registry
->enabled_extensions()) {
120 if (extensions_list
.empty()) {
121 extensions_list
= extension
->name();
123 extensions_list
+= ",\n" + extension
->name();
126 if (!extensions_list
.empty())
127 extensions_list
+= "\n";
129 if (!extensions_list
.empty())
130 (*response
)[kExtensionsListKey
] = extensions_list
;
133 void ChromeInternalLogSource::PopulateDataReductionProxyLogs(
134 SystemLogsResponse
* response
) {
135 PrefService
* prefs
= ProfileManager::GetActiveUserProfile()->GetPrefs();
136 bool is_data_reduction_proxy_enabled
= prefs
->HasPrefPath(
137 data_reduction_proxy::prefs::kDataReductionProxyEnabled
) &&
139 data_reduction_proxy::prefs::kDataReductionProxyEnabled
);
140 (*response
)[kDataReductionProxyKey
] = is_data_reduction_proxy_enabled
?
141 "enabled" : "disabled";
144 } // namespace system_logs