summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/chromeos/cros/cros_in_process_browser_test.cc22
-rw-r--r--chrome/browser/chromeos/cros/cros_in_process_browser_test.h4
-rw-r--r--chrome/browser/chromeos/cros/cros_library.cc19
-rw-r--r--chrome/browser/chromeos/cros/cros_library.h8
-rw-r--r--chrome/browser/chromeos/cros/mock_system_library.h26
-rw-r--r--chrome/browser/chromeos/cros/system_library.cc55
-rw-r--r--chrome/browser/chromeos/cros/system_library.h59
-rw-r--r--chrome/browser/chromeos/login/wizard_controller.cc8
-rw-r--r--chrome/browser/chromeos/options/system_page_view.cc62
-rw-r--r--chrome/browser/chromeos/preferences.cc10
-rw-r--r--chrome/browser/chromeos/preferences.h5
-rw-r--r--chrome/browser/chromeos/status/clock_menu_button.cc28
-rw-r--r--chrome/browser/chromeos/status/clock_menu_button.h15
-rw-r--r--chrome/browser/chromeos/status/clock_menu_button_browsertest.cc8
-rw-r--r--chrome/browser/options_util.cc1
-rw-r--r--chrome/chrome_browser.gypi2
-rw-r--r--chrome/chrome_tests.gypi1
-rw-r--r--chrome/common/pref_names.cc3
-rw-r--r--chrome/common/pref_names.h1
19 files changed, 248 insertions, 89 deletions
diff --git a/chrome/browser/chromeos/cros/cros_in_process_browser_test.cc b/chrome/browser/chromeos/cros/cros_in_process_browser_test.cc
index fcd72b3..74626c7 100644
--- a/chrome/browser/chromeos/cros/cros_in_process_browser_test.cc
+++ b/chrome/browser/chromeos/cros/cros_in_process_browser_test.cc
@@ -17,6 +17,7 @@
#include "chrome/browser/chromeos/cros/mock_power_library.h"
#include "chrome/browser/chromeos/cros/mock_screen_lock_library.h"
#include "chrome/browser/chromeos/cros/mock_synaptics_library.h"
+#include "chrome/browser/chromeos/cros/mock_system_library.h"
#include "chrome/browser/chromeos/login/wizard_controller.h"
#include "chrome/browser/chromeos/login/wizard_screen.h"
#include "chrome/test/in_process_browser_test.h"
@@ -39,7 +40,8 @@ CrosInProcessBrowserTest::CrosInProcessBrowserTest()
mock_network_library_(NULL),
mock_power_library_(NULL),
mock_screen_lock_library_(NULL),
- mock_synaptics_library_(NULL) {}
+ mock_synaptics_library_(NULL),
+ mock_system_library_(NULL) {}
CrosInProcessBrowserTest::~CrosInProcessBrowserTest() {
}
@@ -54,6 +56,7 @@ void CrosInProcessBrowserTest::InitStatusAreaMocks() {
InitMockNetworkLibrary();
InitMockPowerLibrary();
InitMockSynapticsLibrary();
+ InitMockSystemLibrary();
}
void CrosInProcessBrowserTest::InitMockLibraryLoader() {
@@ -122,6 +125,14 @@ void CrosInProcessBrowserTest::InitMockSynapticsLibrary() {
test_api()->SetSynapticsLibrary(mock_synaptics_library_, true);
}
+void CrosInProcessBrowserTest::InitMockSystemLibrary() {
+ InitMockLibraryLoader();
+ if (mock_system_library_)
+ return;
+ mock_system_library_ = new MockSystemLibrary();
+ test_api()->SetSystemLibrary(mock_system_library_, true);
+}
+
void CrosInProcessBrowserTest::SetStatusAreaMocksExpectations() {
SetKeyboardLibraryStatusAreaExpectations();
SetInputMethodLibraryStatusAreaExpectations();
@@ -243,6 +254,13 @@ void CrosInProcessBrowserTest::SetSynapticsLibraryExpectations() {
.Times(AnyNumber());
}
+void CrosInProcessBrowserTest::SetSystemLibraryExpectations() {
+ EXPECT_CALL(*mock_system_library_, GetTimezone())
+ .Times(AnyNumber());
+ EXPECT_CALL(*mock_system_library_, SetTimezone(_))
+ .Times(AnyNumber());
+}
+
void CrosInProcessBrowserTest::TearDownInProcessBrowserTestFixture() {
// Prevent bogus gMock leak check from firing.
if (loader_)
@@ -261,6 +279,8 @@ void CrosInProcessBrowserTest::TearDownInProcessBrowserTestFixture() {
test_api()->SetScreenLockLibrary(NULL, false);
if (mock_synaptics_library_)
test_api()->SetSynapticsLibrary(NULL, false);
+ if (mock_system_library_)
+ test_api()->SetSystemLibrary(NULL, false);
}
} // namespace chromeos
diff --git a/chrome/browser/chromeos/cros/cros_in_process_browser_test.h b/chrome/browser/chromeos/cros/cros_in_process_browser_test.h
index f4ea70c..6806e14 100644
--- a/chrome/browser/chromeos/cros/cros_in_process_browser_test.h
+++ b/chrome/browser/chromeos/cros/cros_in_process_browser_test.h
@@ -21,6 +21,7 @@ class MockPowerLibrary;
class MockScreenLockLibrary;
class MockScreenLockLibrary;
class MockSynapticsLibrary;
+class MockSystemLibrary;
// Base class for Chromium OS tests wanting to bring up a browser in the
// unit test process and mock some parts of CrosLibrary. Once you mock part of
@@ -54,6 +55,7 @@ class CrosInProcessBrowserTest : public InProcessBrowserTest {
void InitMockPowerLibrary();
void InitMockScreenLockLibrary();
void InitMockSynapticsLibrary();
+ void InitMockSystemLibrary();
// This method setups corresponding expectations for basic mocks that
// are used by status area items.
@@ -69,6 +71,7 @@ class CrosInProcessBrowserTest : public InProcessBrowserTest {
void SetNetworkLibraryStatusAreaExpectations();
void SetPowerLibraryStatusAreaExpectations();
void SetSynapticsLibraryExpectations();
+ void SetSystemLibraryExpectations();
// Overriden for things you would normally override TearDown for.
virtual void TearDownInProcessBrowserTestFixture();
@@ -85,6 +88,7 @@ class CrosInProcessBrowserTest : public InProcessBrowserTest {
MockPowerLibrary* mock_power_library_;
MockScreenLockLibrary* mock_screen_lock_library_;
MockSynapticsLibrary* mock_synaptics_library_;
+ MockSystemLibrary* mock_system_library_;
ImePropertyList ime_properties_;
diff --git a/chrome/browser/chromeos/cros/cros_library.cc b/chrome/browser/chromeos/cros/cros_library.cc
index a99876b..e9b834d 100644
--- a/chrome/browser/chromeos/cros/cros_library.cc
+++ b/chrome/browser/chromeos/cros/cros_library.cc
@@ -16,6 +16,7 @@
#include "chrome/browser/chromeos/cros/speech_synthesis_library.h"
#include "chrome/browser/chromeos/cros/synaptics_library.h"
#include "chrome/browser/chromeos/cros/syslogs_library.h"
+#include "chrome/browser/chromeos/cros/system_library.h"
namespace chromeos {
@@ -31,6 +32,7 @@ CrosLibrary::CrosLibrary() : library_loader_(NULL),
speech_synthesis_lib_(NULL),
synaptics_lib_(NULL),
syslogs_lib_(NULL),
+ system_lib_(NULL),
own_library_loader_(true),
own_cryptohome_lib_(true),
own_keyboard_lib_(true),
@@ -43,6 +45,7 @@ CrosLibrary::CrosLibrary() : library_loader_(NULL),
own_speech_synthesis_lib_(true),
own_synaptics_lib_(true),
own_syslogs_lib_(true),
+ own_system_lib_(true),
loaded_(false),
load_error_(false),
test_api_(NULL) {
@@ -74,6 +77,8 @@ CrosLibrary::~CrosLibrary() {
delete synaptics_lib_;
if (own_syslogs_lib_)
delete syslogs_lib_;
+ if (own_system_lib_)
+ delete system_lib_;
delete test_api_;
}
@@ -148,6 +153,12 @@ SyslogsLibrary* CrosLibrary::GetSyslogsLibrary() {
return syslogs_lib_;
}
+SystemLibrary* CrosLibrary::GetSystemLibrary() {
+ if (!system_lib_)
+ system_lib_ = new SystemLibraryImpl();
+ return system_lib_;
+}
+
bool CrosLibrary::EnsureLoaded() {
if (!loaded_ && !load_error_) {
if (!library_loader_)
@@ -262,4 +273,12 @@ void CrosLibrary::TestApi::SetSyslogsLibrary(SyslogsLibrary* library,
library_->syslogs_lib_ = library;
}
+void CrosLibrary::TestApi::SetSystemLibrary(SystemLibrary* library,
+ bool own) {
+ if (library_->system_lib_)
+ delete library_->system_lib_;
+ library_->own_system_lib_ = own;
+ library_->system_lib_ = library;
+}
+
} // namespace chromeos
diff --git a/chrome/browser/chromeos/cros/cros_library.h b/chrome/browser/chromeos/cros/cros_library.h
index 68ce1b3..286e532 100644
--- a/chrome/browser/chromeos/cros/cros_library.h
+++ b/chrome/browser/chromeos/cros/cros_library.h
@@ -23,6 +23,7 @@ class ScreenLockLibrary;
class SpeechSynthesisLibrary;
class SynapticsLibrary;
class SyslogsLibrary;
+class SystemLibrary;
// This class handles access to sub-parts of ChromeOS library. it provides
// a level of indirection so individual libraries that it exposes can
@@ -61,6 +62,8 @@ class CrosLibrary {
void SetSynapticsLibrary(SynapticsLibrary* library, bool own);
// Setter for SyslogsLibrary.
void SetSyslogsLibrary(SyslogsLibrary* library, bool own);
+ // Setter for SystemLibrary.
+ void SetSystemLibrary(SystemLibrary* library, bool own);
private:
friend class CrosLibrary;
@@ -104,6 +107,9 @@ class CrosLibrary {
// This gets the singleton SyslogsLibrary.
SyslogsLibrary* GetSyslogsLibrary();
+ // This gets the singleton SystemLibrary.
+ SystemLibrary* GetSystemLibrary();
+
// Getter for Test API that gives access to internal members of this class.
TestApi* GetTestApi();
@@ -135,6 +141,7 @@ class CrosLibrary {
SpeechSynthesisLibrary* speech_synthesis_lib_;
SynapticsLibrary* synaptics_lib_;
SyslogsLibrary* syslogs_lib_;
+ SystemLibrary* system_lib_;
bool own_library_loader_;
bool own_cryptohome_lib_;
@@ -148,6 +155,7 @@ class CrosLibrary {
bool own_speech_synthesis_lib_;
bool own_synaptics_lib_;
bool own_syslogs_lib_;
+ bool own_system_lib_;
// True if libcros was successfully loaded.
bool loaded_;
diff --git a/chrome/browser/chromeos/cros/mock_system_library.h b/chrome/browser/chromeos/cros/mock_system_library.h
new file mode 100644
index 0000000..bbb8006
--- /dev/null
+++ b/chrome/browser/chromeos/cros/mock_system_library.h
@@ -0,0 +1,26 @@
+// Copyright (c) 2010 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_CROS_MOCK_SYSTEM_LIBRARY_H_
+#define CHROME_BROWSER_CHROMEOS_CROS_MOCK_SYSTEM_LIBRARY_H_
+
+#include "chrome/browser/chromeos/cros/system_library.h"
+#include "testing/gmock/include/gmock/gmock.h"
+
+namespace chromeos {
+
+class MockSystemLibrary : public SystemLibrary {
+ public:
+ MockSystemLibrary() {}
+ virtual ~MockSystemLibrary() {}
+ MOCK_METHOD1(AddObserver, void(Observer*));
+ MOCK_METHOD1(RemoveObserver, void(Observer*));
+ MOCK_METHOD0(GetTimezone, const icu::TimeZone&());
+ MOCK_METHOD1(SetTimezone, void(const icu::TimeZone*));
+};
+
+} // namespace chromeos
+
+#endif // CHROME_BROWSER_CHROMEOS_CROS_MOCK_SYSTEM_LIBRARY_H_
+
diff --git a/chrome/browser/chromeos/cros/system_library.cc b/chrome/browser/chromeos/cros/system_library.cc
new file mode 100644
index 0000000..7f528d1
--- /dev/null
+++ b/chrome/browser/chromeos/cros/system_library.cc
@@ -0,0 +1,55 @@
+// Copyright (c) 2010 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/cros/system_library.h"
+
+#include "base/utf_string_conversions.h"
+#include "chrome/browser/chromeos/cros/cros_library.h"
+
+namespace chromeos {
+
+SystemLibraryImpl::SystemLibraryImpl() {
+ std::string id = "US/Pacific";
+ if (CrosLibrary::Get()->EnsureLoaded()) {
+ std::string timezone_id = chromeos::GetTimezoneID();
+ if (timezone_id.empty()) {
+ LOG(ERROR) << "Got an empty string for timezone, default to " << id;
+ } else {
+ id = timezone_id;
+ }
+ }
+ icu::TimeZone* timezone =
+ icu::TimeZone::createTimeZone(icu::UnicodeString::fromUTF8(id));
+ timezone_.reset(timezone);
+ icu::TimeZone::setDefault(*timezone);
+ LOG(INFO) << "Timezone is " << id;
+}
+
+void SystemLibraryImpl::AddObserver(Observer* observer) {
+ observers_.AddObserver(observer);
+}
+
+void SystemLibraryImpl::RemoveObserver(Observer* observer) {
+ observers_.RemoveObserver(observer);
+}
+
+const icu::TimeZone& SystemLibraryImpl::GetTimezone() {
+ return *timezone_.get();
+}
+
+void SystemLibraryImpl::SetTimezone(const icu::TimeZone* timezone) {
+ timezone_.reset(timezone->clone());
+ if (CrosLibrary::Get()->EnsureLoaded()) {
+ icu::UnicodeString unicode;
+ timezone->getID(unicode);
+ std::string id;
+ UTF16ToUTF8(unicode.getBuffer(), unicode.length(), &id);
+ LOG(INFO) << "Setting timezone to " << id;
+ chromeos::SetTimezoneID(id);
+ }
+ icu::TimeZone::setDefault(*timezone);
+ FOR_EACH_OBSERVER(Observer, observers_, TimezoneChanged(*timezone));
+}
+
+} // namespace chromeos
diff --git a/chrome/browser/chromeos/cros/system_library.h b/chrome/browser/chromeos/cros/system_library.h
new file mode 100644
index 0000000..2347785
--- /dev/null
+++ b/chrome/browser/chromeos/cros/system_library.h
@@ -0,0 +1,59 @@
+// Copyright (c) 2010 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_CROS_SYSTEM_LIBRARY_H_
+#define CHROME_BROWSER_CHROMEOS_CROS_SYSTEM_LIBRARY_H_
+
+#include "base/observer_list.h"
+#include "base/scoped_ptr.h"
+#include "base/singleton.h"
+#include "third_party/cros/chromeos_system.h"
+#include "unicode/timezone.h"
+
+namespace chromeos {
+
+// This interface defines interaction with the ChromeOS system APIs.
+class SystemLibrary {
+ public:
+ class Observer {
+ public:
+ // Called when the timezone has changed. |timezone| is non-null.
+ virtual void TimezoneChanged(const icu::TimeZone& timezone) = 0;
+ };
+
+ virtual ~SystemLibrary() {}
+
+ virtual void AddObserver(Observer* observer) = 0;
+ virtual void RemoveObserver(Observer* observer) = 0;
+
+ // 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;
+};
+
+// This class handles the interaction with the ChromeOS syslogs APIs.
+class SystemLibraryImpl : public SystemLibrary {
+ public:
+ SystemLibraryImpl();
+ virtual ~SystemLibraryImpl() {}
+
+ // NetworkLibrary overrides.
+ virtual void AddObserver(Observer* observer);
+ virtual void RemoveObserver(Observer* observer);
+
+ virtual const icu::TimeZone& GetTimezone();
+ virtual void SetTimezone(const icu::TimeZone*);
+
+ private:
+ scoped_ptr<icu::TimeZone> timezone_;
+ ObserverList<Observer> observers_;
+
+ DISALLOW_COPY_AND_ASSIGN(SystemLibraryImpl);
+};
+
+} // namespace chromeos
+
+#endif // CHROME_BROWSER_CHROMEOS_CROS_SYSTEM_LIBRARY_H_
diff --git a/chrome/browser/chromeos/login/wizard_controller.cc b/chrome/browser/chromeos/login/wizard_controller.cc
index 5df2c4d..dd96148 100644
--- a/chrome/browser/chromeos/login/wizard_controller.cc
+++ b/chrome/browser/chromeos/login/wizard_controller.cc
@@ -17,6 +17,7 @@
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chromeos/cros/cros_library.h"
#include "chrome/browser/chromeos/cros/login_library.h"
+#include "chrome/browser/chromeos/cros/system_library.h"
#include "chrome/browser/chromeos/customization_document.h"
#include "chrome/browser/chromeos/login/account_screen.h"
#include "chrome/browser/chromeos/login/background_view.h"
@@ -34,7 +35,6 @@
#include "chrome/browser/profile_manager.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/notification_service.h"
-#include "chrome/common/pref_names.h"
#include "third_party/cros/chromeos_wm_ipc_enums.h"
#include "views/accelerator.h"
#include "views/painter.h"
@@ -618,11 +618,7 @@ void ShowLoginWizard(const std::string& first_screen_name,
if (!timezone_name.empty()) {
icu::TimeZone* timezone = icu::TimeZone::createTimeZone(
icu::UnicodeString::fromUTF8(timezone_name));
- icu::TimeZone::adoptDefault(timezone);
- // Save timezone to default profile preferences.
- PrefService* prefs = ProfileManager::GetDefaultProfile()->GetPrefs();
- prefs->SetString(prefs::kTimeZone, timezone_name);
- prefs->SavePersistentPrefs();
+ chromeos::CrosLibrary::Get()->GetSystemLibrary()->SetTimezone(timezone);
}
}
}
diff --git a/chrome/browser/chromeos/options/system_page_view.cc b/chrome/browser/chromeos/options/system_page_view.cc
index f9ff16d..f074889 100644
--- a/chrome/browser/chromeos/options/system_page_view.cc
+++ b/chrome/browser/chromeos/options/system_page_view.cc
@@ -10,6 +10,8 @@
#include "app/combobox_model.h"
#include "base/stl_util-inl.h"
#include "base/utf_string_conversions.h"
+#include "chrome/browser/chromeos/cros/cros_library.h"
+#include "chrome/browser/chromeos/cros/system_library.h"
#include "chrome/browser/chromeos/options/language_config_view.h"
#include "chrome/browser/chromeos/options/options_window_view.h"
#include "chrome/browser/pref_member.h"
@@ -30,20 +32,23 @@ namespace chromeos {
// Date/Time section for datetime settings
class DateTimeSection : public SettingsPageSection,
- public views::Combobox::Listener {
+ public views::Combobox::Listener,
+ public SystemLibrary::Observer {
public:
explicit DateTimeSection(Profile* profile);
- virtual ~DateTimeSection() {}
+ virtual ~DateTimeSection();
// Overridden from views::Combobox::Listener:
virtual void ItemChanged(views::Combobox* sender,
int prev_index,
int new_index);
+ // Overridden from SystemLibrary::Observer:
+ virtual void TimezoneChanged(const icu::TimeZone& timezone);
+
protected:
// SettingsPageSection overrides:
virtual void InitContents(GridLayout* layout);
- virtual void NotifyPrefChanged(const std::wstring* pref_name);
private:
// The combobox model for the list of timezones.
@@ -126,12 +131,8 @@ class DateTimeSection : public SettingsPageSection,
L"(GMT+%d) " : L"(GMT%d) "), hour_offset) + output;
}
- virtual std::string GetTimeZoneIDAt(int index) {
- icu::UnicodeString id;
- timezones_[index]->getID(id);
- std::string output;
- UTF16ToUTF8(id.getBuffer(), id.length(), &output);
- return output;
+ virtual icu::TimeZone* GetTimeZoneAt(int index) {
+ return timezones_[index];
}
private:
@@ -140,24 +141,23 @@ class DateTimeSection : public SettingsPageSection,
DISALLOW_COPY_AND_ASSIGN(TimezoneComboboxModel);
};
- // Selects the timezone.
- void SelectTimeZone(const std::string& id);
-
// TimeZone combobox model.
views::Combobox* timezone_combobox_;
// Controls for this section:
TimezoneComboboxModel timezone_combobox_model_;
- // Preferences for this section:
- StringPrefMember timezone_;
-
DISALLOW_COPY_AND_ASSIGN(DateTimeSection);
};
DateTimeSection::DateTimeSection(Profile* profile)
: SettingsPageSection(profile, IDS_OPTIONS_SETTINGS_SECTION_TITLE_DATETIME),
timezone_combobox_(NULL) {
+ CrosLibrary::Get()->GetSystemLibrary()->AddObserver(this);
+}
+
+DateTimeSection::~DateTimeSection() {
+ CrosLibrary::Get()->GetSystemLibrary()->RemoveObserver(this);
}
void DateTimeSection::ItemChanged(views::Combobox* sender,
@@ -165,7 +165,18 @@ void DateTimeSection::ItemChanged(views::Combobox* sender,
int new_index) {
if (new_index == prev_index)
return;
- timezone_.SetValue(timezone_combobox_model_.GetTimeZoneIDAt(new_index));
+
+ CrosLibrary::Get()->GetSystemLibrary()->SetTimezone(
+ timezone_combobox_model_.GetTimeZoneAt(new_index));
+}
+
+void DateTimeSection::TimezoneChanged(const icu::TimeZone& timezone) {
+ for (int i = 0; i < timezone_combobox_model_.GetItemCount(); i++) {
+ if (*timezone_combobox_model_.GetTimeZoneAt(i) == timezone) {
+ timezone_combobox_->SetSelectedItem(i);
+ return;
+ }
+ }
}
void DateTimeSection::InitContents(GridLayout* layout) {
@@ -178,24 +189,7 @@ void DateTimeSection::InitContents(GridLayout* layout) {
layout->AddView(timezone_combobox_);
layout->AddPaddingRow(0, kRelatedControlVerticalSpacing);
- // Init member prefs so we can update the controls if prefs change.
- timezone_.Init(prefs::kTimeZone, profile()->GetPrefs(), this);
-}
-
-void DateTimeSection::NotifyPrefChanged(const std::wstring* pref_name) {
- if (!pref_name || *pref_name == prefs::kTimeZone) {
- std::string timezone = timezone_.GetValue();
- SelectTimeZone(timezone);
- }
-}
-
-void DateTimeSection::SelectTimeZone(const std::string& id) {
- for (int i = 0; i < timezone_combobox_model_.GetItemCount(); i++) {
- if (timezone_combobox_model_.GetTimeZoneIDAt(i) == id) {
- timezone_combobox_->SetSelectedItem(i);
- return;
- }
- }
+ TimezoneChanged(CrosLibrary::Get()->GetSystemLibrary()->GetTimezone());
}
////////////////////////////////////////////////////////////////////////////////
diff --git a/chrome/browser/chromeos/preferences.cc b/chrome/browser/chromeos/preferences.cc
index 30251b0..f0ef37b 100644
--- a/chrome/browser/chromeos/preferences.cc
+++ b/chrome/browser/chromeos/preferences.cc
@@ -19,7 +19,6 @@ namespace chromeos {
// static
void Preferences::RegisterUserPrefs(PrefService* prefs) {
- prefs->RegisterStringPref(prefs::kTimeZone, "US/Pacific");
prefs->RegisterBooleanPref(prefs::kTapToClickEnabled, false);
prefs->RegisterBooleanPref(prefs::kAccessibilityEnabled, false);
prefs->RegisterBooleanPref(prefs::kVertEdgeScrollEnabled, false);
@@ -79,7 +78,6 @@ void Preferences::RegisterUserPrefs(PrefService* prefs) {
}
void Preferences::Init(PrefService* prefs) {
- timezone_.Init(prefs::kTimeZone, prefs, this);
tap_to_click_enabled_.Init(prefs::kTapToClickEnabled, prefs, this);
accessibility_enabled_.Init(prefs::kAccessibilityEnabled, prefs, this);
vert_edge_scroll_enabled_.Init(prefs::kVertEdgeScrollEnabled, prefs, this);
@@ -140,8 +138,6 @@ void Preferences::Observe(NotificationType type,
}
void Preferences::NotifyPrefChanged(const std::wstring* pref_name) {
- if (!pref_name || *pref_name == prefs::kTimeZone)
- SetTimeZone(timezone_.GetValue());
if (!pref_name || *pref_name == prefs::kTapToClickEnabled) {
CrosLibrary::Get()->GetSynapticsLibrary()->SetBoolParameter(
PARAM_BOOL_TAP_TO_CLICK,
@@ -259,12 +255,6 @@ void Preferences::NotifyPrefChanged(const std::wstring* pref_name) {
}
}
-void Preferences::SetTimeZone(const std::string& id) {
- icu::TimeZone* timezone = icu::TimeZone::createTimeZone(
- icu::UnicodeString::fromUTF8(id));
- icu::TimeZone::adoptDefault(timezone);
-}
-
void Preferences::SetLanguageConfigBoolean(const char* section,
const char* name,
bool value) {
diff --git a/chrome/browser/chromeos/preferences.h b/chrome/browser/chromeos/preferences.h
index 9f1770c..81c1f8c 100644
--- a/chrome/browser/chromeos/preferences.h
+++ b/chrome/browser/chromeos/preferences.h
@@ -18,7 +18,7 @@ namespace chromeos {
// The Preferences class handles Chrome OS preferences. When the class
// is first initialized, it will initialize the OS settings to what's stored in
-// the preferences. These include timezones, touchpad settings, etc.
+// the preferences. These include touchpad settings, etc.
// When the preferences change, we change the settings to reflect the new value.
class Preferences : public NotificationObserver {
public:
@@ -43,8 +43,6 @@ class Preferences : public NotificationObserver {
virtual void NotifyPrefChanged(const std::wstring* pref_name);
private:
- void SetTimeZone(const std::string& id);
-
// Writes boolean |value| to the input method (IBus) configuration daemon.
// |section| (e.g. "general") and |name| (e.g. "use_global_engine") should
// not be NULL.
@@ -76,7 +74,6 @@ class Preferences : public NotificationObserver {
const char* name,
const std::string& value);
- StringPrefMember timezone_;
BooleanPrefMember tap_to_click_enabled_;
BooleanPrefMember vert_edge_scroll_enabled_;
BooleanPrefMember accessibility_enabled_;
diff --git a/chrome/browser/chromeos/status/clock_menu_button.cc b/chrome/browser/chromeos/status/clock_menu_button.cc
index e714a10..9576490 100644
--- a/chrome/browser/chromeos/status/clock_menu_button.cc
+++ b/chrome/browser/chromeos/status/clock_menu_button.cc
@@ -10,6 +10,7 @@
#include "base/string_util.h"
#include "base/time.h"
#include "chrome/browser/browser.h"
+#include "chrome/browser/chromeos/cros/cros_library.h"
#include "chrome/browser/chromeos/status/status_area_host.h"
#include "chrome/browser/profile.h"
#include "chrome/common/pref_names.h"
@@ -26,6 +27,9 @@ const int kTimerSlopSeconds = 1;
ClockMenuButton::ClockMenuButton(StatusAreaHost* host)
: MenuButton(NULL, std::wstring(), this, false),
host_(host) {
+ // Add as SystemLibrary observer. We update the clock if timezone changes.
+ CrosLibrary::Get()->GetSystemLibrary()->AddObserver(this);
+
set_border(NULL);
SetFont(ResourceBundle::GetSharedInstance().GetFont(
ResourceBundle::BaseFont).DeriveFont(1, gfx::Font::BOLD));
@@ -33,10 +37,10 @@ ClockMenuButton::ClockMenuButton(StatusAreaHost* host)
SetShowHighlighted(false);
set_alignment(TextButton::ALIGN_RIGHT);
UpdateTextAndSetNextTimer();
- // Init member prefs so we can update the clock if prefs change.
- // This only works if we are within a browser and have a profile.
- if (host->GetProfile())
- timezone_.Init(prefs::kTimeZone, host->GetProfile()->GetPrefs(), this);
+}
+
+ClockMenuButton::~ClockMenuButton() {
+ CrosLibrary::Get()->GetSystemLibrary()->RemoveObserver(this);
}
void ClockMenuButton::UpdateTextAndSetNextTimer() {
@@ -111,19 +115,11 @@ void ClockMenuButton::ActivatedAt(int index) {
}
///////////////////////////////////////////////////////////////////////////////
-// ClockMenuButton, NotificationObserver implementation:
-
-void ClockMenuButton::Observe(NotificationType type,
- const NotificationSource& source,
- const NotificationDetails& details) {
- if (type == NotificationType::PREF_CHANGED) {
- const std::wstring* pref_name = Details<std::wstring>(details).ptr();
- if (!pref_name || *pref_name == prefs::kTimeZone) {
- UpdateText();
- }
- }
-}
+// ClockMenuButton, SystemLibrary::Observer implementation:
+void ClockMenuButton::TimezoneChanged(const icu::TimeZone& timezone) {
+ UpdateText();
+}
////////////////////////////////////////////////////////////////////////////////
// ClockMenuButton, views::ViewMenuDelegate implementation:
diff --git a/chrome/browser/chromeos/status/clock_menu_button.h b/chrome/browser/chromeos/status/clock_menu_button.h
index 5457bec..b5daa2c 100644
--- a/chrome/browser/chromeos/status/clock_menu_button.h
+++ b/chrome/browser/chromeos/status/clock_menu_button.h
@@ -7,7 +7,7 @@
#include "base/scoped_ptr.h"
#include "base/timer.h"
-#include "chrome/browser/pref_member.h"
+#include "chrome/browser/chromeos/cros/system_library.h"
#include "chrome/common/notification_observer.h"
#include "chrome/common/notification_service.h"
#include "unicode/calendar.h"
@@ -24,10 +24,10 @@ class StatusAreaHost;
class ClockMenuButton : public views::MenuButton,
public views::ViewMenuDelegate,
public menus::MenuModel,
- public NotificationObserver {
+ public SystemLibrary::Observer {
public:
explicit ClockMenuButton(StatusAreaHost* host);
- virtual ~ClockMenuButton() {}
+ virtual ~ClockMenuButton();
// menus::MenuModel implementation.
virtual bool HasIcons() const { return false; }
@@ -50,10 +50,8 @@ class ClockMenuButton : public views::MenuButton,
virtual void ActivatedAt(int index);
virtual void MenuWillShow() {}
- // Overridden from NotificationObserver:
- virtual void Observe(NotificationType type,
- const NotificationSource& source,
- const NotificationDetails& details);
+ // Overridden from SystemLibrary::Observer:
+ virtual void TimezoneChanged(const icu::TimeZone& timezone);
// Updates the time on the menu button. Can be called by host if timezone
// changes.
@@ -75,9 +73,6 @@ class ClockMenuButton : public views::MenuButton,
StatusAreaHost* host_;
- // Preferences for this section:
- StringPrefMember timezone_;
-
DISALLOW_COPY_AND_ASSIGN(ClockMenuButton);
};
diff --git a/chrome/browser/chromeos/status/clock_menu_button_browsertest.cc b/chrome/browser/chromeos/status/clock_menu_button_browsertest.cc
index cfaf61e..49cfcf3 100644
--- a/chrome/browser/chromeos/status/clock_menu_button_browsertest.cc
+++ b/chrome/browser/chromeos/status/clock_menu_button_browsertest.cc
@@ -7,6 +7,8 @@
#include "base/string_util.h"
#include "chrome/browser/browser.h"
#include "chrome/browser/browser_window.h"
+#include "chrome/browser/chromeos/cros/cros_library.h"
+#include "chrome/browser/chromeos/cros/system_library.h"
#include "chrome/browser/chromeos/frame/browser_view.h"
#include "chrome/browser/chromeos/status/browser_status_area_view.h"
#include "chrome/browser/chromeos/view_ids.h"
@@ -35,9 +37,9 @@ IN_PROC_BROWSER_TEST_F(ClockMenuButtonTest, TimezoneTest) {
ASSERT_TRUE(clock != NULL);
// Update timezone and make sure clock text changes.
std::wstring text_before = clock->text();
- StringPrefMember timezone;
- timezone.Init(prefs::kTimeZone, browser()->profile()->GetPrefs(), NULL);
- timezone.SetValue("Asia/Hong_Kong");
+ scoped_ptr<icu::TimeZone> timezone(icu::TimeZone::createTimeZone(
+ icu::UnicodeString::fromUTF8("Asia/Hong_Kong")));
+ CrosLibrary::Get()->GetSystemLibrary()->SetTimezone(timezone.get());
std::wstring text_after = clock->text();
EXPECT_NE(text_before, text_after);
}
diff --git a/chrome/browser/options_util.cc b/chrome/browser/options_util.cc
index b4c5c9a..17b064d 100644
--- a/chrome/browser/options_util.cc
+++ b/chrome/browser/options_util.cc
@@ -35,7 +35,6 @@ void OptionsUtil::ResetToDefaults(Profile* profile) {
prefs::kTLS1Enabled,
#endif
#if defined(OS_CHROMEOS)
- prefs::kTimeZone,
prefs::kTapToClickEnabled,
prefs::kVertEdgeScrollEnabled,
prefs::kTouchpadSpeedFactor,
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index 94e361f..9f3d353 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -379,6 +379,8 @@
'browser/chromeos/cros/synaptics_library.h',
'browser/chromeos/cros/syslogs_library.cc',
'browser/chromeos/cros/syslogs_library.h',
+ 'browser/chromeos/cros/system_library.cc',
+ 'browser/chromeos/cros/system_library.h',
'browser/chromeos/customization_document.cc',
'browser/chromeos/customization_document.h',
'browser/chromeos/dom_ui/system_options_handler.cc',
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi
index 69cef8d..62b6aa4 100644
--- a/chrome/chrome_tests.gypi
+++ b/chrome/chrome_tests.gypi
@@ -1511,6 +1511,7 @@
'browser/chromeos/cros/mock_power_library.h',
'browser/chromeos/cros/mock_speech_synthesis_library.h',
'browser/chromeos/cros/mock_synaptics_library.h',
+ 'browser/chromeos/cros/mock_system_library.h',
'browser/chromeos/login/account_screen_browsertest.cc',
'browser/chromeos/login/login_browsertest.cc',
'browser/chromeos/login/login_screen_browsertest.cc',
diff --git a/chrome/common/pref_names.cc b/chrome/common/pref_names.cc
index a12decc..3c8cd8d 100644
--- a/chrome/common/pref_names.cc
+++ b/chrome/common/pref_names.cc
@@ -178,9 +178,6 @@ const wchar_t kTLS1Enabled[] = L"ssl.tls1.enabled";
#endif
#if defined(OS_CHROMEOS)
-// A string pref set to the timezone.
-const wchar_t kTimeZone[] = L"settings.datetime.timezone";
-
// A boolean pref set to true if TapToClick is being done in browser.
const wchar_t kTapToClickEnabled[] = L"settings.touchpad.enable_tap_to_click";
diff --git a/chrome/common/pref_names.h b/chrome/common/pref_names.h
index 90593f9..6b0fbb5 100644
--- a/chrome/common/pref_names.h
+++ b/chrome/common/pref_names.h
@@ -68,7 +68,6 @@ extern const wchar_t kSSL3Enabled[];
extern const wchar_t kTLS1Enabled[];
#endif
#if defined(OS_CHROMEOS)
-extern const wchar_t kTimeZone[];
extern const wchar_t kTapToClickEnabled[];
extern const wchar_t kVertEdgeScrollEnabled[];
extern const wchar_t kTouchpadSpeedFactor[];