| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/chromeos/system_logs/chrome_internal_log_source.h" |
| 6 |
| 7 #include "base/json/json_string_value_serializer.h" |
| 8 #include "chrome/browser/browser_process.h" |
| 9 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 10 #include "chrome/browser/chromeos/system_logs/system_logs_fetcher.h" |
| 11 #include "chrome/browser/extensions/extension_service.h" |
| 12 #include "chrome/browser/extensions/extension_system.h" |
| 13 #include "chrome/browser/profiles/profile_manager.h" |
| 14 #include "chrome/browser/sync/about_sync_util.h" |
| 15 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 16 #include "chrome/common/extensions/extension.h" |
| 17 #include "chrome/common/extensions/extension_set.h" |
| 18 #include "content/public/browser/browser_thread.h" |
| 19 |
| 20 |
| 21 const char kSyncDataKey[] = "about_sync_data"; |
| 22 const char kExtensionsListKey[] = "extensions"; |
| 23 |
| 24 namespace chromeos { |
| 25 |
| 26 void ChromeInternalLogSource::Fetch(const SysLogsSourceCallback& callback) { |
| 27 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 28 DCHECK(!callback.is_null()); |
| 29 |
| 30 SystemLogsResponse response; |
| 31 PopulateSyncLogs(&response); |
| 32 PopulateExtensionInfoLogs(&response); |
| 33 |
| 34 callback.Run(&response); |
| 35 } |
| 36 |
| 37 void ChromeInternalLogSource::PopulateSyncLogs(SystemLogsResponse* response) { |
| 38 Profile* profile = ProfileManager::GetDefaultProfile(); |
| 39 if (!ProfileSyncServiceFactory::GetInstance()->HasProfileSyncService( |
| 40 profile)) |
| 41 return; |
| 42 |
| 43 ProfileSyncService* service = |
| 44 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile); |
| 45 scoped_ptr<base::DictionaryValue> sync_logs( |
| 46 sync_ui_util::ConstructAboutInformation(service)); |
| 47 |
| 48 // Remove credentials section. |
| 49 base::ListValue* details = NULL; |
| 50 sync_logs->GetList(kDetailsKey, &details); |
| 51 if (!details) |
| 52 return; |
| 53 for (base::ListValue::iterator it = details->begin(); |
| 54 it != details->end(); ++it) { |
| 55 base::DictionaryValue* dict = NULL; |
| 56 if ((*it)->GetAsDictionary(&dict)) { |
| 57 std::string title; |
| 58 dict->GetString("title", &title); |
| 59 if (title == kCredentialsTitle) { |
| 60 details->Erase(it, NULL); |
| 61 break; |
| 62 } |
| 63 } |
| 64 } |
| 65 |
| 66 // Add sync logs to logs. |
| 67 std::string sync_logs_string; |
| 68 JSONStringValueSerializer serializer(&sync_logs_string); |
| 69 serializer.Serialize(*sync_logs.get()); |
| 70 |
| 71 (*response)[kSyncDataKey] = sync_logs_string; |
| 72 } |
| 73 |
| 74 void ChromeInternalLogSource::PopulateExtensionInfoLogs( |
| 75 SystemLogsResponse* response) { |
| 76 bool reporting_enabled = false; |
| 77 chromeos::CrosSettings::Get()->GetBoolean(chromeos::kStatsReportingPref, |
| 78 &reporting_enabled); |
| 79 if (!reporting_enabled) |
| 80 return; |
| 81 |
| 82 Profile* default_profile = |
| 83 g_browser_process->profile_manager()->GetDefaultProfile(); |
| 84 if (!default_profile) |
| 85 return; |
| 86 |
| 87 ExtensionService* service = |
| 88 extensions::ExtensionSystem::Get(default_profile)->extension_service(); |
| 89 if (!service) |
| 90 return; |
| 91 |
| 92 std::string extensions_list; |
| 93 const ExtensionSet* extensions = service->extensions(); |
| 94 for (ExtensionSet::const_iterator it = extensions->begin(); |
| 95 it != extensions->end(); |
| 96 ++it) { |
| 97 const extensions::Extension* extension = *it; |
| 98 if (extensions_list.empty()) { |
| 99 extensions_list = extension->name(); |
| 100 } else { |
| 101 extensions_list += ", " + extension->name(); |
| 102 } |
| 103 } |
| 104 |
| 105 if (!extensions_list.empty()) |
| 106 (*response)[kExtensionsListKey] = extensions_list; |
| 107 } |
| 108 |
| 109 } // namespace chromeos |
| OLD | NEW |