cygprofile: increase timeouts to allow showing web contents
[chromium-blink-merge.git] / chrome / browser / feedback / system_logs / log_sources / chrome_internal_log_source.cc
bloba534f9320bec161d8d5f2973b7da5e86b014d63b
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"
23 #if defined(OS_WIN)
24 #include "base/win/win_util.h"
25 #endif
27 namespace {
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";
35 #endif
36 #if defined(OS_WIN)
37 const char kUsbKeyboardDetected[] = "usb_keyboard_detected";
38 #endif
40 } // namespace
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;
64 #endif
66 PopulateSyncLogs(&response);
67 PopulateExtensionInfoLogs(&response);
68 PopulateDataReductionProxyLogs(&response);
69 #if defined(OS_WIN)
70 PopulateUsbKeyboardDetected(&response);
71 #endif
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();
82 if (!profile ||
83 !ProfileSyncServiceFactory::GetInstance()->HasProfileSyncService(profile))
84 return;
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);
95 if (!details)
96 return;
97 for (base::ListValue::iterator it = details->begin();
98 it != details->end(); ++it) {
99 base::DictionaryValue* dict = NULL;
100 if ((*it)->GetAsDictionary(&dict)) {
101 std::string title;
102 dict->GetString("title", &title);
103 if (title == kIdentityTitle) {
104 details->Erase(it, NULL);
105 break;
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())
121 return;
123 Profile* primary_profile =
124 g_browser_process->profile_manager()->GetPrimaryUserProfile();
125 if (!primary_profile)
126 return;
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();
135 } else {
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) &&
151 prefs->GetBoolean(
152 data_reduction_proxy::prefs::kDataReductionProxyEnabled);
153 (*response)[kDataReductionProxyKey] = is_data_reduction_proxy_enabled ?
154 "enabled" : "disabled";
157 #if defined(OS_WIN)
158 void ChromeInternalLogSource::PopulateUsbKeyboardDetected(
159 SystemLogsResponse* response) {
160 std::string reason;
161 bool result = base::win::IsKeyboardPresentOnSlate(&reason);
162 (*response)[kUsbKeyboardDetected] = result ? "Keyboard Detected:\n" :
163 "No Keyboard:\n";
164 (*response)[kUsbKeyboardDetected] += reason;
166 #endif
168 } // namespace system_logs