diff options
author | satorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-10 06:24:52 +0000 |
---|---|---|
committer | satorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-10 06:24:52 +0000 |
commit | d43970a7ceee5fc5433787b0f28b64234a4039f2 (patch) | |
tree | 0cfd2581dc24c226cab75da6b683458dac540199 | |
parent | 7237bfcc6ded653b4ae2defaee6f1303b1744ede (diff) | |
download | chromium_src-d43970a7ceee5fc5433787b0f28b64234a4039f2.zip chromium_src-d43970a7ceee5fc5433787b0f28b64234a4039f2.tar.gz chromium_src-d43970a7ceee5fc5433787b0f28b64234a4039f2.tar.bz2 |
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
38 files changed, 684 insertions, 400 deletions
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<unsigned char>& 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<StartupCustomizationDocument> >::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.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/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<icu::TimeZone> 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<icu::TimeZone> 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/mock_system_access.cc b/chrome/browser/chromeos/system/mock_statistics_provider.cc index fd51c7f..26c2d22 100644 --- a/chrome/browser/chromeos/mock_system_access.cc +++ b/chrome/browser/chromeos/system/mock_statistics_provider.cc @@ -2,12 +2,14 @@ // 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" +#include "chrome/browser/chromeos/system/mock_statistics_provider.h" namespace chromeos { +namespace system { -MockSystemAccess::MockSystemAccess() {} +MockStatisticsProvider::MockStatisticsProvider() {} -MockSystemAccess::~MockSystemAccess() {} +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/name_value_pairs_parser.cc b/chrome/browser/chromeos/system/name_value_pairs_parser.cc index be38daf..700ebac 100644 --- a/chrome/browser/chromeos/name_value_pairs_parser.cc +++ b/chrome/browser/chromeos/system/name_value_pairs_parser.cc @@ -2,7 +2,7 @@ // 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 "chrome/browser/chromeos/system/name_value_pairs_parser.h" #include "base/command_line.h" #include "base/logging.h" @@ -12,6 +12,7 @@ #include "base/threading/thread_restrictions.h" namespace chromeos { // NOLINT +namespace system { namespace { @@ -100,4 +101,5 @@ bool NameValuePairsParser::ParseNameValuePairsFromTool( return true; } +} // namespace system } // namespace chromeos diff --git a/chrome/browser/chromeos/name_value_pairs_parser.h b/chrome/browser/chromeos/system/name_value_pairs_parser.h index ae8823b..bbaf97a 100644 --- a/chrome/browser/chromeos/name_value_pairs_parser.h +++ b/chrome/browser/chromeos/system/name_value_pairs_parser.h @@ -2,8 +2,8 @@ // 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_ +#ifndef CHROME_BROWSER_CHROMEOS_SYSTEM_NAME_VALUE_PAIRS_PARSER_H_ +#define CHROME_BROWSER_CHROMEOS_SYSTEM_NAME_VALUE_PAIRS_PARSER_H_ #pragma once #include <map> @@ -13,6 +13,7 @@ #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. @@ -47,6 +48,7 @@ class NameValuePairsParser { DISALLOW_COPY_AND_ASSIGN(NameValuePairsParser); }; +} // namespace system } // namespace chromeos -#endif // CHROME_BROWSER_CHROMEOS_NAME_VALUE_PAIRS_PARSER_H_ +#endif // CHROME_BROWSER_CHROMEOS_SYSTEM_NAME_VALUE_PAIRS_PARSER_H_ diff --git a/chrome/browser/chromeos/name_value_pairs_parser_unittest.cc b/chrome/browser/chromeos/system/name_value_pairs_parser_unittest.cc index 0973920..65918d0 100644 --- a/chrome/browser/chromeos/name_value_pairs_parser_unittest.cc +++ b/chrome/browser/chromeos/system/name_value_pairs_parser_unittest.cc @@ -2,12 +2,13 @@ // 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 "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; @@ -61,4 +62,5 @@ TEST(NameValuePairsParser, TestParseNameValuePairsFromTool) { 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>; + + 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<StatisticsProviderImpl, + DefaultSingletonTraits<StatisticsProviderImpl> >::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 <string> + +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_access.cc b/chrome/browser/chromeos/system/syslogs_provider.cc index 04cada6..57c76cf 100644 --- a/chrome/browser/chromeos/system_access.cc +++ b/chrome/browser/chromeos/system/syslogs_provider.cc @@ -2,56 +2,21 @@ // 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 "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/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"; +namespace chromeos { +namespace system { +namespace { const char kSysLogsScript[] = "/usr/share/userfeedback/scripts/sysinfo_script_runner"; @@ -124,6 +89,9 @@ std::string ReadValue(std::string* data) { // // 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. @@ -145,14 +113,14 @@ LogDictionaryType* GetSystemLogs(FilePath* zip_file_name, // 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) + 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) + if (::system(cmd.c_str()) == -1) LOG(WARNING) << "Command " << cmd << " failed to run"; } // Read logs from the temp file @@ -192,16 +160,11 @@ LogDictionaryType* GetSystemLogs(FilePath* zip_file_name, 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); +} // namespace +class SyslogsProviderImpl : public SyslogsProvider { + public: + // SyslogsProvider implementation: virtual Handle RequestSyslogs( bool compress_logs, SyslogsContext context, @@ -219,154 +182,23 @@ class SystemAccessImpl : public SystemAccess { void LoadCompressedLogs(const FilePath& zip_file, std::string* zip_content); - static SystemAccessImpl* GetInstance(); + static SyslogsProviderImpl* GetInstance(); private: - friend struct DefaultSingletonTraits<SystemAccessImpl>; - - SystemAccessImpl(); + friend struct DefaultSingletonTraits<SyslogsProviderImpl>; - // Updates the machine statistcs by examining the system. - void UpdateMachineStatistics(); + SyslogsProviderImpl(); // Gets syslogs context string from the enum value. const char* GetSyslogsContextString(SyslogsContext context); - scoped_ptr<icu::TimeZone> timezone_; - ObserverList<Observer> observers_; - NameValuePairsParser::NameValueMap machine_info_; - - DISALLOW_COPY_AND_ASSIGN(SystemAccessImpl); + DISALLOW_COPY_AND_ASSIGN(SyslogsProviderImpl); }; -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; +SyslogsProviderImpl::SyslogsProviderImpl() { } -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( +CancelableRequestProvider::Handle SyslogsProviderImpl::RequestSyslogs( bool compress_logs, SyslogsContext context, CancelableRequestConsumerBase* consumer, @@ -381,14 +213,14 @@ CancelableRequestProvider::Handle SystemAccessImpl::RequestSyslogs( BrowserThread::PostTask( BrowserThread::FILE, FROM_HERE, NewRunnableMethod( - this, &SystemAccessImpl::ReadSyslogs, request, + this, &SyslogsProviderImpl::ReadSyslogs, request, compress_logs, context)); return request->handle(); } // Called from FILE thread. -void SystemAccessImpl::ReadSyslogs( +void SyslogsProviderImpl::ReadSyslogs( scoped_refptr<CancelableRequest<ReadCompleteCallback> > request, bool compress_logs, SyslogsContext context) { @@ -409,7 +241,7 @@ void SystemAccessImpl::ReadSyslogs( } LogDictionaryType* logs = NULL; - logs = chromeos::GetSystemLogs( + logs = GetSystemLogs( compress_logs ? &zip_file : NULL, GetSyslogsContextString(context)); @@ -427,7 +259,7 @@ void SystemAccessImpl::ReadSyslogs( } -void SystemAccessImpl::LoadCompressedLogs(const FilePath& zip_file, +void SyslogsProviderImpl::LoadCompressedLogs(const FilePath& zip_file, std::string* zip_content) { DCHECK(zip_content); if (!file_util::ReadFileToString(zip_file, zip_content)) { @@ -436,7 +268,8 @@ void SystemAccessImpl::LoadCompressedLogs(const FilePath& zip_file, } } -const char* SystemAccessImpl::GetSyslogsContextString(SyslogsContext context) { +const char* SyslogsProviderImpl::GetSyslogsContextString( + SyslogsContext context) { switch (context) { case(SYSLOGS_FEEDBACK): return kContextFeedback; @@ -452,19 +285,18 @@ const char* SystemAccessImpl::GetSyslogsContextString(SyslogsContext context) { } } -SystemAccessImpl* SystemAccessImpl::GetInstance() { - return Singleton<SystemAccessImpl, - DefaultSingletonTraits<SystemAccessImpl> >::get(); +SyslogsProviderImpl* SyslogsProviderImpl::GetInstance() { + return Singleton<SyslogsProviderImpl, + DefaultSingletonTraits<SyslogsProviderImpl> >::get(); } -} // namespace - -SystemAccess* SystemAccess::GetInstance() { - return SystemAccessImpl::GetInstance(); +SyslogsProvider* SyslogsProvider::GetInstance() { + return SyslogsProviderImpl::GetInstance(); } +} // namespace system } // namespace chromeos -// Allows InvokeLater without adding refcounting. SystemAccessImpl is a +// 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::SystemAccessImpl); +DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::system::SyslogsProviderImpl); diff --git a/chrome/browser/chromeos/system_access.h b/chrome/browser/chromeos/system/syslogs_provider.h index 857c433..ecb92b6 100644 --- a/chrome/browser/chromeos/system_access.h +++ b/chrome/browser/chromeos/system/syslogs_provider.h @@ -2,45 +2,26 @@ // 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_ +#ifndef CHROME_BROWSER_CHROMEOS_SYSTEM_SYSLOGS_PROVIDER_H_ +#define CHROME_BROWSER_CHROMEOS_SYSTEM_SYSLOGS_PROVIDER_H_ #pragma once #include <string> #include "base/callback_old.h" #include "content/browser/cancelable_request.h" -#include "unicode/timezone.h" class CancelableRequestConsumerBase; namespace chromeos { +namespace system { typedef std::map<std::string, std::string> LogDictionaryType; -// This interface provides access to Chrome OS system APIs such as the -// timezone setting. -class SystemAccess : public CancelableRequestProvider { +// This interface provides access to Chrome OS syslogs. +class SyslogsProvider : 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; + static SyslogsProvider* GetInstance(); // The callback type used with RequestSyslogs(). typedef Callback2<LogDictionaryType*, @@ -65,14 +46,11 @@ class SystemAccess : public CancelableRequestProvider { 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() {} + virtual ~SyslogsProvider() {} }; +} // namespace system } // namespace chromeos -#endif // CHROME_BROWSER_CHROMEOS_SYSTEM_ACCESS_H_ +#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>; + + TimezoneSettingsImpl(); + + scoped_ptr<icu::TimeZone> timezone_; + ObserverList<Observer> 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<TimezoneSettingsImpl, + DefaultSingletonTraits<TimezoneSettingsImpl> >::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 <string> + +#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/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<SystemLogRequest> requests_; - scoped_ptr<chromeos::LogDictionaryType> logs_; + scoped_ptr<chromeos::system::LogDictionaryType> 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. diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index ae0cc20..1fc6c5e 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -633,8 +633,6 @@ 'browser/chromeos/media/media_player.h', 'browser/chromeos/metrics_cros_settings_provider.cc', 'browser/chromeos/metrics_cros_settings_provider.h', - 'browser/chromeos/name_value_pairs_parser.cc', - 'browser/chromeos/name_value_pairs_parser.h', 'browser/chromeos/native_dialog_window.cc', 'browser/chromeos/native_dialog_window.h', 'browser/chromeos/net/network_change_notifier_chromeos.cc', @@ -710,8 +708,14 @@ 'browser/chromeos/status/status_area_host.h', 'browser/chromeos/status/status_area_view.cc', 'browser/chromeos/status/status_area_view.h', - 'browser/chromeos/system_access.cc', - 'browser/chromeos/system_access.h', + 'browser/chromeos/system/name_value_pairs_parser.cc', + 'browser/chromeos/system/name_value_pairs_parser.h', + 'browser/chromeos/system/statistics_provider.cc', + 'browser/chromeos/system/statistics_provider.h', + 'browser/chromeos/system/syslogs_provider.cc', + 'browser/chromeos/system/syslogs_provider.h', + 'browser/chromeos/system/timezone_settings.cc', + 'browser/chromeos/system/timezone_settings.h', 'browser/chromeos/system_key_event_listener.cc', 'browser/chromeos/system_key_event_listener.h', 'browser/chromeos/tab_closeable_state_watcher.cc', diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 95427bb..9360198 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -1341,14 +1341,14 @@ 'browser/chromeos/login/signed_settings_unittest.cc', 'browser/chromeos/login/user_controller_unittest.cc', 'browser/chromeos/login/wizard_accessibility_handler_unittest.cc', - 'browser/chromeos/mock_system_access.cc', - 'browser/chromeos/mock_system_access.h', - 'browser/chromeos/name_value_pairs_parser_unittest.cc', + 'browser/chromeos/system/name_value_pairs_parser_unittest.cc', 'browser/chromeos/network_message_observer_unittest.cc', 'browser/chromeos/notifications/desktop_notifications_unittest.cc', 'browser/chromeos/offline/offline_load_page_unittest.cc', 'browser/chromeos/proxy_config_service_impl_unittest.cc', 'browser/chromeos/status/input_method_menu_unittest.cc', + 'browser/chromeos/system/mock_statistics_provider.cc', + 'browser/chromeos/system/mock_statistics_provider.h', 'browser/chromeos/version_loader_unittest.cc', 'browser/command_updater_unittest.cc', 'browser/content_settings/content_settings_mock_provider.cc', |