summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos/cros/system_library.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/chromeos/cros/system_library.cc')
-rw-r--r--chrome/browser/chromeos/cros/system_library.cc55
1 files changed, 55 insertions, 0 deletions
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