| Index: chrome/browser/chromeos/cros/system_library.cc
|
| diff --git a/chrome/browser/chromeos/cros/system_library.cc b/chrome/browser/chromeos/cros/system_library.cc
|
| index 7f528d1ce22c9cfedde6e9959158ff524b8662fc..e09172b3d39a68af0ccfa76ac35fc8476f5c962f 100644
|
| --- a/chrome/browser/chromeos/cros/system_library.cc
|
| +++ b/chrome/browser/chromeos/cros/system_library.cc
|
| @@ -9,47 +9,86 @@
|
|
|
| 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;
|
| +class SystemLibraryImpl : public SystemLibrary {
|
| + public:
|
| + 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;
|
| }
|
| - 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 AddObserver(Observer* observer) {
|
| + observers_.AddObserver(observer);
|
| + }
|
|
|
| -void SystemLibraryImpl::RemoveObserver(Observer* observer) {
|
| - observers_.RemoveObserver(observer);
|
| -}
|
| + void RemoveObserver(Observer* observer) {
|
| + observers_.RemoveObserver(observer);
|
| + }
|
|
|
| -const icu::TimeZone& SystemLibraryImpl::GetTimezone() {
|
| - return *timezone_.get();
|
| -}
|
| + const icu::TimeZone& GetTimezone() {
|
| + return *timezone_.get();
|
| + }
|
| +
|
| + void 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));
|
| + }
|
| +
|
| + private:
|
| + scoped_ptr<icu::TimeZone> timezone_;
|
| + ObserverList<Observer> observers_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(SystemLibraryImpl);
|
| +};
|
|
|
| -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);
|
| +class SystemLibraryStubImpl : public SystemLibrary {
|
| + public:
|
| + SystemLibraryStubImpl() {
|
| + std::string id = "US/Pacific";
|
| + icu::TimeZone* timezone =
|
| + icu::TimeZone::createTimeZone(icu::UnicodeString::fromUTF8(id));
|
| + timezone_.reset(timezone);
|
| }
|
| - icu::TimeZone::setDefault(*timezone);
|
| - FOR_EACH_OBSERVER(Observer, observers_, TimezoneChanged(*timezone));
|
| + ~SystemLibraryStubImpl() {}
|
| +
|
| + void AddObserver(Observer* observer) {}
|
| + void RemoveObserver(Observer* observer) {}
|
| + const icu::TimeZone& GetTimezone() {
|
| + return *timezone_.get();
|
| + }
|
| + void SetTimezone(const icu::TimeZone* timezone) {}
|
| +
|
| + private:
|
| + scoped_ptr<icu::TimeZone> timezone_;
|
| + DISALLOW_COPY_AND_ASSIGN(SystemLibraryStubImpl);
|
| +};
|
| +
|
| +// static
|
| +SystemLibrary* SystemLibrary::GetImpl(bool stub) {
|
| + if (stub)
|
| + return new SystemLibraryStubImpl();
|
| + else
|
| + return new SystemLibraryImpl();
|
| }
|
|
|
| } // namespace chromeos
|
|
|