From d43970a7ceee5fc5433787b0f28b64234a4039f2 Mon Sep 17 00:00:00 2001 From: "satorux@chromium.org" Date: Sun, 10 Jul 2011 06:24:52 +0000 Subject: Split SystemAccess into TimezoneSettings, StatisticsProvider, and SyslogsProvider. SystemAccess contained three separate things: timezone settings, statistics provider, and syslogs provider. We should have them in separate classes. This patch touches many files but changes are mechanical. No logic changes introduced. BUG=none TEST=chrome builds and try bots pass Review URL: http://codereview.chromium.org/7324017 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@91971 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/bug_report_data.cc | 4 +- chrome/browser/bug_report_data.h | 8 +- chrome/browser/bug_report_util.cc | 6 +- chrome/browser/bug_report_util.h | 4 +- chrome/browser/chromeos/customization_document.cc | 23 +- chrome/browser/chromeos/customization_document.h | 8 +- .../chromeos/customization_document_unittest.cc | 27 +- .../chromeos/login/base_login_display_host.cc | 4 +- chrome/browser/chromeos/login/helper.cc | 1 - chrome/browser/chromeos/mock_system_access.cc | 13 - chrome/browser/chromeos/mock_system_access.h | 37 -- chrome/browser/chromeos/name_value_pairs_parser.cc | 103 ----- chrome/browser/chromeos/name_value_pairs_parser.h | 52 --- .../chromeos/name_value_pairs_parser_unittest.cc | 64 --- .../browser/chromeos/status/clock_menu_button.cc | 6 +- chrome/browser/chromeos/status/clock_menu_button.h | 6 +- .../status/clock_menu_button_browsertest.cc | 6 +- .../chromeos/system/mock_statistics_provider.cc | 15 + .../chromeos/system/mock_statistics_provider.h | 31 ++ .../chromeos/system/name_value_pairs_parser.cc | 105 +++++ .../chromeos/system/name_value_pairs_parser.h | 54 +++ .../system/name_value_pairs_parser_unittest.cc | 66 +++ .../browser/chromeos/system/statistics_provider.cc | 108 +++++ .../browser/chromeos/system/statistics_provider.h | 32 ++ chrome/browser/chromeos/system/syslogs_provider.cc | 302 +++++++++++++ chrome/browser/chromeos/system/syslogs_provider.h | 56 +++ .../browser/chromeos/system/timezone_settings.cc | 164 +++++++ chrome/browser/chromeos/system/timezone_settings.h | 45 ++ chrome/browser/chromeos/system_access.cc | 470 --------------------- chrome/browser/chromeos/system_access.h | 78 ---- .../extension_info_private_api_chromeos.cc | 7 +- chrome/browser/metrics/metrics_service.cc | 4 +- chrome/browser/policy/cloud_policy_data_store.cc | 13 +- .../policy/device_management_backend_impl.cc | 9 +- .../policy/device_policy_identity_strategy.cc | 106 +++++ chrome/browser/ui/webui/bug_report_ui.cc | 24 +- .../webui/chromeos/imageburner/imageburner_ui.cc | 7 +- .../browser/ui/webui/chromeos/register_page_ui.cc | 12 +- chrome/browser/ui/webui/chromeos/system_info_ui.cc | 18 +- chrome/browser/ui/webui/net_internals_ui.cc | 34 +- .../options/chromeos/system_settings_provider.cc | 8 +- .../options/chromeos/system_settings_provider.h | 6 +- 42 files changed, 1213 insertions(+), 933 deletions(-) delete mode 100644 chrome/browser/chromeos/mock_system_access.cc delete mode 100644 chrome/browser/chromeos/mock_system_access.h delete mode 100644 chrome/browser/chromeos/name_value_pairs_parser.cc delete mode 100644 chrome/browser/chromeos/name_value_pairs_parser.h delete mode 100644 chrome/browser/chromeos/name_value_pairs_parser_unittest.cc create mode 100644 chrome/browser/chromeos/system/mock_statistics_provider.cc create mode 100644 chrome/browser/chromeos/system/mock_statistics_provider.h create mode 100644 chrome/browser/chromeos/system/name_value_pairs_parser.cc create mode 100644 chrome/browser/chromeos/system/name_value_pairs_parser.h create mode 100644 chrome/browser/chromeos/system/name_value_pairs_parser_unittest.cc create mode 100644 chrome/browser/chromeos/system/statistics_provider.cc create mode 100644 chrome/browser/chromeos/system/statistics_provider.h create mode 100644 chrome/browser/chromeos/system/syslogs_provider.cc create mode 100644 chrome/browser/chromeos/system/syslogs_provider.h create mode 100644 chrome/browser/chromeos/system/timezone_settings.cc create mode 100644 chrome/browser/chromeos/system/timezone_settings.h delete mode 100644 chrome/browser/chromeos/system_access.cc delete mode 100644 chrome/browser/chromeos/system_access.h create mode 100644 chrome/browser/policy/device_policy_identity_strategy.cc (limited to 'chrome/browser') diff --git a/chrome/browser/bug_report_data.cc b/chrome/browser/bug_report_data.cc index 6674570..45eb45d 100644 --- a/chrome/browser/bug_report_data.cc +++ b/chrome/browser/bug_report_data.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -50,7 +50,7 @@ void BugReportData::UpdateData(Profile* profile, #if defined(OS_CHROMEOS) // Called from the same thread as HandleGetDialogDefaults, i.e. the UI thread. -void BugReportData::SyslogsComplete(chromeos::LogDictionaryType* logs, +void BugReportData::SyslogsComplete(chromeos::system::LogDictionaryType* logs, std::string* zip_content) { if (sent_report_) { // We already sent the report, just delete the data. diff --git a/chrome/browser/bug_report_data.h b/chrome/browser/bug_report_data.h index 4d3e6df..f8da055 100644 --- a/chrome/browser/bug_report_data.h +++ b/chrome/browser/bug_report_data.h @@ -12,7 +12,7 @@ #include "chrome/browser/bug_report_util.h" #if defined(OS_CHROMEOS) -#include "chrome/browser/chromeos/system_access.h" +#include "chrome/browser/chromeos/system/syslogs_provider.h" #endif class BugReportData { @@ -43,7 +43,7 @@ class BugReportData { ); #if defined(OS_CHROMEOS) - void SyslogsComplete(chromeos::LogDictionaryType* logs, + void SyslogsComplete(chromeos::system::LogDictionaryType* logs, std::string* zip_content); #endif @@ -55,7 +55,7 @@ class BugReportData { const std::vector& image() const { return image_; } #if defined(OS_CHROMEOS) const std::string& user_email() const { return user_email_; } - chromeos::LogDictionaryType* sys_info() const { return sys_info_; } + chromeos::system::LogDictionaryType* sys_info() const { return sys_info_; } bool send_sys_info() const { return send_sys_info_; } bool sent_report() const { return sent_report_; } std::string* zip_content() const { return zip_content_; } @@ -76,7 +76,7 @@ class BugReportData { #if defined(OS_CHROMEOS) // Chromeos specific values for SendReport. std::string user_email_; - chromeos::LogDictionaryType* sys_info_; + chromeos::system::LogDictionaryType* sys_info_; // Content of the compressed system logs. std::string* zip_content_; // NOTE: Extra boolean sent_report_ is required because callback may diff --git a/chrome/browser/bug_report_util.cc b/chrome/browser/bug_report_util.cc index cedcbec..227f427 100644 --- a/chrome/browser/bug_report_util.cc +++ b/chrome/browser/bug_report_util.cc @@ -260,7 +260,7 @@ void BugReportUtil::SendReport(Profile* profile, const std::string& user_email_text, const char* zipped_logs_data, int zipped_logs_length, - const chromeos::LogDictionaryType* const sys_info) { + const chromeos::system::LogDictionaryType* const sys_info) { #else int png_height) { #endif @@ -326,8 +326,8 @@ void BugReportUtil::SendReport(Profile* profile, #if defined(OS_CHROMEOS) if (sys_info) { // Add the product specific data - for (chromeos::LogDictionaryType::const_iterator i = sys_info->begin(); - i != sys_info->end(); ++i) + for (chromeos::system::LogDictionaryType::const_iterator i = + sys_info->begin(); i != sys_info->end(); ++i) if (!CommandLine::ForCurrentProcess()->HasSwitch( switches::kCompressSystemFeedback) || ValidFeedbackSize(i->second)) { AddFeedbackData(&feedback_data, i->first, i->second); diff --git a/chrome/browser/bug_report_util.h b/chrome/browser/bug_report_util.h index dff1d67..203be98 100644 --- a/chrome/browser/bug_report_util.h +++ b/chrome/browser/bug_report_util.h @@ -20,7 +20,7 @@ #include "base/win/windows_version.h" #elif defined(OS_CHROMEOS) #include "chrome/browser/chromeos/cros/cros_library.h" -#include "chrome/browser/chromeos/system_access.h" +#include "chrome/browser/chromeos/system/syslogs_provider.h" #endif class Profile; @@ -75,7 +75,7 @@ class BugReportUtil { const std::string& user_email_text, const char* zipped_logs_data, int zipped_logs_length, - const chromeos::LogDictionaryType* const sys_info); + const chromeos::system::LogDictionaryType* const sys_info); #else int png_height); #endif diff --git a/chrome/browser/chromeos/customization_document.cc b/chrome/browser/chromeos/customization_document.cc index 8af62dc..36c198a 100644 --- a/chrome/browser/chromeos/customization_document.cc +++ b/chrome/browser/chromeos/customization_document.cc @@ -16,7 +16,7 @@ #include "chrome/browser/chromeos/cros/cros_library.h" #include "chrome/browser/chromeos/cros/network_library.h" #include "chrome/browser/chromeos/login/wizard_controller.h" -#include "chrome/browser/chromeos/system_access.h" +#include "chrome/browser/chromeos/system/statistics_provider.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/profiles/profile_manager.h" #include "content/browser/browser_thread.h" @@ -147,13 +147,14 @@ StartupCustomizationDocument::StartupCustomizationDocument() { base::ThreadRestrictions::ScopedAllowIO allow_io; LoadManifestFromFile(FilePath(kStartupCustomizationManifestPath)); } - Init(SystemAccess::GetInstance()); + Init(chromeos::system::StatisticsProvider::GetInstance()); } StartupCustomizationDocument::StartupCustomizationDocument( - SystemAccess* system_access, const std::string& manifest) { + chromeos::system::StatisticsProvider* statistics_provider, + const std::string& manifest) { LoadManifestFromString(manifest); - Init(system_access); + Init(statistics_provider); } StartupCustomizationDocument::~StartupCustomizationDocument() {} @@ -163,7 +164,8 @@ StartupCustomizationDocument* StartupCustomizationDocument::GetInstance() { DefaultSingletonTraits >::get(); } -void StartupCustomizationDocument::Init(SystemAccess* system_access) { +void StartupCustomizationDocument::Init( + chromeos::system::StatisticsProvider* statistics_provider) { if (!IsReady()) return; @@ -173,7 +175,7 @@ void StartupCustomizationDocument::Init(SystemAccess* system_access) { root_->GetString(kRegistrationUrlAttr, ®istration_url_); std::string hwid; - if (system_access->GetMachineStatistic(kHardwareClass, &hwid)) { + if (statistics_provider->GetMachineStatistic(kHardwareClass, &hwid)) { ListValue* hwid_list = NULL; if (root_->GetList(kHwidMapAttr, &hwid_list)) { for (size_t i = 0; i < hwid_list->GetSize(); ++i) { @@ -204,9 +206,12 @@ void StartupCustomizationDocument::Init(SystemAccess* system_access) { LOG(ERROR) << "HWID is missing in machine statistics"; } - system_access->GetMachineStatistic(kInitialLocaleAttr, &initial_locale_); - system_access->GetMachineStatistic(kInitialTimezoneAttr, &initial_timezone_); - system_access->GetMachineStatistic(kKeyboardLayoutAttr, &keyboard_layout_); + statistics_provider->GetMachineStatistic(kInitialLocaleAttr, + &initial_locale_); + statistics_provider->GetMachineStatistic(kInitialTimezoneAttr, + &initial_timezone_); + statistics_provider->GetMachineStatistic(kKeyboardLayoutAttr, + &keyboard_layout_); } std::string StartupCustomizationDocument::GetHelpPage( diff --git a/chrome/browser/chromeos/customization_document.h b/chrome/browser/chromeos/customization_document.h index ea12c89b..0da9347 100644 --- a/chrome/browser/chromeos/customization_document.h +++ b/chrome/browser/chromeos/customization_document.h @@ -28,7 +28,9 @@ namespace base { namespace chromeos { -class SystemAccess; +namespace system { +class StatisticsProvider; +} // system // Base class for OEM customization document classes. class CustomizationDocument { @@ -80,12 +82,12 @@ class StartupCustomizationDocument : public CustomizationDocument { StartupCustomizationDocument(); // C-tor for test construction. - StartupCustomizationDocument(SystemAccess* system_access, + StartupCustomizationDocument(system::StatisticsProvider* provider, const std::string& manifest); virtual ~StartupCustomizationDocument(); - void Init(SystemAccess* system_access); + void Init(system::StatisticsProvider* provider); // If |attr| exists in machine stat, assign it to |value|. void InitFromMachineStatistic(const char* attr, std::string* value); diff --git a/chrome/browser/chromeos/customization_document_unittest.cc b/chrome/browser/chromeos/customization_document_unittest.cc index 262e0f5..8e5bbbd 100644 --- a/chrome/browser/chromeos/customization_document_unittest.cc +++ b/chrome/browser/chromeos/customization_document_unittest.cc @@ -5,7 +5,7 @@ #include "chrome/browser/chromeos/customization_document.h" #include "base/time.h" -#include "chrome/browser/chromeos/mock_system_access.h" +#include "chrome/browser/chromeos/system/mock_statistics_provider.h" #include "testing/gtest/include/gtest/gtest.h" namespace { @@ -116,14 +116,14 @@ using ::testing::Return; using ::testing::SetArgumentPointee; TEST(StartupCustomizationDocumentTest, Basic) { - MockSystemAccess mock_system_access; - EXPECT_CALL(mock_system_access, GetMachineStatistic(_, NotNull())) + system::MockStatisticsProvider mock_statistics_provider; + EXPECT_CALL(mock_statistics_provider, GetMachineStatistic(_, NotNull())) .WillRepeatedly(Return(false)); - EXPECT_CALL(mock_system_access, + EXPECT_CALL(mock_statistics_provider, GetMachineStatistic(std::string("hardware_class"), NotNull())) .WillOnce(DoAll(SetArgumentPointee<1>(std::string("Mario 12345")), Return(true))); - StartupCustomizationDocument customization(&mock_system_access, + StartupCustomizationDocument customization(&mock_statistics_provider, kGoodStartupManifest); EXPECT_EQ("ru-RU", customization.initial_locale()); EXPECT_EQ("Europe/Moscow", customization.initial_timezone()); @@ -146,24 +146,24 @@ TEST(StartupCustomizationDocumentTest, Basic) { } TEST(StartupCustomizationDocumentTest, VPD) { - MockSystemAccess mock_system_access; - EXPECT_CALL(mock_system_access, + system::MockStatisticsProvider mock_statistics_provider; + EXPECT_CALL(mock_statistics_provider, GetMachineStatistic(std::string("hardware_class"), NotNull())) .WillOnce(DoAll(SetArgumentPointee<1>(std::string("Mario 12345")), Return(true))); - EXPECT_CALL(mock_system_access, + EXPECT_CALL(mock_statistics_provider, GetMachineStatistic(std::string("initial_locale"), NotNull())) .WillOnce(DoAll(SetArgumentPointee<1>(std::string("ja")), Return(true))); - EXPECT_CALL(mock_system_access, + EXPECT_CALL(mock_statistics_provider, GetMachineStatistic(std::string("initial_timezone"), NotNull())) .WillOnce(DoAll(SetArgumentPointee<1>(std::string("Asia/Tokyo")), Return(true))); - EXPECT_CALL(mock_system_access, + EXPECT_CALL(mock_statistics_provider, GetMachineStatistic(std::string("keyboard_layout"), NotNull())) .WillOnce(DoAll(SetArgumentPointee<1>(std::string("mozc-jp")), Return(true))); - StartupCustomizationDocument customization(&mock_system_access, + StartupCustomizationDocument customization(&mock_statistics_provider, kGoodStartupManifest); EXPECT_TRUE(customization.IsReady()); EXPECT_EQ("ja", customization.initial_locale()); @@ -172,8 +172,9 @@ TEST(StartupCustomizationDocumentTest, VPD) { } TEST(StartupCustomizationDocumentTest, BadManifest) { - MockSystemAccess mock_system_access; - StartupCustomizationDocument customization(&mock_system_access, kBadManifest); + system::MockStatisticsProvider mock_statistics_provider; + StartupCustomizationDocument customization(&mock_statistics_provider, + kBadManifest); EXPECT_FALSE(customization.IsReady()); } diff --git a/chrome/browser/chromeos/login/base_login_display_host.cc b/chrome/browser/chromeos/login/base_login_display_host.cc index 0338e19..2b763b8 100644 --- a/chrome/browser/chromeos/login/base_login_display_host.cc +++ b/chrome/browser/chromeos/login/base_login_display_host.cc @@ -23,7 +23,7 @@ #include "chrome/browser/chromeos/login/views_login_display_host.h" #include "chrome/browser/chromeos/login/webui_login_display_host.h" #include "chrome/browser/chromeos/login/wizard_controller.h" -#include "chrome/browser/chromeos/system_access.h" +#include "chrome/browser/chromeos/system/timezone_settings.h" #include "chrome/browser/chromeos/wm_ipc.h" #include "chrome/browser/policy/browser_policy_connector.h" #include "chrome/browser/prefs/pref_service.h" @@ -325,7 +325,7 @@ void ShowLoginWizard(const std::string& first_screen_name, icu::TimeZone* timezone = icu::TimeZone::createTimeZone( icu::UnicodeString::fromUTF8(timezone_name)); CHECK(timezone) << "Timezone could not be set for " << timezone_name; - chromeos::SystemAccess::GetInstance()->SetTimezone(*timezone); + chromeos::system::TimezoneSettings::GetInstance()->SetTimezone(*timezone); } } } diff --git a/chrome/browser/chromeos/login/helper.cc b/chrome/browser/chromeos/login/helper.cc index 6b17544..afc563a 100644 --- a/chrome/browser/chromeos/login/helper.cc +++ b/chrome/browser/chromeos/login/helper.cc @@ -6,7 +6,6 @@ #include "base/file_util.h" #include "chrome/browser/chromeos/cros/network_library.h" -#include "chrome/browser/chromeos/system_access.h" #include "chrome/browser/google/google_util.h" #include "googleurl/src/gurl.h" #include "grit/generated_resources.h" diff --git a/chrome/browser/chromeos/mock_system_access.cc b/chrome/browser/chromeos/mock_system_access.cc deleted file mode 100644 index fd51c7f..0000000 --- a/chrome/browser/chromeos/mock_system_access.cc +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/chromeos/mock_system_access.h" - -namespace chromeos { - -MockSystemAccess::MockSystemAccess() {} - -MockSystemAccess::~MockSystemAccess() {} - -} // namespace chromeos diff --git a/chrome/browser/chromeos/mock_system_access.h b/chrome/browser/chromeos/mock_system_access.h deleted file mode 100644 index 4d30e86..0000000 --- a/chrome/browser/chromeos/mock_system_access.h +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_CHROMEOS_MOCK_SYSTEM_ACCESS_H_ -#define CHROME_BROWSER_CHROMEOS_MOCK_SYSTEM_ACCESS_H_ -#pragma once - -#include "base/basictypes.h" -#include "chrome/browser/chromeos/system_access.h" -#include "testing/gmock/include/gmock/gmock.h" - -namespace chromeos { - -class MockSystemAccess : public SystemAccess { - public: - MockSystemAccess(); - virtual ~MockSystemAccess(); - - MOCK_METHOD0(GetTimezone, const icu::TimeZone&()); - MOCK_METHOD1(SetTimezone, void(const icu::TimeZone& timezone)); - MOCK_METHOD2(GetMachineStatistic, bool(const std::string& name, - std::string* result)); - MOCK_METHOD1(AddObserver, void(Observer* observer)); - MOCK_METHOD1(RemoveObserver, void(Observer* observer)); - MOCK_METHOD4(RequestSyslogs, Handle(bool compress_logs, - SyslogsContext context, - CancelableRequestConsumerBase* consumer, - ReadCompleteCallback* callback)); - - private: - DISALLOW_COPY_AND_ASSIGN(MockSystemAccess); -}; - -} // namespace chromeos - -#endif // CHROME_BROWSER_CHROMEOS_MOCK_SYSTEM_ACCESS_H_ diff --git a/chrome/browser/chromeos/name_value_pairs_parser.cc b/chrome/browser/chromeos/name_value_pairs_parser.cc deleted file mode 100644 index be38daf..0000000 --- a/chrome/browser/chromeos/name_value_pairs_parser.cc +++ /dev/null @@ -1,103 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/chromeos/name_value_pairs_parser.h" - -#include "base/command_line.h" -#include "base/logging.h" -#include "base/process_util.h" -#include "base/string_tokenizer.h" -#include "base/string_util.h" -#include "base/threading/thread_restrictions.h" - -namespace chromeos { // NOLINT - -namespace { - -const char kQuoteChars[] = "\""; - -} // namespace - -NameValuePairsParser::NameValuePairsParser(NameValueMap* map) - : map_(map) { -} - -void NameValuePairsParser::AddNameValuePair(const std::string& key, - const std::string& value) { - (*map_)[key] = value; - VLOG(1) << "name: " << key << ", value: " << value; -} - -bool NameValuePairsParser::ParseNameValuePairs(const std::string& in_string, - const std::string& eq, - const std::string& delim) { - // Set up the pair tokenizer. - StringTokenizer pair_toks(in_string, delim); - pair_toks.set_quote_chars(kQuoteChars); - // Process token pairs. - while (pair_toks.GetNext()) { - std::string pair(pair_toks.token()); - if (pair.find(eq) == 0) { - LOG(WARNING) << "Empty key: '" << pair << "'. Aborting."; - return false; - } - StringTokenizer keyvalue(pair, eq); - std::string key,value; - if (keyvalue.GetNext()) { - TrimString(keyvalue.token(), kQuoteChars, &key); - if (keyvalue.GetNext()) { - TrimString(keyvalue.token(), kQuoteChars, &value); - if (keyvalue.GetNext()) { - LOG(WARNING) << "Multiple key tokens: '" << pair << "'. Aborting."; - return false; - } - } - } - if (key.empty()) { - LOG(WARNING) << "Invalid token pair: '" << pair << "'. Aborting."; - return false; - } - AddNameValuePair(key, value); - } - return true; -} - -bool NameValuePairsParser::GetSingleValueFromTool(int argc, - const char* argv[], - const std::string& key) { - CommandLine command_line(argc, argv); - std::string output_string; - // TODO(stevenjb,satorux): Make this non blocking: crosbug.com/5603. - base::ThreadRestrictions::ScopedAllowIO allow_io_for_thread_join; - if (argc < 1 || !base::GetAppOutput(command_line, &output_string)) { - LOG(WARNING) << "Error excuting: " << command_line.command_line_string(); - return false; - } - TrimWhitespaceASCII(output_string, TRIM_ALL, &output_string); - AddNameValuePair(key, output_string); - return true; -} - -bool NameValuePairsParser::ParseNameValuePairsFromTool( - int argc, - const char* argv[], - const std::string& eq, - const std::string& delim) { - CommandLine command_line(argc, argv); - std::string output_string; - // TODO(stevenjb,satorux): Make this non blocking: crosbug.com/5603. - base::ThreadRestrictions::ScopedAllowIO allow_io_for_thread_join; - if (argc < 1 || !base::GetAppOutput(command_line, &output_string)) { - LOG(WARNING) << "Error excuting: " << command_line.command_line_string(); - return false; - } - if (!ParseNameValuePairs(output_string, eq, delim)) { - LOG(WARNING) << "Error parsing values while excuting: " - << command_line.command_line_string(); - return false; - } - return true; -} - -} // namespace chromeos diff --git a/chrome/browser/chromeos/name_value_pairs_parser.h b/chrome/browser/chromeos/name_value_pairs_parser.h deleted file mode 100644 index ae8823b..0000000 --- a/chrome/browser/chromeos/name_value_pairs_parser.h +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_CHROMEOS_NAME_VALUE_PAIRS_PARSER_H_ -#define CHROME_BROWSER_CHROMEOS_NAME_VALUE_PAIRS_PARSER_H_ -#pragma once - -#include -#include -#include - -#include "base/basictypes.h" - -namespace chromeos { - -// The parser is used to get machine info as name-value pairs. Defined -// here to be accessable by tests. -class NameValuePairsParser { - public: - typedef std::map NameValueMap; - - // The obtained info will be written into machine_info. - explicit NameValuePairsParser(NameValueMap* map); - - void AddNameValuePair(const std::string& key, const std::string& value); - - // Executes tool and inserts (key, ) into map_. - bool GetSingleValueFromTool(int argc, const char* argv[], - const std::string& key); - // Executes tool, parses the output using ParseNameValuePairs, - // and inserts the results into name_value_pairs_. - bool ParseNameValuePairsFromTool(int argc, const char* argv[], - const std::string& eq, - const std::string& delim); - - private: - // This will parse strings with output in the format: - // [][...] - // e.g. ParseNameValuePairs("key1=value1 key2=value2", "=", " ") - bool ParseNameValuePairs(const std::string& in_string, - const std::string& eq, - const std::string& delim); - - NameValueMap* map_; - - DISALLOW_COPY_AND_ASSIGN(NameValuePairsParser); -}; - -} // namespace chromeos - -#endif // CHROME_BROWSER_CHROMEOS_NAME_VALUE_PAIRS_PARSER_H_ diff --git a/chrome/browser/chromeos/name_value_pairs_parser_unittest.cc b/chrome/browser/chromeos/name_value_pairs_parser_unittest.cc deleted file mode 100644 index 0973920..0000000 --- a/chrome/browser/chromeos/name_value_pairs_parser_unittest.cc +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/chromeos/name_value_pairs_parser.h" - -#include "base/basictypes.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace chromeos { - -TEST(NameValuePairsParser, TestGetSingleValueFromTool) { - NameValuePairsParser::NameValueMap map; - NameValuePairsParser parser(&map); - const char* command[] = { "echo", "Foo" }; - EXPECT_TRUE(parser.GetSingleValueFromTool(arraysize(command), command, - "foo")); - ASSERT_EQ(1U, map.size()); - EXPECT_EQ("Foo", map["foo"]); -} - -TEST(NameValuePairsParser, TestParseNameValuePairsFromTool) { - NameValuePairsParser::NameValueMap map; - NameValuePairsParser parser(&map); - const char* command1[] = { "echo", "foo=Foo bar=Bar\nfoobar=FooBar\n" }; - EXPECT_TRUE(parser.ParseNameValuePairsFromTool( - arraysize(command1), command1, "=", " \n")); - ASSERT_EQ(3U, map.size()); - EXPECT_EQ("Foo", map["foo"]); - EXPECT_EQ("Bar", map["bar"]); - EXPECT_EQ("FooBar", map["foobar"]); - - map.clear(); - const char* command2[] = { "echo", "foo=Foo,bar=Bar" }; - EXPECT_TRUE(parser.ParseNameValuePairsFromTool( - arraysize(command2), command2, "=", ",\n")); - ASSERT_EQ(2U, map.size()); - EXPECT_EQ("Foo", map["foo"]); - EXPECT_EQ("Bar", map["bar"]); - - map.clear(); - const char* command3[] = { "echo", "foo=Foo=foo,bar=Bar" }; - EXPECT_FALSE(parser.ParseNameValuePairsFromTool( - arraysize(command3), command3, "=", ",\n")); - - map.clear(); - const char* command4[] = { "echo", "foo=Foo,=Bar" }; - EXPECT_FALSE(parser.ParseNameValuePairsFromTool( - arraysize(command4), command4, "=", ",\n")); - - map.clear(); - const char* command5[] = { "echo", - "\"initial_locale\"=\"ja\"\n" - "\"initial_timezone\"=\"Asia/Tokyo\"\n" - "\"keyboard_layout\"=\"mozc-jp\"\n" }; - EXPECT_TRUE(parser.ParseNameValuePairsFromTool( - arraysize(command5), command5, "=", "\n")); - ASSERT_EQ(3U, map.size()); - EXPECT_EQ("ja", map["initial_locale"]); - EXPECT_EQ("Asia/Tokyo", map["initial_timezone"]); - EXPECT_EQ("mozc-jp", map["keyboard_layout"]); -} - -} // namespace chromeos diff --git a/chrome/browser/chromeos/status/clock_menu_button.cc b/chrome/browser/chromeos/status/clock_menu_button.cc index a183792..5880b0b 100644 --- a/chrome/browser/chromeos/status/clock_menu_button.cc +++ b/chrome/browser/chromeos/status/clock_menu_button.cc @@ -40,8 +40,8 @@ const int kTimerSlopSeconds = 1; ClockMenuButton::ClockMenuButton(StatusAreaHost* host) : StatusAreaButton(host, this) { - // Add as SystemAccess observer. We update the clock if timezone changes. - SystemAccess::GetInstance()->AddObserver(this); + // Add as TimezoneSettings observer. We update the clock if timezone changes. + system::TimezoneSettings::GetInstance()->AddObserver(this); CrosLibrary::Get()->GetPowerLibrary()->AddObserver(this); // Start monitoring the kUse24HourClock preference. if (host->GetProfile()) { // This can be NULL in the login screen. @@ -54,7 +54,7 @@ ClockMenuButton::ClockMenuButton(StatusAreaHost* host) ClockMenuButton::~ClockMenuButton() { CrosLibrary::Get()->GetPowerLibrary()->RemoveObserver(this); - SystemAccess::GetInstance()->RemoveObserver(this); + system::TimezoneSettings::GetInstance()->RemoveObserver(this); } void ClockMenuButton::UpdateTextAndSetNextTimer() { diff --git a/chrome/browser/chromeos/status/clock_menu_button.h b/chrome/browser/chromeos/status/clock_menu_button.h index ebba360..d6fd4ee 100644 --- a/chrome/browser/chromeos/status/clock_menu_button.h +++ b/chrome/browser/chromeos/status/clock_menu_button.h @@ -14,7 +14,7 @@ #include "chrome/browser/prefs/pref_member.h" #include "content/common/notification_observer.h" #include "content/common/notification_type.h" -#include "chrome/browser/chromeos/system_access.h" +#include "chrome/browser/chromeos/system/timezone_settings.h" #include "unicode/calendar.h" #include "views/controls/button/menu_button.h" #include "views/controls/menu/menu_delegate.h" @@ -35,7 +35,7 @@ class ClockMenuButton : public StatusAreaButton, public views::ViewMenuDelegate, public NotificationObserver, public PowerLibrary::Observer, - public SystemAccess::Observer { + public system::TimezoneSettings::Observer { public: explicit ClockMenuButton(StatusAreaHost* host); virtual ~ClockMenuButton(); @@ -49,7 +49,7 @@ class ClockMenuButton : public StatusAreaButton, virtual void PowerChanged(PowerLibrary* obj) {} virtual void SystemResumed(); - // Overridden from SystemAccess::Observer: + // Overridden from TimezoneSettings::Observer: virtual void TimezoneChanged(const icu::TimeZone& timezone); // views::View diff --git a/chrome/browser/chromeos/status/clock_menu_button_browsertest.cc b/chrome/browser/chromeos/status/clock_menu_button_browsertest.cc index d913c63..67c77c4 100644 --- a/chrome/browser/chromeos/status/clock_menu_button_browsertest.cc +++ b/chrome/browser/chromeos/status/clock_menu_button_browsertest.cc @@ -8,7 +8,7 @@ #include "chrome/browser/chromeos/cros/cros_library.h" #include "chrome/browser/chromeos/frame/browser_view.h" #include "chrome/browser/chromeos/status/status_area_view.h" -#include "chrome/browser/chromeos/system_access.h" +#include "chrome/browser/chromeos/system/timezone_settings.h" #include "chrome/browser/chromeos/view_ids.h" #include "chrome/browser/prefs/pref_member.h" #include "chrome/browser/ui/browser.h" @@ -42,11 +42,11 @@ IN_PROC_BROWSER_TEST_F(ClockMenuButtonTest, TimezoneTest) { // Update timezone and make sure clock text changes. scoped_ptr timezone_first(icu::TimeZone::createTimeZone( icu::UnicodeString::fromUTF8("Asia/Hong_Kong"))); - SystemAccess::GetInstance()->SetTimezone(*timezone_first); + system::TimezoneSettings::GetInstance()->SetTimezone(*timezone_first); std::wstring text_before = clock->text(); scoped_ptr timezone_second(icu::TimeZone::createTimeZone( icu::UnicodeString::fromUTF8("Pacific/Samoa"))); - SystemAccess::GetInstance()->SetTimezone(*timezone_second); + system::TimezoneSettings::GetInstance()->SetTimezone(*timezone_second); std::wstring text_after = clock->text(); EXPECT_NE(text_before, text_after); } diff --git a/chrome/browser/chromeos/system/mock_statistics_provider.cc b/chrome/browser/chromeos/system/mock_statistics_provider.cc new file mode 100644 index 0000000..26c2d22 --- /dev/null +++ b/chrome/browser/chromeos/system/mock_statistics_provider.cc @@ -0,0 +1,15 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/chromeos/system/mock_statistics_provider.h" + +namespace chromeos { +namespace system { + +MockStatisticsProvider::MockStatisticsProvider() {} + +MockStatisticsProvider::~MockStatisticsProvider() {} + +} // namespace system +} // namespace chromeos diff --git a/chrome/browser/chromeos/system/mock_statistics_provider.h b/chrome/browser/chromeos/system/mock_statistics_provider.h new file mode 100644 index 0000000..e0acd0a --- /dev/null +++ b/chrome/browser/chromeos/system/mock_statistics_provider.h @@ -0,0 +1,31 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_CHROMEOS_SYSTEM_MOCK_STATISTICS_PROVIDER_H_ +#define CHROME_BROWSER_CHROMEOS_SYSTEM_MOCK_STATISTICS_PROVIDER_H_ +#pragma once + +#include "base/basictypes.h" +#include "chrome/browser/chromeos/system/statistics_provider.h" +#include "testing/gmock/include/gmock/gmock.h" + +namespace chromeos { +namespace system { + +class MockStatisticsProvider : public system::StatisticsProvider { + public: + MockStatisticsProvider(); + virtual ~MockStatisticsProvider(); + + MOCK_METHOD2(GetMachineStatistic, bool(const std::string& name, + std::string* result)); + + private: + DISALLOW_COPY_AND_ASSIGN(MockStatisticsProvider); +}; + +} // namespace system +} // namespace chromeos + +#endif // CHROME_BROWSER_CHROMEOS_SYSTEM_MOCK_STATISTICS_PROVIDER_H_ diff --git a/chrome/browser/chromeos/system/name_value_pairs_parser.cc b/chrome/browser/chromeos/system/name_value_pairs_parser.cc new file mode 100644 index 0000000..700ebac --- /dev/null +++ b/chrome/browser/chromeos/system/name_value_pairs_parser.cc @@ -0,0 +1,105 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/chromeos/system/name_value_pairs_parser.h" + +#include "base/command_line.h" +#include "base/logging.h" +#include "base/process_util.h" +#include "base/string_tokenizer.h" +#include "base/string_util.h" +#include "base/threading/thread_restrictions.h" + +namespace chromeos { // NOLINT +namespace system { + +namespace { + +const char kQuoteChars[] = "\""; + +} // namespace + +NameValuePairsParser::NameValuePairsParser(NameValueMap* map) + : map_(map) { +} + +void NameValuePairsParser::AddNameValuePair(const std::string& key, + const std::string& value) { + (*map_)[key] = value; + VLOG(1) << "name: " << key << ", value: " << value; +} + +bool NameValuePairsParser::ParseNameValuePairs(const std::string& in_string, + const std::string& eq, + const std::string& delim) { + // Set up the pair tokenizer. + StringTokenizer pair_toks(in_string, delim); + pair_toks.set_quote_chars(kQuoteChars); + // Process token pairs. + while (pair_toks.GetNext()) { + std::string pair(pair_toks.token()); + if (pair.find(eq) == 0) { + LOG(WARNING) << "Empty key: '" << pair << "'. Aborting."; + return false; + } + StringTokenizer keyvalue(pair, eq); + std::string key,value; + if (keyvalue.GetNext()) { + TrimString(keyvalue.token(), kQuoteChars, &key); + if (keyvalue.GetNext()) { + TrimString(keyvalue.token(), kQuoteChars, &value); + if (keyvalue.GetNext()) { + LOG(WARNING) << "Multiple key tokens: '" << pair << "'. Aborting."; + return false; + } + } + } + if (key.empty()) { + LOG(WARNING) << "Invalid token pair: '" << pair << "'. Aborting."; + return false; + } + AddNameValuePair(key, value); + } + return true; +} + +bool NameValuePairsParser::GetSingleValueFromTool(int argc, + const char* argv[], + const std::string& key) { + CommandLine command_line(argc, argv); + std::string output_string; + // TODO(stevenjb,satorux): Make this non blocking: crosbug.com/5603. + base::ThreadRestrictions::ScopedAllowIO allow_io_for_thread_join; + if (argc < 1 || !base::GetAppOutput(command_line, &output_string)) { + LOG(WARNING) << "Error excuting: " << command_line.command_line_string(); + return false; + } + TrimWhitespaceASCII(output_string, TRIM_ALL, &output_string); + AddNameValuePair(key, output_string); + return true; +} + +bool NameValuePairsParser::ParseNameValuePairsFromTool( + int argc, + const char* argv[], + const std::string& eq, + const std::string& delim) { + CommandLine command_line(argc, argv); + std::string output_string; + // TODO(stevenjb,satorux): Make this non blocking: crosbug.com/5603. + base::ThreadRestrictions::ScopedAllowIO allow_io_for_thread_join; + if (argc < 1 || !base::GetAppOutput(command_line, &output_string)) { + LOG(WARNING) << "Error excuting: " << command_line.command_line_string(); + return false; + } + if (!ParseNameValuePairs(output_string, eq, delim)) { + LOG(WARNING) << "Error parsing values while excuting: " + << command_line.command_line_string(); + return false; + } + return true; +} + +} // namespace system +} // namespace chromeos diff --git a/chrome/browser/chromeos/system/name_value_pairs_parser.h b/chrome/browser/chromeos/system/name_value_pairs_parser.h new file mode 100644 index 0000000..bbaf97a --- /dev/null +++ b/chrome/browser/chromeos/system/name_value_pairs_parser.h @@ -0,0 +1,54 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_CHROMEOS_SYSTEM_NAME_VALUE_PAIRS_PARSER_H_ +#define CHROME_BROWSER_CHROMEOS_SYSTEM_NAME_VALUE_PAIRS_PARSER_H_ +#pragma once + +#include +#include +#include + +#include "base/basictypes.h" + +namespace chromeos { +namespace system { + +// The parser is used to get machine info as name-value pairs. Defined +// here to be accessable by tests. +class NameValuePairsParser { + public: + typedef std::map NameValueMap; + + // The obtained info will be written into machine_info. + explicit NameValuePairsParser(NameValueMap* map); + + void AddNameValuePair(const std::string& key, const std::string& value); + + // Executes tool and inserts (key, ) into map_. + bool GetSingleValueFromTool(int argc, const char* argv[], + const std::string& key); + // Executes tool, parses the output using ParseNameValuePairs, + // and inserts the results into name_value_pairs_. + bool ParseNameValuePairsFromTool(int argc, const char* argv[], + const std::string& eq, + const std::string& delim); + + private: + // This will parse strings with output in the format: + // [][...] + // e.g. ParseNameValuePairs("key1=value1 key2=value2", "=", " ") + bool ParseNameValuePairs(const std::string& in_string, + const std::string& eq, + const std::string& delim); + + NameValueMap* map_; + + DISALLOW_COPY_AND_ASSIGN(NameValuePairsParser); +}; + +} // namespace system +} // namespace chromeos + +#endif // CHROME_BROWSER_CHROMEOS_SYSTEM_NAME_VALUE_PAIRS_PARSER_H_ diff --git a/chrome/browser/chromeos/system/name_value_pairs_parser_unittest.cc b/chrome/browser/chromeos/system/name_value_pairs_parser_unittest.cc new file mode 100644 index 0000000..65918d0 --- /dev/null +++ b/chrome/browser/chromeos/system/name_value_pairs_parser_unittest.cc @@ -0,0 +1,66 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/chromeos/system/name_value_pairs_parser.h" + +#include "base/basictypes.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace chromeos { +namespace system { + +TEST(NameValuePairsParser, TestGetSingleValueFromTool) { + NameValuePairsParser::NameValueMap map; + NameValuePairsParser parser(&map); + const char* command[] = { "echo", "Foo" }; + EXPECT_TRUE(parser.GetSingleValueFromTool(arraysize(command), command, + "foo")); + ASSERT_EQ(1U, map.size()); + EXPECT_EQ("Foo", map["foo"]); +} + +TEST(NameValuePairsParser, TestParseNameValuePairsFromTool) { + NameValuePairsParser::NameValueMap map; + NameValuePairsParser parser(&map); + const char* command1[] = { "echo", "foo=Foo bar=Bar\nfoobar=FooBar\n" }; + EXPECT_TRUE(parser.ParseNameValuePairsFromTool( + arraysize(command1), command1, "=", " \n")); + ASSERT_EQ(3U, map.size()); + EXPECT_EQ("Foo", map["foo"]); + EXPECT_EQ("Bar", map["bar"]); + EXPECT_EQ("FooBar", map["foobar"]); + + map.clear(); + const char* command2[] = { "echo", "foo=Foo,bar=Bar" }; + EXPECT_TRUE(parser.ParseNameValuePairsFromTool( + arraysize(command2), command2, "=", ",\n")); + ASSERT_EQ(2U, map.size()); + EXPECT_EQ("Foo", map["foo"]); + EXPECT_EQ("Bar", map["bar"]); + + map.clear(); + const char* command3[] = { "echo", "foo=Foo=foo,bar=Bar" }; + EXPECT_FALSE(parser.ParseNameValuePairsFromTool( + arraysize(command3), command3, "=", ",\n")); + + map.clear(); + const char* command4[] = { "echo", "foo=Foo,=Bar" }; + EXPECT_FALSE(parser.ParseNameValuePairsFromTool( + arraysize(command4), command4, "=", ",\n")); + + map.clear(); + const char* command5[] = { "echo", + "\"initial_locale\"=\"ja\"\n" + "\"initial_timezone\"=\"Asia/Tokyo\"\n" + "\"keyboard_layout\"=\"mozc-jp\"\n" }; + EXPECT_TRUE(parser.ParseNameValuePairsFromTool( + arraysize(command5), command5, "=", "\n")); + ASSERT_EQ(3U, map.size()); + EXPECT_EQ("ja", map["initial_locale"]); + EXPECT_EQ("Asia/Tokyo", map["initial_timezone"]); + EXPECT_EQ("mozc-jp", map["keyboard_layout"]); +} + +} // namespace system +} // namespace chromeos diff --git a/chrome/browser/chromeos/system/statistics_provider.cc b/chrome/browser/chromeos/system/statistics_provider.cc new file mode 100644 index 0000000..4a85699 --- /dev/null +++ b/chrome/browser/chromeos/system/statistics_provider.cc @@ -0,0 +1,108 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/chromeos/system/statistics_provider.h" + +#include "base/memory/singleton.h" +#include "base/task.h" +#include "chrome/browser/chromeos/system/name_value_pairs_parser.h" + +namespace chromeos { +namespace system { +namespace { + +// The system command that returns the hardware class. +const char kHardwareClassKey[] = "hardware_class"; +const char* kHardwareClassTool[] = { "crossystem", "hwid" }; +const char kUnknownHardwareClass[] = "unknown"; + +// Command to get machine hardware info and key/value delimiters. +// /tmp/machine-info is generated by platform/init/chromeos_startup. +const char* kMachineHardwareInfoTool[] = { "cat", "/tmp/machine-info" }; +const char kMachineHardwareInfoEq[] = "="; +const char kMachineHardwareInfoDelim[] = " \n"; + +// Command to get machine OS info and key/value delimiters. +const char* kMachineOSInfoTool[] = { "cat", "/etc/lsb-release" }; +const char kMachineOSInfoEq[] = "="; +const char kMachineOSInfoDelim[] = "\n"; + +// Command to get VPD info and key/value delimiters. +const char* kVpdTool[] = { "cat", "/var/log/vpd_2.0.txt" }; +const char kVpdEq[] = "="; +const char kVpdDelim[] = "\n"; + +} // namespace + +class StatisticsProviderImpl : public StatisticsProvider { + public: + // StatisticsProvider implementation: + virtual bool GetMachineStatistic(const std::string& name, + std::string* result); + + static StatisticsProviderImpl* GetInstance(); + + private: + friend struct DefaultSingletonTraits; + + StatisticsProviderImpl(); + + // Updates the machine statistcs by examining the system. + void UpdateMachineStatistics(); + + NameValuePairsParser::NameValueMap machine_info_; + + DISALLOW_COPY_AND_ASSIGN(StatisticsProviderImpl); +}; + +bool StatisticsProviderImpl::GetMachineStatistic( + const std::string& name, std::string* result) { + NameValuePairsParser::NameValueMap::iterator iter = machine_info_.find(name); + if (iter != machine_info_.end()) { + *result = iter->second; + return true; + } + return false; +} + +StatisticsProviderImpl::StatisticsProviderImpl() { + // Get Statistics + UpdateMachineStatistics(); +} + +void StatisticsProviderImpl::UpdateMachineStatistics() { + NameValuePairsParser parser(&machine_info_); + if (!parser.GetSingleValueFromTool(arraysize(kHardwareClassTool), + kHardwareClassTool, + kHardwareClassKey)) { + // Use kUnknownHardwareClass if the hardware class command fails. + parser.AddNameValuePair(kHardwareClassKey, kUnknownHardwareClass); + } + parser.ParseNameValuePairsFromTool(arraysize(kMachineHardwareInfoTool), + kMachineHardwareInfoTool, + kMachineHardwareInfoEq, + kMachineHardwareInfoDelim); + parser.ParseNameValuePairsFromTool(arraysize(kMachineOSInfoTool), + kMachineOSInfoTool, + kMachineOSInfoEq, + kMachineOSInfoDelim); + parser.ParseNameValuePairsFromTool( + arraysize(kVpdTool), kVpdTool, kVpdEq, kVpdDelim); +} + +StatisticsProviderImpl* StatisticsProviderImpl::GetInstance() { + return Singleton >::get(); +} + +StatisticsProvider* StatisticsProvider::GetInstance() { + return StatisticsProviderImpl::GetInstance(); +} + +} // namespace system +} // namespace chromeos + +// Allows InvokeLater without adding refcounting. StatisticsProviderImpl is a +// Singleton and won't be deleted until it's last InvokeLater is run. +DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::system::StatisticsProviderImpl); diff --git a/chrome/browser/chromeos/system/statistics_provider.h b/chrome/browser/chromeos/system/statistics_provider.h new file mode 100644 index 0000000..1908087 --- /dev/null +++ b/chrome/browser/chromeos/system/statistics_provider.h @@ -0,0 +1,32 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_CHROMEOS_SYSTEM_STATISTICS_PROVIDER_H_ +#define CHROME_BROWSER_CHROMEOS_SYSTEM_STATISTICS_PROVIDER_H_ +#pragma once + +#include + +namespace chromeos { +namespace system { + +// This interface provides access to Chrome OS statistics. +class StatisticsProvider { + public: + // Retrieve the named machine statistic (e.g. "hardware_class"). + // This does not update the statistcs. If the |name| is not set, |result| + // preserves old value. + virtual bool GetMachineStatistic(const std::string& name, + std::string* result) = 0; + + static StatisticsProvider* GetInstance(); + + protected: + virtual ~StatisticsProvider() {} +}; + +} // namespace system +} // namespace chromeos + +#endif // CHROME_BROWSER_CHROMEOS_SYSTEM_STATISTICS_PROVIDER_H_ diff --git a/chrome/browser/chromeos/system/syslogs_provider.cc b/chrome/browser/chromeos/system/syslogs_provider.cc new file mode 100644 index 0000000..57c76cf --- /dev/null +++ b/chrome/browser/chromeos/system/syslogs_provider.cc @@ -0,0 +1,302 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/chromeos/system/syslogs_provider.h" + +#include "base/command_line.h" +#include "base/file_path.h" +#include "base/file_util.h" +#include "base/logging.h" +#include "base/memory/scoped_ptr.h" +#include "base/memory/singleton.h" +#include "base/string_util.h" +#include "chrome/common/chrome_switches.h" +#include "content/browser/browser_thread.h" + +namespace chromeos { +namespace system { +namespace { + +const char kSysLogsScript[] = + "/usr/share/userfeedback/scripts/sysinfo_script_runner"; +const char kBzip2Command[] = + "/bin/bzip2"; +const char kMultilineQuote[] = "\"\"\""; +const char kNewLineChars[] = "\r\n"; +const char kInvalidLogEntry[] = ""; +const char kEmptyLogEntry[] = ""; + +const char kContextFeedback[] = "feedback"; +const char kContextSysInfo[] = "sysinfo"; +const char kContextNetwork[] = "network"; + +// Reads a key from the input string erasing the read values + delimiters read +// from the initial string +std::string ReadKey(std::string* data) { + size_t equal_sign = data->find("="); + if (equal_sign == std::string::npos) + return std::string(""); + std::string key = data->substr(0, equal_sign); + data->erase(0, equal_sign); + if (data->size() > 0) { + // erase the equal to sign also + data->erase(0,1); + return key; + } + return std::string(); +} + +// Reads a value from the input string; erasing the read values from +// the initial string; detects if the value is multiline and reads +// accordingly +std::string ReadValue(std::string* data) { + // Trim the leading spaces and tabs. In order to use a multi-line + // value, you have to place the multi-line quote on the same line as + // the equal sign. + // + // Why not use TrimWhitespace? Consider the following input: + // + // KEY1= + // KEY2=VALUE + // + // If we use TrimWhitespace, we will incorrectly trim the new line + // and assume that KEY1's value is "KEY2=VALUE" rather than empty. + TrimString(*data, " \t", data); + + // If multiline value + if (StartsWithASCII(*data, std::string(kMultilineQuote), false)) { + data->erase(0, strlen(kMultilineQuote)); + size_t next_multi = data->find(kMultilineQuote); + if (next_multi == std::string::npos) { + // Error condition, clear data to stop further processing + data->erase(); + return std::string(); + } + std::string value = data->substr(0, next_multi); + data->erase(0, next_multi + 3); + return value; + } else { // single line value + size_t endl_pos = data->find_first_of(kNewLineChars); + // if we don't find a new line, we just return the rest of the data + std::string value = data->substr(0, endl_pos); + data->erase(0, endl_pos); + return value; + } +} + +// Returns a map of system log keys and values. +// +// Parameters: +// temp_filename: This is an out parameter that holds the name of a file in +// Reads a value from the input string; erasing the read values from +// the initial string; detects if the value is multiline and reads +// accordingly +// /tmp that contains the system logs in a KEY=VALUE format. +// If this parameter is NULL, system logs are not retained on +// the filesystem after this call completes. +// context: This is an in parameter specifying what context should be +// passed to the syslog collection script; currently valid +// values are "sysinfo" or "feedback"; in case of an invalid +// value, the script will currently default to "sysinfo" + +LogDictionaryType* GetSystemLogs(FilePath* zip_file_name, + const std::string& context) { + // Create the temp file, logs will go here + FilePath temp_filename; + + if (!file_util::CreateTemporaryFile(&temp_filename)) + return NULL; + + std::string cmd = std::string(kSysLogsScript) + " " + context + " >> " + + temp_filename.value(); + + // Ignore the return value - if the script execution didn't work + // stderr won't go into the output file anyway. + if (::system(cmd.c_str()) == -1) + LOG(WARNING) << "Command " << cmd << " failed to run"; + + // Compress the logs file if requested. + if (zip_file_name) { + cmd = std::string(kBzip2Command) + " -c " + temp_filename.value() + " > " + + zip_file_name->value(); + if (::system(cmd.c_str()) == -1) + LOG(WARNING) << "Command " << cmd << " failed to run"; + } + // Read logs from the temp file + std::string data; + bool read_success = file_util::ReadFileToString(temp_filename, + &data); + // if we were using an internal temp file, the user does not need the + // logs to stay past the ReadFile call - delete the file + file_util::Delete(temp_filename, false); + + if (!read_success) + return NULL; + + // Parse the return data into a dictionary + LogDictionaryType* logs = new LogDictionaryType(); + while (data.length() > 0) { + std::string key = ReadKey(&data); + TrimWhitespaceASCII(key, TRIM_ALL, &key); + if (!key.empty()) { + std::string value = ReadValue(&data); + if (IsStringUTF8(value)) { + TrimWhitespaceASCII(value, TRIM_ALL, &value); + if (value.empty()) + (*logs)[key] = kEmptyLogEntry; + else + (*logs)[key] = value; + } else { + LOG(WARNING) << "Invalid characters in system log entry: " << key; + (*logs)[key] = kInvalidLogEntry; + } + } else { + // no more keys, we're done + break; + } + } + + return logs; +} + +} // namespace + +class SyslogsProviderImpl : public SyslogsProvider { + public: + // SyslogsProvider implementation: + virtual Handle RequestSyslogs( + bool compress_logs, + SyslogsContext context, + CancelableRequestConsumerBase* consumer, + ReadCompleteCallback* callback); + + // Reads system logs, compresses content if requested. + // Called from FILE thread. + void ReadSyslogs( + scoped_refptr > request, + bool compress_logs, + SyslogsContext context); + + // Loads compressed logs and writes into |zip_content|. + void LoadCompressedLogs(const FilePath& zip_file, + std::string* zip_content); + + static SyslogsProviderImpl* GetInstance(); + + private: + friend struct DefaultSingletonTraits; + + SyslogsProviderImpl(); + + // Gets syslogs context string from the enum value. + const char* GetSyslogsContextString(SyslogsContext context); + + DISALLOW_COPY_AND_ASSIGN(SyslogsProviderImpl); +}; + +SyslogsProviderImpl::SyslogsProviderImpl() { +} + +CancelableRequestProvider::Handle SyslogsProviderImpl::RequestSyslogs( + bool compress_logs, + SyslogsContext context, + CancelableRequestConsumerBase* consumer, + ReadCompleteCallback* callback) { + // Register the callback request. + scoped_refptr > request( + new CancelableRequest(callback)); + AddRequest(request, consumer); + + // Schedule a task on the FILE thread which will then trigger a request + // callback on the calling thread (e.g. UI) when complete. + BrowserThread::PostTask( + BrowserThread::FILE, FROM_HERE, + NewRunnableMethod( + this, &SyslogsProviderImpl::ReadSyslogs, request, + compress_logs, context)); + + return request->handle(); +} + +// Called from FILE thread. +void SyslogsProviderImpl::ReadSyslogs( + scoped_refptr > request, + bool compress_logs, + SyslogsContext context) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); + + if (request->canceled()) + return; + + if (compress_logs && !CommandLine::ForCurrentProcess()->HasSwitch( + switches::kCompressSystemFeedback)) + compress_logs = false; + + // Create temp file. + FilePath zip_file; + if (compress_logs && !file_util::CreateTemporaryFile(&zip_file)) { + LOG(ERROR) << "Cannot create temp file"; + compress_logs = false; + } + + LogDictionaryType* logs = NULL; + logs = GetSystemLogs( + compress_logs ? &zip_file : NULL, + GetSyslogsContextString(context)); + + std::string* zip_content = NULL; + if (compress_logs) { + // Load compressed logs. + zip_content = new std::string(); + LoadCompressedLogs(zip_file, zip_content); + file_util::Delete(zip_file, false); + } + + // Will call the callback on the calling thread. + request->ForwardResult(Tuple2(logs, zip_content)); +} + + +void SyslogsProviderImpl::LoadCompressedLogs(const FilePath& zip_file, + std::string* zip_content) { + DCHECK(zip_content); + if (!file_util::ReadFileToString(zip_file, zip_content)) { + LOG(ERROR) << "Cannot read compressed logs file from " << + zip_file.value().c_str(); + } +} + +const char* SyslogsProviderImpl::GetSyslogsContextString( + SyslogsContext context) { + switch (context) { + case(SYSLOGS_FEEDBACK): + return kContextFeedback; + case(SYSLOGS_SYSINFO): + return kContextSysInfo; + case(SYSLOGS_NETWORK): + return kContextNetwork; + case(SYSLOGS_DEFAULT): + return kContextSysInfo; + default: + NOTREACHED(); + return ""; + } +} + +SyslogsProviderImpl* SyslogsProviderImpl::GetInstance() { + return Singleton >::get(); +} + +SyslogsProvider* SyslogsProvider::GetInstance() { + return SyslogsProviderImpl::GetInstance(); +} + +} // namespace system +} // namespace chromeos + +// Allows InvokeLater without adding refcounting. SyslogsProviderImpl is a +// Singleton and won't be deleted until it's last InvokeLater is run. +DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::system::SyslogsProviderImpl); diff --git a/chrome/browser/chromeos/system/syslogs_provider.h b/chrome/browser/chromeos/system/syslogs_provider.h new file mode 100644 index 0000000..ecb92b6 --- /dev/null +++ b/chrome/browser/chromeos/system/syslogs_provider.h @@ -0,0 +1,56 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_CHROMEOS_SYSTEM_SYSLOGS_PROVIDER_H_ +#define CHROME_BROWSER_CHROMEOS_SYSTEM_SYSLOGS_PROVIDER_H_ +#pragma once + +#include + +#include "base/callback_old.h" +#include "content/browser/cancelable_request.h" + +class CancelableRequestConsumerBase; + +namespace chromeos { +namespace system { + +typedef std::map LogDictionaryType; + +// This interface provides access to Chrome OS syslogs. +class SyslogsProvider : public CancelableRequestProvider { + public: + static SyslogsProvider* GetInstance(); + + // The callback type used with RequestSyslogs(). + typedef Callback2::Type ReadCompleteCallback; + + // Used to specify the syslogs context with RequestSyslogs(). + enum SyslogsContext { + SYSLOGS_FEEDBACK, + SYSLOGS_SYSINFO, + SYSLOGS_NETWORK, + SYSLOGS_DEFAULT + }; + + // Request system logs. Read happens on the FILE thread and callback is + // called on the thread this is called from (via ForwardResult). + // Logs are owned by callback function (use delete when done with them). + // Returns the request handle. Call CancelRequest(Handle) to cancel + // the request before the callback gets called. + virtual Handle RequestSyslogs( + bool compress_logs, + SyslogsContext context, + CancelableRequestConsumerBase* consumer, + ReadCompleteCallback* callback) = 0; + + protected: + virtual ~SyslogsProvider() {} +}; + +} // namespace system +} // namespace chromeos + +#endif // CHROME_BROWSER_CHROMEOS_SYSTEM_SYSLOGS_PROVIDER_H_ diff --git a/chrome/browser/chromeos/system/timezone_settings.cc b/chrome/browser/chromeos/system/timezone_settings.cc new file mode 100644 index 0000000..03703a9 --- /dev/null +++ b/chrome/browser/chromeos/system/timezone_settings.cc @@ -0,0 +1,164 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/chromeos/system/timezone_settings.h" + +#include "base/file_path.h" +#include "base/file_util.h" +#include "base/logging.h" +#include "base/observer_list.h" +#include "base/memory/scoped_ptr.h" +#include "base/memory/singleton.h" +#include "base/string_util.h" +#include "base/utf_string_conversions.h" + +namespace chromeos { +namespace system { + +namespace { + +// The filepath to the timezone file that symlinks to the actual timezone file. +const char kTimezoneSymlink[] = "/var/lib/timezone/localtime"; +const char kTimezoneSymlink2[] = "/var/lib/timezone/localtime2"; + +// The directory that contains all the timezone files. So for timezone +// "US/Pacific", the actual timezone file is: "/usr/share/zoneinfo/US/Pacific" +const char kTimezoneFilesDir[] = "/usr/share/zoneinfo/"; + +// Fallback time zone ID used in case of an unexpected error. +const char kFallbackTimeZoneId[] = "America/Los_Angeles"; + +} // namespace + +class TimezoneSettingsImpl : public TimezoneSettings { + public: + // TimezoneSettings.implementation: + virtual const icu::TimeZone& GetTimezone(); + virtual void SetTimezone(const icu::TimeZone& timezone); + virtual void AddObserver(Observer* observer); + virtual void RemoveObserver(Observer* observer); + + static TimezoneSettingsImpl* GetInstance(); + + private: + friend struct DefaultSingletonTraits; + + TimezoneSettingsImpl(); + + scoped_ptr timezone_; + ObserverList observers_; + + DISALLOW_COPY_AND_ASSIGN(TimezoneSettingsImpl); +}; + +std::string GetTimezoneIDAsString() { + // Look at kTimezoneSymlink, see which timezone we are symlinked to. + char buf[256]; + const ssize_t len = readlink(kTimezoneSymlink, buf, + sizeof(buf)-1); + if (len == -1) { + LOG(ERROR) << "GetTimezoneID: Cannot read timezone symlink " + << kTimezoneSymlink; + return std::string(); + } + + std::string timezone(buf, len); + // Remove kTimezoneFilesDir from the beginning. + if (timezone.find(kTimezoneFilesDir) != 0) { + LOG(ERROR) << "GetTimezoneID: Timezone symlink is wrong " + << timezone; + return std::string(); + } + + return timezone.substr(strlen(kTimezoneFilesDir)); +} + +void SetTimezoneIDFromString(const std::string& id) { + // Change the kTimezoneSymlink symlink to the path for this timezone. + // We want to do this in an atomic way. So we are going to create the symlink + // at kTimezoneSymlink2 and then move it to kTimezoneSymlink + + FilePath timezone_symlink(kTimezoneSymlink); + FilePath timezone_symlink2(kTimezoneSymlink2); + FilePath timezone_file(kTimezoneFilesDir + id); + + // Make sure timezone_file exists. + if (!file_util::PathExists(timezone_file)) { + LOG(ERROR) << "SetTimezoneID: Cannot find timezone file " + << timezone_file.value(); + return; + } + + // Delete old symlink2 if it exists. + file_util::Delete(timezone_symlink2, false); + + // Create new symlink2. + if (symlink(timezone_file.value().c_str(), + timezone_symlink2.value().c_str()) == -1) { + LOG(ERROR) << "SetTimezoneID: Unable to create symlink " + << timezone_symlink2.value() << " to " << timezone_file.value(); + return; + } + + // Move symlink2 to symlink. + if (!file_util::ReplaceFile(timezone_symlink2, timezone_symlink)) { + LOG(ERROR) << "SetTimezoneID: Unable to move symlink " + << timezone_symlink2.value() << " to " + << timezone_symlink.value(); + } +} + +const icu::TimeZone& TimezoneSettingsImpl::GetTimezone() { + return *timezone_.get(); +} + +void TimezoneSettingsImpl::SetTimezone(const icu::TimeZone& timezone) { + timezone_.reset(timezone.clone()); + icu::UnicodeString unicode; + timezone.getID(unicode); + std::string id; + UTF16ToUTF8(unicode.getBuffer(), unicode.length(), &id); + VLOG(1) << "Setting timezone to " << id; + SetTimezoneIDFromString(id); + icu::TimeZone::setDefault(timezone); + FOR_EACH_OBSERVER(Observer, observers_, TimezoneChanged(timezone)); +} + +void TimezoneSettingsImpl::AddObserver(Observer* observer) { + observers_.AddObserver(observer); +} + +void TimezoneSettingsImpl::RemoveObserver(Observer* observer) { + observers_.RemoveObserver(observer); +} + +TimezoneSettingsImpl::TimezoneSettingsImpl() { + // Get Timezone + std::string id = GetTimezoneIDAsString(); + if (id.empty()) { + id = kFallbackTimeZoneId; + LOG(ERROR) << "Got an empty string for timezone, default to " << id; + } + icu::TimeZone* timezone = + icu::TimeZone::createTimeZone(icu::UnicodeString::fromUTF8(id)); + timezone_.reset(timezone); + icu::TimeZone::setDefault(*timezone); + VLOG(1) << "Timezone is " << id; +} + +TimezoneSettingsImpl* TimezoneSettingsImpl::GetInstance() { + return Singleton >::get(); +} + +TimezoneSettings* TimezoneSettings::GetInstance() { + return TimezoneSettingsImpl::GetInstance(); +} + +} // namespace system +} // namespace chromeos + +// Allows InvokeLater without adding refcounting. TimezoneSettingsImpl is a +// Singleton and won't be deleted until it's last InvokeLater is run. +DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::system::TimezoneSettingsImpl); diff --git a/chrome/browser/chromeos/system/timezone_settings.h b/chrome/browser/chromeos/system/timezone_settings.h new file mode 100644 index 0000000..06c4626 --- /dev/null +++ b/chrome/browser/chromeos/system/timezone_settings.h @@ -0,0 +1,45 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_CHROMEOS_SYSTEM_TIMEZONE_SETTINGS_H_ +#define CHROME_BROWSER_CHROMEOS_SYSTEM_TIMEZONE_SETTINGS_H_ +#pragma once + +#include + +#include "base/callback_old.h" +#include "content/browser/cancelable_request.h" +#include "unicode/timezone.h" + +namespace chromeos { +namespace system { + +// This interface provides access to Chrome OS timezone settings. +class TimezoneSettings : public CancelableRequestProvider { + public: + class Observer { + public: + // Called when the timezone has changed. |timezone| is non-null. + virtual void TimezoneChanged(const icu::TimeZone& timezone) = 0; + }; + + static TimezoneSettings* GetInstance(); + + // Returns the current timezone as an icu::Timezone object. + virtual const icu::TimeZone& GetTimezone() = 0; + + // Sets the current timezone. |timezone| must be non-null. + virtual void SetTimezone(const icu::TimeZone& timezone) = 0; + + virtual void AddObserver(Observer* observer) = 0; + virtual void RemoveObserver(Observer* observer) = 0; + + protected: + virtual ~TimezoneSettings() {} +}; + +} // namespace system +} // namespace chromeos + +#endif // CHROME_BROWSER_CHROMEOS_SYSTEM_TIMEZONE_SETTINGS_H_ diff --git a/chrome/browser/chromeos/system_access.cc b/chrome/browser/chromeos/system_access.cc deleted file mode 100644 index 04cada6..0000000 --- a/chrome/browser/chromeos/system_access.cc +++ /dev/null @@ -1,470 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/chromeos/system_access.h" - -#include "base/command_line.h" -#include "base/file_path.h" -#include "base/file_util.h" -#include "base/logging.h" -#include "base/observer_list.h" -#include "base/memory/scoped_ptr.h" -#include "base/memory/singleton.h" -#include "base/string_util.h" -#include "base/utf_string_conversions.h" -#include "chrome/browser/chromeos/name_value_pairs_parser.h" -#include "chrome/common/chrome_switches.h" -#include "content/browser/browser_thread.h" - -namespace chromeos { // NOLINT - -namespace { // NOLINT - -// The filepath to the timezone file that symlinks to the actual timezone file. -const char kTimezoneSymlink[] = "/var/lib/timezone/localtime"; -const char kTimezoneSymlink2[] = "/var/lib/timezone/localtime2"; - -// The directory that contains all the timezone files. So for timezone -// "US/Pacific", the actual timezone file is: "/usr/share/zoneinfo/US/Pacific" -const char kTimezoneFilesDir[] = "/usr/share/zoneinfo/"; - -// The system command that returns the hardware class. -const char kHardwareClassKey[] = "hardware_class"; -const char* kHardwareClassTool[] = { "crossystem", "hwid" }; -const char kUnknownHardwareClass[] = "unknown"; - -// Command to get machine hardware info and key/value delimiters. -// /tmp/machine-info is generated by platform/init/chromeos_startup. -const char* kMachineHardwareInfoTool[] = { "cat", "/tmp/machine-info" }; -const char kMachineHardwareInfoEq[] = "="; -const char kMachineHardwareInfoDelim[] = " \n"; - -// Command to get machine OS info and key/value delimiters. -const char* kMachineOSInfoTool[] = { "cat", "/etc/lsb-release" }; -const char kMachineOSInfoEq[] = "="; -const char kMachineOSInfoDelim[] = "\n"; - -// Command to get VPD info and key/value delimiters. -const char* kVpdTool[] = { "cat", "/var/log/vpd_2.0.txt" }; -const char kVpdEq[] = "="; -const char kVpdDelim[] = "\n"; - -// Fallback time zone ID used in case of an unexpected error. -const char kFallbackTimeZoneId[] = "America/Los_Angeles"; - -const char kSysLogsScript[] = - "/usr/share/userfeedback/scripts/sysinfo_script_runner"; -const char kBzip2Command[] = - "/bin/bzip2"; -const char kMultilineQuote[] = "\"\"\""; -const char kNewLineChars[] = "\r\n"; -const char kInvalidLogEntry[] = ""; -const char kEmptyLogEntry[] = ""; - -const char kContextFeedback[] = "feedback"; -const char kContextSysInfo[] = "sysinfo"; -const char kContextNetwork[] = "network"; - -// Reads a key from the input string erasing the read values + delimiters read -// from the initial string -std::string ReadKey(std::string* data) { - size_t equal_sign = data->find("="); - if (equal_sign == std::string::npos) - return std::string(""); - std::string key = data->substr(0, equal_sign); - data->erase(0, equal_sign); - if (data->size() > 0) { - // erase the equal to sign also - data->erase(0,1); - return key; - } - return std::string(); -} - -// Reads a value from the input string; erasing the read values from -// the initial string; detects if the value is multiline and reads -// accordingly -std::string ReadValue(std::string* data) { - // Trim the leading spaces and tabs. In order to use a multi-line - // value, you have to place the multi-line quote on the same line as - // the equal sign. - // - // Why not use TrimWhitespace? Consider the following input: - // - // KEY1= - // KEY2=VALUE - // - // If we use TrimWhitespace, we will incorrectly trim the new line - // and assume that KEY1's value is "KEY2=VALUE" rather than empty. - TrimString(*data, " \t", data); - - // If multiline value - if (StartsWithASCII(*data, std::string(kMultilineQuote), false)) { - data->erase(0, strlen(kMultilineQuote)); - size_t next_multi = data->find(kMultilineQuote); - if (next_multi == std::string::npos) { - // Error condition, clear data to stop further processing - data->erase(); - return std::string(); - } - std::string value = data->substr(0, next_multi); - data->erase(0, next_multi + 3); - return value; - } else { // single line value - size_t endl_pos = data->find_first_of(kNewLineChars); - // if we don't find a new line, we just return the rest of the data - std::string value = data->substr(0, endl_pos); - data->erase(0, endl_pos); - return value; - } -} - -// Returns a map of system log keys and values. -// -// Parameters: -// temp_filename: This is an out parameter that holds the name of a file in -// /tmp that contains the system logs in a KEY=VALUE format. -// If this parameter is NULL, system logs are not retained on -// the filesystem after this call completes. -// context: This is an in parameter specifying what context should be -// passed to the syslog collection script; currently valid -// values are "sysinfo" or "feedback"; in case of an invalid -// value, the script will currently default to "sysinfo" - -LogDictionaryType* GetSystemLogs(FilePath* zip_file_name, - const std::string& context) { - // Create the temp file, logs will go here - FilePath temp_filename; - - if (!file_util::CreateTemporaryFile(&temp_filename)) - return NULL; - - std::string cmd = std::string(kSysLogsScript) + " " + context + " >> " + - temp_filename.value(); - - // Ignore the return value - if the script execution didn't work - // stderr won't go into the output file anyway. - if (system(cmd.c_str()) == -1) - LOG(WARNING) << "Command " << cmd << " failed to run"; - - // Compress the logs file if requested. - if (zip_file_name) { - cmd = std::string(kBzip2Command) + " -c " + temp_filename.value() + " > " + - zip_file_name->value(); - if (system(cmd.c_str()) == -1) - LOG(WARNING) << "Command " << cmd << " failed to run"; - } - // Read logs from the temp file - std::string data; - bool read_success = file_util::ReadFileToString(temp_filename, - &data); - // if we were using an internal temp file, the user does not need the - // logs to stay past the ReadFile call - delete the file - file_util::Delete(temp_filename, false); - - if (!read_success) - return NULL; - - // Parse the return data into a dictionary - LogDictionaryType* logs = new LogDictionaryType(); - while (data.length() > 0) { - std::string key = ReadKey(&data); - TrimWhitespaceASCII(key, TRIM_ALL, &key); - if (!key.empty()) { - std::string value = ReadValue(&data); - if (IsStringUTF8(value)) { - TrimWhitespaceASCII(value, TRIM_ALL, &value); - if (value.empty()) - (*logs)[key] = kEmptyLogEntry; - else - (*logs)[key] = value; - } else { - LOG(WARNING) << "Invalid characters in system log entry: " << key; - (*logs)[key] = kInvalidLogEntry; - } - } else { - // no more keys, we're done - break; - } - } - - return logs; -} - -class SystemAccessImpl : public SystemAccess { - public: - // SystemAccess.implementation: - virtual const icu::TimeZone& GetTimezone(); - virtual void SetTimezone(const icu::TimeZone& timezone); - virtual bool GetMachineStatistic(const std::string& name, - std::string* result); - virtual void AddObserver(Observer* observer); - virtual void RemoveObserver(Observer* observer); - - virtual Handle RequestSyslogs( - bool compress_logs, - SyslogsContext context, - CancelableRequestConsumerBase* consumer, - ReadCompleteCallback* callback); - - // Reads system logs, compresses content if requested. - // Called from FILE thread. - void ReadSyslogs( - scoped_refptr > request, - bool compress_logs, - SyslogsContext context); - - // Loads compressed logs and writes into |zip_content|. - void LoadCompressedLogs(const FilePath& zip_file, - std::string* zip_content); - - static SystemAccessImpl* GetInstance(); - - private: - friend struct DefaultSingletonTraits; - - SystemAccessImpl(); - - // Updates the machine statistcs by examining the system. - void UpdateMachineStatistics(); - - // Gets syslogs context string from the enum value. - const char* GetSyslogsContextString(SyslogsContext context); - - scoped_ptr timezone_; - ObserverList observers_; - NameValuePairsParser::NameValueMap machine_info_; - - DISALLOW_COPY_AND_ASSIGN(SystemAccessImpl); -}; - -std::string GetTimezoneIDAsString() { - // Look at kTimezoneSymlink, see which timezone we are symlinked to. - char buf[256]; - const ssize_t len = readlink(kTimezoneSymlink, buf, - sizeof(buf)-1); - if (len == -1) { - LOG(ERROR) << "GetTimezoneID: Cannot read timezone symlink " - << kTimezoneSymlink; - return std::string(); - } - - std::string timezone(buf, len); - // Remove kTimezoneFilesDir from the beginning. - if (timezone.find(kTimezoneFilesDir) != 0) { - LOG(ERROR) << "GetTimezoneID: Timezone symlink is wrong " - << timezone; - return std::string(); - } - - return timezone.substr(strlen(kTimezoneFilesDir)); -} - -void SetTimezoneIDFromString(const std::string& id) { - // Change the kTimezoneSymlink symlink to the path for this timezone. - // We want to do this in an atomic way. So we are going to create the symlink - // at kTimezoneSymlink2 and then move it to kTimezoneSymlink - - FilePath timezone_symlink(kTimezoneSymlink); - FilePath timezone_symlink2(kTimezoneSymlink2); - FilePath timezone_file(kTimezoneFilesDir + id); - - // Make sure timezone_file exists. - if (!file_util::PathExists(timezone_file)) { - LOG(ERROR) << "SetTimezoneID: Cannot find timezone file " - << timezone_file.value(); - return; - } - - // Delete old symlink2 if it exists. - file_util::Delete(timezone_symlink2, false); - - // Create new symlink2. - if (symlink(timezone_file.value().c_str(), - timezone_symlink2.value().c_str()) == -1) { - LOG(ERROR) << "SetTimezoneID: Unable to create symlink " - << timezone_symlink2.value() << " to " << timezone_file.value(); - return; - } - - // Move symlink2 to symlink. - if (!file_util::ReplaceFile(timezone_symlink2, timezone_symlink)) { - LOG(ERROR) << "SetTimezoneID: Unable to move symlink " - << timezone_symlink2.value() << " to " - << timezone_symlink.value(); - } -} - -const icu::TimeZone& SystemAccessImpl::GetTimezone() { - return *timezone_.get(); -} - -void SystemAccessImpl::SetTimezone(const icu::TimeZone& timezone) { - timezone_.reset(timezone.clone()); - icu::UnicodeString unicode; - timezone.getID(unicode); - std::string id; - UTF16ToUTF8(unicode.getBuffer(), unicode.length(), &id); - VLOG(1) << "Setting timezone to " << id; - chromeos::SetTimezoneIDFromString(id); - icu::TimeZone::setDefault(timezone); - FOR_EACH_OBSERVER(Observer, observers_, TimezoneChanged(timezone)); -} - -bool SystemAccessImpl::GetMachineStatistic( - const std::string& name, std::string* result) { - NameValuePairsParser::NameValueMap::iterator iter = machine_info_.find(name); - if (iter != machine_info_.end()) { - *result = iter->second; - return true; - } - return false; -} - -void SystemAccessImpl::AddObserver(Observer* observer) { - observers_.AddObserver(observer); -} - -void SystemAccessImpl::RemoveObserver(Observer* observer) { - observers_.RemoveObserver(observer); -} - -SystemAccessImpl::SystemAccessImpl() { - // Get Statistics - UpdateMachineStatistics(); - // Get Timezone - std::string id = GetTimezoneIDAsString(); - if (id.empty()) { - id = kFallbackTimeZoneId; - LOG(ERROR) << "Got an empty string for timezone, default to " << id; - } - icu::TimeZone* timezone = - icu::TimeZone::createTimeZone(icu::UnicodeString::fromUTF8(id)); - timezone_.reset(timezone); - icu::TimeZone::setDefault(*timezone); - VLOG(1) << "Timezone is " << id; -} - -void SystemAccessImpl::UpdateMachineStatistics() { - NameValuePairsParser parser(&machine_info_); - if (!parser.GetSingleValueFromTool(arraysize(kHardwareClassTool), - kHardwareClassTool, - kHardwareClassKey)) { - // Use kUnknownHardwareClass if the hardware class command fails. - parser.AddNameValuePair(kHardwareClassKey, kUnknownHardwareClass); - } - parser.ParseNameValuePairsFromTool(arraysize(kMachineHardwareInfoTool), - kMachineHardwareInfoTool, - kMachineHardwareInfoEq, - kMachineHardwareInfoDelim); - parser.ParseNameValuePairsFromTool(arraysize(kMachineOSInfoTool), - kMachineOSInfoTool, - kMachineOSInfoEq, - kMachineOSInfoDelim); - parser.ParseNameValuePairsFromTool( - arraysize(kVpdTool), kVpdTool, kVpdEq, kVpdDelim); -} - -CancelableRequestProvider::Handle SystemAccessImpl::RequestSyslogs( - bool compress_logs, - SyslogsContext context, - CancelableRequestConsumerBase* consumer, - ReadCompleteCallback* callback) { - // Register the callback request. - scoped_refptr > request( - new CancelableRequest(callback)); - AddRequest(request, consumer); - - // Schedule a task on the FILE thread which will then trigger a request - // callback on the calling thread (e.g. UI) when complete. - BrowserThread::PostTask( - BrowserThread::FILE, FROM_HERE, - NewRunnableMethod( - this, &SystemAccessImpl::ReadSyslogs, request, - compress_logs, context)); - - return request->handle(); -} - -// Called from FILE thread. -void SystemAccessImpl::ReadSyslogs( - scoped_refptr > request, - bool compress_logs, - SyslogsContext context) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); - - if (request->canceled()) - return; - - if (compress_logs && !CommandLine::ForCurrentProcess()->HasSwitch( - switches::kCompressSystemFeedback)) - compress_logs = false; - - // Create temp file. - FilePath zip_file; - if (compress_logs && !file_util::CreateTemporaryFile(&zip_file)) { - LOG(ERROR) << "Cannot create temp file"; - compress_logs = false; - } - - LogDictionaryType* logs = NULL; - logs = chromeos::GetSystemLogs( - compress_logs ? &zip_file : NULL, - GetSyslogsContextString(context)); - - std::string* zip_content = NULL; - if (compress_logs) { - // Load compressed logs. - zip_content = new std::string(); - LoadCompressedLogs(zip_file, zip_content); - file_util::Delete(zip_file, false); - } - - // Will call the callback on the calling thread. - request->ForwardResult(Tuple2(logs, zip_content)); -} - - -void SystemAccessImpl::LoadCompressedLogs(const FilePath& zip_file, - std::string* zip_content) { - DCHECK(zip_content); - if (!file_util::ReadFileToString(zip_file, zip_content)) { - LOG(ERROR) << "Cannot read compressed logs file from " << - zip_file.value().c_str(); - } -} - -const char* SystemAccessImpl::GetSyslogsContextString(SyslogsContext context) { - switch (context) { - case(SYSLOGS_FEEDBACK): - return kContextFeedback; - case(SYSLOGS_SYSINFO): - return kContextSysInfo; - case(SYSLOGS_NETWORK): - return kContextNetwork; - case(SYSLOGS_DEFAULT): - return kContextSysInfo; - default: - NOTREACHED(); - return ""; - } -} - -SystemAccessImpl* SystemAccessImpl::GetInstance() { - return Singleton >::get(); -} - -} // namespace - -SystemAccess* SystemAccess::GetInstance() { - return SystemAccessImpl::GetInstance(); -} - -} // namespace chromeos - -// Allows InvokeLater without adding refcounting. SystemAccessImpl is a -// Singleton and won't be deleted until it's last InvokeLater is run. -DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::SystemAccessImpl); diff --git a/chrome/browser/chromeos/system_access.h b/chrome/browser/chromeos/system_access.h deleted file mode 100644 index 857c433..0000000 --- a/chrome/browser/chromeos/system_access.h +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_CHROMEOS_SYSTEM_ACCESS_H_ -#define CHROME_BROWSER_CHROMEOS_SYSTEM_ACCESS_H_ -#pragma once - -#include - -#include "base/callback_old.h" -#include "content/browser/cancelable_request.h" -#include "unicode/timezone.h" - -class CancelableRequestConsumerBase; - -namespace chromeos { - -typedef std::map LogDictionaryType; - -// This interface provides access to Chrome OS system APIs such as the -// timezone setting. -class SystemAccess : public CancelableRequestProvider { - public: - class Observer { - public: - // Called when the timezone has changed. |timezone| is non-null. - virtual void TimezoneChanged(const icu::TimeZone& timezone) = 0; - }; - - static SystemAccess* GetInstance(); - - // Returns the current timezone as an icu::Timezone object. - virtual const icu::TimeZone& GetTimezone() = 0; - - // Sets the current timezone. |timezone| must be non-null. - virtual void SetTimezone(const icu::TimeZone& timezone) = 0; - - // Retrieve the named machine statistic (e.g. "hardware_class"). - // This does not update the statistcs. If the |name| is not set, |result| - // preserves old value. - virtual bool GetMachineStatistic(const std::string& name, - std::string* result) = 0; - - // The callback type used with RequestSyslogs(). - typedef Callback2::Type ReadCompleteCallback; - - // Used to specify the syslogs context with RequestSyslogs(). - enum SyslogsContext { - SYSLOGS_FEEDBACK, - SYSLOGS_SYSINFO, - SYSLOGS_NETWORK, - SYSLOGS_DEFAULT - }; - - // Request system logs. Read happens on the FILE thread and callback is - // called on the thread this is called from (via ForwardResult). - // Logs are owned by callback function (use delete when done with them). - // Returns the request handle. Call CancelRequest(Handle) to cancel - // the request before the callback gets called. - virtual Handle RequestSyslogs( - bool compress_logs, - SyslogsContext context, - CancelableRequestConsumerBase* consumer, - ReadCompleteCallback* callback) = 0; - - // The observer is used to monitor timezone changes. - virtual void AddObserver(Observer* observer) = 0; - virtual void RemoveObserver(Observer* observer) = 0; - - protected: - virtual ~SystemAccess() {} -}; - -} // namespace chromeos - -#endif // CHROME_BROWSER_CHROMEOS_SYSTEM_ACCESS_H_ diff --git a/chrome/browser/extensions/extension_info_private_api_chromeos.cc b/chrome/browser/extensions/extension_info_private_api_chromeos.cc index 07c81bd..edeb3ad 100644 --- a/chrome/browser/extensions/extension_info_private_api_chromeos.cc +++ b/chrome/browser/extensions/extension_info_private_api_chromeos.cc @@ -8,7 +8,7 @@ #include "chrome/browser/chromeos/cros/cros_library.h" #include "chrome/browser/chromeos/cros/network_library.h" #include "chrome/browser/chromeos/login/wizard_controller.h" -#include "chrome/browser/chromeos/system_access.h" +#include "chrome/browser/chromeos/system/statistics_provider.h" using chromeos::CrosLibrary; using chromeos::NetworkLibrary; @@ -55,8 +55,9 @@ bool GetChromeosInfoFunction::GetValue(const std::string& property_name, std::string* value) { value->clear(); if (property_name == kPropertyHWID) { - chromeos::SystemAccess* system = chromeos::SystemAccess::GetInstance(); - system->GetMachineStatistic(kHardwareClass, value); + chromeos::system::StatisticsProvider* provider = + chromeos::system::StatisticsProvider::GetInstance(); + provider->GetMachineStatistic(kHardwareClass, value); } else if (property_name == kPropertyHomeProvider) { if (CrosLibrary::Get()->EnsureLoaded()) { NetworkLibrary* netlib = CrosLibrary::Get()->GetNetworkLibrary(); diff --git a/chrome/browser/metrics/metrics_service.cc b/chrome/browser/metrics/metrics_service.cc index 4448c41..73c652c 100644 --- a/chrome/browser/metrics/metrics_service.cc +++ b/chrome/browser/metrics/metrics_service.cc @@ -200,7 +200,7 @@ #if defined(OS_CHROMEOS) #include "chrome/browser/chromeos/cros/cros_library.h" #include "chrome/browser/chromeos/external_metrics.h" -#include "chrome/browser/chromeos/system_access.h" +#include "chrome/browser/chromeos/system/statistics_provider.h" #endif namespace { @@ -343,7 +343,7 @@ class MetricsService::InitTask : public Task { webkit::npapi::PluginList::Singleton()->GetPlugins(false, &plugins); std::string hardware_class; // Empty string by default. #if defined(OS_CHROMEOS) - chromeos::SystemAccess::GetInstance()->GetMachineStatistic( + chromeos::system::StatisticsProvider::GetInstance()->GetMachineStatistic( "hardware_class", &hardware_class); #endif // OS_CHROMEOS callback_loop_->PostTask(FROM_HERE, new InitTaskComplete( diff --git a/chrome/browser/policy/cloud_policy_data_store.cc b/chrome/browser/policy/cloud_policy_data_store.cc index 22d8581..b3d7a84b 100644 --- a/chrome/browser/policy/cloud_policy_data_store.cc +++ b/chrome/browser/policy/cloud_policy_data_store.cc @@ -9,7 +9,7 @@ #include "chrome/browser/policy/proto/device_management_constants.h" #if defined(OS_CHROMEOS) -#include "chrome/browser/chromeos/system_access.h" +#include "chrome/browser/chromeos/system/statistics_provider.h" #endif namespace { @@ -34,13 +34,14 @@ CloudPolicyDataStore* CloudPolicyDataStore::CreateForDevicePolicies() { std::string machine_model; std::string machine_id; #if defined(OS_CHROMEOS) - chromeos::SystemAccess* sys_lib = chromeos::SystemAccess::GetInstance(); - if (!sys_lib->GetMachineStatistic(kMachineInfoSystemHwqual, - &machine_model)) { + chromeos::system::StatisticsProvider* provider = + chromeos::system::StatisticsProvider::GetInstance(); + if (!provider->GetMachineStatistic(kMachineInfoSystemHwqual, + &machine_model)) { LOG(ERROR) << "Failed to get machine model."; } - if (!sys_lib->GetMachineStatistic(kMachineInfoSerialNumber, - &machine_id)) { + if (!provider->GetMachineStatistic(kMachineInfoSerialNumber, + &machine_id)) { LOG(ERROR) << "Failed to get machine serial number."; } #endif diff --git a/chrome/browser/policy/device_management_backend_impl.cc b/chrome/browser/policy/device_management_backend_impl.cc index 7f3850e..0988706 100644 --- a/chrome/browser/policy/device_management_backend_impl.cc +++ b/chrome/browser/policy/device_management_backend_impl.cc @@ -21,7 +21,7 @@ #include "net/url_request/url_request_status.h" #if defined(OS_CHROMEOS) -#include "chrome/browser/chromeos/system_access.h" +#include "chrome/browser/chromeos/system/statistics_provider.h" #endif namespace policy { @@ -460,12 +460,13 @@ std::string DeviceManagementBackendImpl::GetPlatformString() { std::string os_hardware(base::SysInfo::CPUArchitecture()); #if defined(OS_CHROMEOS) - chromeos::SystemAccess* sys_lib = chromeos::SystemAccess::GetInstance(); + chromeos::system::StatisticsProvider* provider = + chromeos::system::StatisticsProvider::GetInstance(); std::string hwclass; std::string board; - if (!sys_lib->GetMachineStatistic(kMachineInfoHWClass, &hwclass) || - !sys_lib->GetMachineStatistic(kMachineInfoBoard, &board)) { + if (!provider->GetMachineStatistic(kMachineInfoHWClass, &hwclass) || + !provider->GetMachineStatistic(kMachineInfoBoard, &board)) { LOG(ERROR) << "Failed to get machine information"; } os_name += ",CrOS," + board; diff --git a/chrome/browser/policy/device_policy_identity_strategy.cc b/chrome/browser/policy/device_policy_identity_strategy.cc new file mode 100644 index 0000000..b0519aa --- /dev/null +++ b/chrome/browser/policy/device_policy_identity_strategy.cc @@ -0,0 +1,106 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/policy/device_policy_identity_strategy.h" + +#include "chrome/browser/browser_process.h" +#include "chrome/browser/chromeos/cros/cros_library.h" +#include "chrome/browser/chromeos/login/ownership_service.h" +#include "chrome/browser/chromeos/login/user_manager.h" +#include "chrome/browser/chromeos/system/statistics_provider.h" +#include "chrome/browser/net/gaia/token_service.h" +#include "chrome/browser/policy/proto/device_management_constants.h" +#include "chrome/browser/profiles/profile.h" +#include "chrome/browser/profiles/profile_manager.h" +#include "chrome/common/guid.h" +#include "chrome/common/net/gaia/gaia_constants.h" +#include "content/common/notification_service.h" +#include "content/common/notification_type.h" + +// MachineInfo key names. +static const char kMachineInfoSystemHwqual[] = "hardware_class"; +static const char kMachineInfoSerialNumber[] = "serial_number"; + +namespace policy { + +DevicePolicyIdentityStrategy::DevicePolicyIdentityStrategy() { + chromeos::system::StatisticsProvider* provider = + chromeos::system::StatisticsProvider::GetInstance(); + + if (!provider->GetMachineStatistic(kMachineInfoSystemHwqual, + &machine_model_)) { + LOG(ERROR) << "Failed to get machine model."; + } + if (!provider->GetMachineStatistic(kMachineInfoSerialNumber, + &machine_id_)) { + LOG(ERROR) << "Failed to get machine serial number."; + } +} + +DevicePolicyIdentityStrategy::~DevicePolicyIdentityStrategy() { +} + +std::string DevicePolicyIdentityStrategy::GetDeviceToken() { + return device_token_; +} + +std::string DevicePolicyIdentityStrategy::GetDeviceID() { + return device_id_; +} + +std::string DevicePolicyIdentityStrategy::GetMachineID() { + return machine_id_; +} + +std::string DevicePolicyIdentityStrategy::GetMachineModel() { + return machine_model_; +} + +em::DeviceRegisterRequest_Type +DevicePolicyIdentityStrategy::GetPolicyRegisterType() { + return em::DeviceRegisterRequest::DEVICE; +} + +std::string DevicePolicyIdentityStrategy::GetPolicyType() { + return kChromeDevicePolicyType; +} + +void DevicePolicyIdentityStrategy::SetAuthCredentials( + const std::string& username, + const std::string& auth_token) { + username_ = username; + auth_token_ = auth_token; + device_id_ = guid::GenerateGUID(); + NotifyAuthChanged(); +} + +void DevicePolicyIdentityStrategy::SetDeviceManagementCredentials( + const std::string& owner_email, + const std::string& device_id, + const std::string& device_token) { + username_ = owner_email; + device_id_ = device_id; + device_token_ = device_token; + NotifyDeviceTokenChanged(); +} + +void DevicePolicyIdentityStrategy::FetchPolicy() { + DCHECK(!device_token_.empty()); + NotifyDeviceTokenChanged(); +} + +bool DevicePolicyIdentityStrategy::GetCredentials(std::string* username, + std::string* auth_token) { + *username = username_; + *auth_token = auth_token_; + + return !username->empty() && !auth_token->empty(); +} + +void DevicePolicyIdentityStrategy::OnDeviceTokenAvailable( + const std::string& token) { + device_token_ = token; +} + +} // namespace policy diff --git a/chrome/browser/ui/webui/bug_report_ui.cc b/chrome/browser/ui/webui/bug_report_ui.cc index 4f8aa52..62c3ec8 100644 --- a/chrome/browser/ui/webui/bug_report_ui.cc +++ b/chrome/browser/ui/webui/bug_report_ui.cc @@ -44,7 +44,7 @@ #include "base/synchronization/waitable_event.h" #include "chrome/browser/chromeos/cros/cros_library.h" #include "chrome/browser/chromeos/login/user_manager.h" -#include "chrome/browser/chromeos/system_access.h" +#include "chrome/browser/chromeos/system/syslogs_provider.h" #endif namespace { @@ -223,8 +223,8 @@ class BugReportHandler : public WebUIMessageHandler, BugReportData* bug_report_; std::string target_tab_url_; #if defined(OS_CHROMEOS) - // Variables to track SystemAccess::RequestSyslogs callback. - chromeos::SystemAccess::Handle syslogs_handle_; + // Variables to track SyslogsProvider::RequestSyslogs callback. + chromeos::system::SyslogsProvider::Handle syslogs_handle_; CancelableRequestConsumer syslogs_consumer_; #endif @@ -566,12 +566,12 @@ void BugReportHandler::HandleGetDialogDefaults(const ListValue*) { // 1: about:system dialog_defaults.Append(new StringValue(chrome::kChromeUISystemInfoURL)); // Trigger the request for system information here. - chromeos::SystemAccess* system_access = - chromeos::SystemAccess::GetInstance(); - if (system_access) { - syslogs_handle_ = system_access->RequestSyslogs( + chromeos::system::SyslogsProvider* provider = + chromeos::system::SyslogsProvider::GetInstance(); + if (provider) { + syslogs_handle_ = provider->RequestSyslogs( true, // don't compress. - chromeos::SystemAccess::SYSLOGS_FEEDBACK, + chromeos::system::SyslogsProvider::SYSLOGS_FEEDBACK, &syslogs_consumer_, NewCallback(bug_report_, &BugReportData::SyslogsComplete)); } @@ -725,10 +725,10 @@ void BugReportHandler::HandleOpenSystemTab(const ListValue* args) { void BugReportHandler::CancelFeedbackCollection() { #if defined(OS_CHROMEOS) if (syslogs_handle_ != 0) { - chromeos::SystemAccess* system_access = - chromeos::SystemAccess::GetInstance(); - if (system_access) - system_access->CancelRequest(syslogs_handle_); + chromeos::system::SyslogsProvider* provider = + chromeos::system::SyslogsProvider::GetInstance(); + if (provider) + provider->CancelRequest(syslogs_handle_); } #endif } diff --git a/chrome/browser/ui/webui/chromeos/imageburner/imageburner_ui.cc b/chrome/browser/ui/webui/chromeos/imageburner/imageburner_ui.cc index ab79ef6..a8fc7c7 100644 --- a/chrome/browser/ui/webui/chromeos/imageburner/imageburner_ui.cc +++ b/chrome/browser/ui/webui/chromeos/imageburner/imageburner_ui.cc @@ -10,7 +10,7 @@ #include "base/task.h" #include "base/utf_string_conversions.h" #include "base/values.h" -#include "chrome/browser/chromeos/system_access.h" +#include "chrome/browser/chromeos/system/statistics_provider.h" #include "chrome/browser/profiles/profile.h" #include "chrome/common/jstemplate_builder.h" #include "chrome/common/time_format.h" @@ -531,8 +531,8 @@ void WebUIHandler::ProcessError(int message_id) { bool WebUIHandler::ExtractInfoFromConfigFile(const ConfigFile& config_file) { std::string hwid; - if (!chromeos::SystemAccess::GetInstance()->GetMachineStatistic( - kHwidStatistic, &hwid)) + if (!chromeos::system::StatisticsProvider::GetInstance()-> + GetMachineStatistic(kHwidStatistic, &hwid)) return false; image_file_name_ = config_file.GetProperty(kFileName, hwid); @@ -674,4 +674,3 @@ ImageBurnUI::ImageBurnUI(TabContents* contents) : ChromeWebUI(contents) { imageburner::UIHTMLSource* html_source = new imageburner::UIHTMLSource(); contents->profile()->GetChromeURLDataManager()->AddDataSource(html_source); } - diff --git a/chrome/browser/ui/webui/chromeos/register_page_ui.cc b/chrome/browser/ui/webui/chromeos/register_page_ui.cc index 5cae02cd..aa13345 100644 --- a/chrome/browser/ui/webui/chromeos/register_page_ui.cc +++ b/chrome/browser/ui/webui/chromeos/register_page_ui.cc @@ -17,7 +17,7 @@ #include "chrome/browser/chromeos/cros/network_library.h" #include "chrome/browser/chromeos/customization_document.h" #include "chrome/browser/chromeos/login/wizard_controller.h" -#include "chrome/browser/chromeos/system_access.h" +#include "chrome/browser/chromeos/system/statistics_provider.h" #include "chrome/browser/chromeos/version_loader.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/webui/chrome_url_data_manager.h" @@ -274,14 +274,16 @@ void RegisterPageHandler::SendUserInfo() { #if defined(OS_CHROMEOS) DictionaryValue value; - chromeos::SystemAccess * sys_lib = - chromeos::SystemAccess::GetInstance(); + chromeos::system::StatisticsProvider * provider = + chromeos::system::StatisticsProvider::GetInstance(); // Required info. std::string system_hwqual; std::string serial_number; - if (!sys_lib->GetMachineStatistic(kMachineInfoSystemHwqual, &system_hwqual) || - !sys_lib->GetMachineStatistic(kMachineInfoSerialNumber, &serial_number)) { + if (!provider->GetMachineStatistic(kMachineInfoSystemHwqual, + &system_hwqual) || + !provider->GetMachineStatistic(kMachineInfoSerialNumber, + &serial_number)) { SkipRegistration("Failed to get required machine info."); return; } diff --git a/chrome/browser/ui/webui/chromeos/system_info_ui.cc b/chrome/browser/ui/webui/chromeos/system_info_ui.cc index 74bd2ab..a72b32d 100644 --- a/chrome/browser/ui/webui/chromeos/system_info_ui.cc +++ b/chrome/browser/ui/webui/chromeos/system_info_ui.cc @@ -15,7 +15,7 @@ #include "base/utf_string_conversions.h" #include "base/values.h" #include "chrome/browser/chromeos/cros/cros_library.h" -#include "chrome/browser/chromeos/system_access.h" +#include "chrome/browser/chromeos/system/syslogs_provider.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/webui/chrome_url_data_manager.h" #include "chrome/common/chrome_paths.h" @@ -48,7 +48,7 @@ class SystemInfoUIHTMLSource : public ChromeURLDataManager::DataSource { private: ~SystemInfoUIHTMLSource() {} - void SyslogsComplete(chromeos::LogDictionaryType* sys_info, + void SyslogsComplete(chromeos::system::LogDictionaryType* sys_info, std::string* ignored_content); CancelableRequestConsumer consumer_; @@ -92,19 +92,19 @@ void SystemInfoUIHTMLSource::StartDataRequest(const std::string& path, path_ = path; request_id_ = request_id; - chromeos::SystemAccess* system_access = - chromeos::SystemAccess::GetInstance(); - if (system_access) { - system_access->RequestSyslogs( + chromeos::system::SyslogsProvider* provider = + chromeos::system::SyslogsProvider::GetInstance(); + if (provider) { + provider->RequestSyslogs( false, // don't compress. - chromeos::SystemAccess::SYSLOGS_SYSINFO, + chromeos::system::SyslogsProvider::SYSLOGS_SYSINFO, &consumer_, NewCallback(this, &SystemInfoUIHTMLSource::SyslogsComplete)); } } void SystemInfoUIHTMLSource::SyslogsComplete( - chromeos::LogDictionaryType* sys_info, + chromeos::system::LogDictionaryType* sys_info, std::string* ignored_content) { DCHECK(!ignored_content); @@ -127,7 +127,7 @@ void SystemInfoUIHTMLSource::SyslogsComplete( if (sys_info) { ListValue* details = new ListValue(); strings.Set("details", details); - chromeos::LogDictionaryType::iterator it; + chromeos::system::LogDictionaryType::iterator it; for (it = sys_info->begin(); it != sys_info->end(); ++it) { DictionaryValue* val = new DictionaryValue; val->SetString("stat_name", it->first); diff --git a/chrome/browser/ui/webui/net_internals_ui.cc b/chrome/browser/ui/webui/net_internals_ui.cc index f430313..e16204a 100644 --- a/chrome/browser/ui/webui/net_internals_ui.cc +++ b/chrome/browser/ui/webui/net_internals_ui.cc @@ -62,7 +62,7 @@ #ifdef OS_CHROMEOS #include "chrome/browser/chromeos/cros/cros_library.h" -#include "chrome/browser/chromeos/system_access.h" +#include "chrome/browser/chromeos/system/syslogs_provider.h" #endif #ifdef OS_WIN #include "chrome/browser/net/service_providers_win.h" @@ -193,7 +193,7 @@ class NetInternalsMessageHandler class SystemLogsGetter { public: SystemLogsGetter(NetInternalsMessageHandler* handler, - chromeos::SystemAccess* system_access); + chromeos::system::SyslogsProvider* syslogs_provider); ~SystemLogsGetter(); // Deletes logs copy we currently have, and resets logs_requested and @@ -211,7 +211,7 @@ class NetInternalsMessageHandler void LoadSystemLogs(); // Processes callback from libcros containing system logs. Postponed // request responses are sent. - void OnSystemLogsLoaded(chromeos::LogDictionaryType* sys_info, + void OnSystemLogsLoaded(chromeos::system::LogDictionaryType* sys_info, std::string* ignored_content); private: @@ -225,10 +225,10 @@ class NetInternalsMessageHandler void SendLogs(const SystemLogRequest& request); NetInternalsMessageHandler* handler_; - chromeos::SystemAccess* system_access_; + chromeos::system::SyslogsProvider* syslogs_provider_; // List of postponed requests. std::list requests_; - scoped_ptr logs_; + scoped_ptr logs_; bool logs_received_; bool logs_requested_; CancelableRequestConsumer consumer_; @@ -525,7 +525,7 @@ WebUIMessageHandler* NetInternalsMessageHandler::Attach(WebUI* web_ui) { web_ui->GetProfile()->GetRequestContext()); #ifdef OS_CHROMEOS syslogs_getter_.reset(new SystemLogsGetter(this, - chromeos::SystemAccess::GetInstance())); + chromeos::system::SyslogsProvider::GetInstance())); #endif renderer_ready_io_callback_.reset( proxy_->CreateCallback(&IOThreadImpl::OnRendererReady)); @@ -710,13 +710,13 @@ void NetInternalsMessageHandler::OnGetPrerenderInfo(const ListValue* list) { NetInternalsMessageHandler::SystemLogsGetter::SystemLogsGetter( NetInternalsMessageHandler* handler, - chromeos::SystemAccess* system_access) + chromeos::system::SyslogsProvider* syslogs_provider) : handler_(handler), - system_access_(system_access), + syslogs_provider_(syslogs_provider), logs_(NULL), logs_received_(false), logs_requested_(false) { - if (!system_access_) + if (!syslogs_provider_) LOG(ERROR) << "System access library not loaded"; } @@ -725,8 +725,8 @@ NetInternalsMessageHandler::SystemLogsGetter::~SystemLogsGetter() { } void NetInternalsMessageHandler::SystemLogsGetter::DeleteSystemLogs() { - if (system_access_ && logs_requested_ && !logs_received_) { - system_access_->CancelRequest(syslogs_request_id_); + if (syslogs_provider_ && logs_requested_ && !logs_received_) { + syslogs_provider_->CancelRequest(syslogs_request_id_); } logs_requested_ = false; logs_received_ = false; @@ -751,12 +751,12 @@ void NetInternalsMessageHandler::SystemLogsGetter::RequestSystemLog( } void NetInternalsMessageHandler::SystemLogsGetter::LoadSystemLogs() { - if (logs_requested_ || !system_access_) + if (logs_requested_ || !syslogs_provider_) return; logs_requested_ = true; - syslogs_request_id_ = system_access_->RequestSyslogs( + syslogs_request_id_ = syslogs_provider_->RequestSyslogs( false, // compress logs. - chromeos::SystemAccess::SYSLOGS_NETWORK, + chromeos::system::SyslogsProvider::SYSLOGS_NETWORK, &consumer_, NewCallback( this, @@ -764,7 +764,8 @@ void NetInternalsMessageHandler::SystemLogsGetter::LoadSystemLogs() { } void NetInternalsMessageHandler::SystemLogsGetter::OnSystemLogsLoaded( - chromeos::LogDictionaryType* sys_info, std::string* ignored_content) { + chromeos::system::LogDictionaryType* sys_info, + std::string* ignored_content) { DCHECK(!ignored_content); logs_.reset(sys_info); logs_received_ = true; @@ -779,7 +780,8 @@ void NetInternalsMessageHandler::SystemLogsGetter::OnSystemLogsLoaded( void NetInternalsMessageHandler::SystemLogsGetter::SendLogs( const SystemLogRequest& request) { DictionaryValue* result = new DictionaryValue(); - chromeos::LogDictionaryType::iterator log_it = logs_->find(request.log_key); + chromeos::system::LogDictionaryType::iterator log_it = + logs_->find(request.log_key); if (log_it != logs_->end()) { if (!log_it->second.empty()) { result->SetString("log", log_it->second); diff --git a/chrome/browser/ui/webui/options/chromeos/system_settings_provider.cc b/chrome/browser/ui/webui/options/chromeos/system_settings_provider.cc index aef8774..c452aa7 100644 --- a/chrome/browser/ui/webui/options/chromeos/system_settings_provider.cc +++ b/chrome/browser/ui/webui/options/chromeos/system_settings_provider.cc @@ -185,12 +185,12 @@ SystemSettingsProvider::SystemSettingsProvider() { timezones_.push_back(icu::TimeZone::createTimeZone( icu::UnicodeString(kTimeZones[i], -1, US_INV))); } - SystemAccess::GetInstance()->AddObserver(this); + system::TimezoneSettings::GetInstance()->AddObserver(this); } SystemSettingsProvider::~SystemSettingsProvider() { - SystemAccess::GetInstance()->RemoveObserver(this); + system::TimezoneSettings::GetInstance()->RemoveObserver(this); STLDeleteElements(&timezones_); } @@ -207,7 +207,7 @@ void SystemSettingsProvider::DoSet(const std::string& path, Value* in_value) { const icu::TimeZone* timezone = GetTimezone(value); if (!timezone) return; - SystemAccess::GetInstance()->SetTimezone(*timezone); + system::TimezoneSettings::GetInstance()->SetTimezone(*timezone); } } @@ -215,7 +215,7 @@ bool SystemSettingsProvider::Get(const std::string& path, Value** out_value) const { if (path == kSystemTimezone) { *out_value = Value::CreateStringValue(GetKnownTimezoneID( - SystemAccess::GetInstance()->GetTimezone())); + system::TimezoneSettings::GetInstance()->GetTimezone())); return true; } return false; diff --git a/chrome/browser/ui/webui/options/chromeos/system_settings_provider.h b/chrome/browser/ui/webui/options/chromeos/system_settings_provider.h index ae413d3..afc7fa9 100644 --- a/chrome/browser/ui/webui/options/chromeos/system_settings_provider.h +++ b/chrome/browser/ui/webui/options/chromeos/system_settings_provider.h @@ -9,7 +9,7 @@ #include "base/string16.h" #include "chrome/browser/chromeos/cros_settings_provider.h" -#include "chrome/browser/chromeos/system_access.h" +#include "chrome/browser/chromeos/system/timezone_settings.h" #include "third_party/icu/public/i18n/unicode/timezone.h" class Value; @@ -18,7 +18,7 @@ class ListValue; namespace chromeos { class SystemSettingsProvider : public CrosSettingsProvider, - public SystemAccess::Observer { + public system::TimezoneSettings::Observer { public: SystemSettingsProvider(); virtual ~SystemSettingsProvider(); @@ -27,7 +27,7 @@ class SystemSettingsProvider : public CrosSettingsProvider, virtual bool Get(const std::string& path, Value** out_value) const; virtual bool HandlesSetting(const std::string& path); - // Overridden from SystemAccess::Observer: + // Overridden from TimezoneSettings::Observer: virtual void TimezoneChanged(const icu::TimeZone& timezone); // Creates the map of timezones used by the options page. -- cgit v1.1