| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chromeos/settings/timezone_settings.h" | 5 #include "chromeos/settings/timezone_settings.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 | 293 |
| 294 // The TimezoneSettings implementation used in production. | 294 // The TimezoneSettings implementation used in production. |
| 295 class TimezoneSettingsImpl : public TimezoneSettingsBaseImpl { | 295 class TimezoneSettingsImpl : public TimezoneSettingsBaseImpl { |
| 296 public: | 296 public: |
| 297 // TimezoneSettings implementation: | 297 // TimezoneSettings implementation: |
| 298 void SetTimezone(const icu::TimeZone& timezone) override; | 298 void SetTimezone(const icu::TimeZone& timezone) override; |
| 299 | 299 |
| 300 static TimezoneSettingsImpl* GetInstance(); | 300 static TimezoneSettingsImpl* GetInstance(); |
| 301 | 301 |
| 302 private: | 302 private: |
| 303 friend struct DefaultSingletonTraits<TimezoneSettingsImpl>; | 303 friend struct base::DefaultSingletonTraits<TimezoneSettingsImpl>; |
| 304 | 304 |
| 305 TimezoneSettingsImpl(); | 305 TimezoneSettingsImpl(); |
| 306 | 306 |
| 307 DISALLOW_COPY_AND_ASSIGN(TimezoneSettingsImpl); | 307 DISALLOW_COPY_AND_ASSIGN(TimezoneSettingsImpl); |
| 308 }; | 308 }; |
| 309 | 309 |
| 310 // The stub TimezoneSettings implementation used on Linux desktop. | 310 // The stub TimezoneSettings implementation used on Linux desktop. |
| 311 class TimezoneSettingsStubImpl : public TimezoneSettingsBaseImpl { | 311 class TimezoneSettingsStubImpl : public TimezoneSettingsBaseImpl { |
| 312 public: | 312 public: |
| 313 // TimezoneSettings implementation: | 313 // TimezoneSettings implementation: |
| 314 void SetTimezone(const icu::TimeZone& timezone) override; | 314 void SetTimezone(const icu::TimeZone& timezone) override; |
| 315 | 315 |
| 316 static TimezoneSettingsStubImpl* GetInstance(); | 316 static TimezoneSettingsStubImpl* GetInstance(); |
| 317 | 317 |
| 318 private: | 318 private: |
| 319 friend struct DefaultSingletonTraits<TimezoneSettingsStubImpl>; | 319 friend struct base::DefaultSingletonTraits<TimezoneSettingsStubImpl>; |
| 320 | 320 |
| 321 TimezoneSettingsStubImpl(); | 321 TimezoneSettingsStubImpl(); |
| 322 | 322 |
| 323 DISALLOW_COPY_AND_ASSIGN(TimezoneSettingsStubImpl); | 323 DISALLOW_COPY_AND_ASSIGN(TimezoneSettingsStubImpl); |
| 324 }; | 324 }; |
| 325 | 325 |
| 326 TimezoneSettingsBaseImpl::~TimezoneSettingsBaseImpl() { | 326 TimezoneSettingsBaseImpl::~TimezoneSettingsBaseImpl() { |
| 327 STLDeleteElements(&timezones_); | 327 STLDeleteElements(&timezones_); |
| 328 } | 328 } |
| 329 | 329 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 // It's safe to change the timezone config files in the background as the | 380 // It's safe to change the timezone config files in the background as the |
| 381 // following operations don't depend on the completion of the config change. | 381 // following operations don't depend on the completion of the config change. |
| 382 base::WorkerPool::GetTaskRunner(true /* task is slow */)-> | 382 base::WorkerPool::GetTaskRunner(true /* task is slow */)-> |
| 383 PostTask(FROM_HERE, base::Bind(&SetTimezoneIDFromString, id)); | 383 PostTask(FROM_HERE, base::Bind(&SetTimezoneIDFromString, id)); |
| 384 icu::TimeZone::setDefault(*known_timezone); | 384 icu::TimeZone::setDefault(*known_timezone); |
| 385 FOR_EACH_OBSERVER(Observer, observers_, TimezoneChanged(*known_timezone)); | 385 FOR_EACH_OBSERVER(Observer, observers_, TimezoneChanged(*known_timezone)); |
| 386 } | 386 } |
| 387 | 387 |
| 388 // static | 388 // static |
| 389 TimezoneSettingsImpl* TimezoneSettingsImpl::GetInstance() { | 389 TimezoneSettingsImpl* TimezoneSettingsImpl::GetInstance() { |
| 390 return Singleton<TimezoneSettingsImpl, | 390 return base::Singleton< |
| 391 DefaultSingletonTraits<TimezoneSettingsImpl> >::get(); | 391 TimezoneSettingsImpl, |
| 392 base::DefaultSingletonTraits<TimezoneSettingsImpl>>::get(); |
| 392 } | 393 } |
| 393 | 394 |
| 394 TimezoneSettingsImpl::TimezoneSettingsImpl() { | 395 TimezoneSettingsImpl::TimezoneSettingsImpl() { |
| 395 std::string id = GetTimezoneIDAsString(); | 396 std::string id = GetTimezoneIDAsString(); |
| 396 if (id.empty()) { | 397 if (id.empty()) { |
| 397 id = kFallbackTimeZoneId; | 398 id = kFallbackTimeZoneId; |
| 398 LOG(ERROR) << "Got an empty string for timezone, default to '" << id; | 399 LOG(ERROR) << "Got an empty string for timezone, default to '" << id; |
| 399 } | 400 } |
| 400 | 401 |
| 401 timezone_.reset(icu::TimeZone::createTimeZone( | 402 timezone_.reset(icu::TimeZone::createTimeZone( |
| (...skipping 24 matching lines...) Expand all Loading... |
| 426 | 427 |
| 427 std::string id = base::UTF16ToUTF8(GetTimezoneID(*known_timezone)); | 428 std::string id = base::UTF16ToUTF8(GetTimezoneID(*known_timezone)); |
| 428 VLOG(1) << "Setting timezone to " << id; | 429 VLOG(1) << "Setting timezone to " << id; |
| 429 timezone_.reset(known_timezone->clone()); | 430 timezone_.reset(known_timezone->clone()); |
| 430 icu::TimeZone::setDefault(*known_timezone); | 431 icu::TimeZone::setDefault(*known_timezone); |
| 431 FOR_EACH_OBSERVER(Observer, observers_, TimezoneChanged(*known_timezone)); | 432 FOR_EACH_OBSERVER(Observer, observers_, TimezoneChanged(*known_timezone)); |
| 432 } | 433 } |
| 433 | 434 |
| 434 // static | 435 // static |
| 435 TimezoneSettingsStubImpl* TimezoneSettingsStubImpl::GetInstance() { | 436 TimezoneSettingsStubImpl* TimezoneSettingsStubImpl::GetInstance() { |
| 436 return Singleton<TimezoneSettingsStubImpl, | 437 return base::Singleton< |
| 437 DefaultSingletonTraits<TimezoneSettingsStubImpl> >::get(); | 438 TimezoneSettingsStubImpl, |
| 439 base::DefaultSingletonTraits<TimezoneSettingsStubImpl>>::get(); |
| 438 } | 440 } |
| 439 | 441 |
| 440 TimezoneSettingsStubImpl::TimezoneSettingsStubImpl() { | 442 TimezoneSettingsStubImpl::TimezoneSettingsStubImpl() { |
| 441 timezone_.reset(icu::TimeZone::createDefault()); | 443 timezone_.reset(icu::TimeZone::createDefault()); |
| 442 const icu::TimeZone* known_timezone = GetKnownTimezoneOrNull(*timezone_); | 444 const icu::TimeZone* known_timezone = GetKnownTimezoneOrNull(*timezone_); |
| 443 if (known_timezone != NULL && *known_timezone != *timezone_) | 445 if (known_timezone != NULL && *known_timezone != *timezone_) |
| 444 timezone_.reset(known_timezone->clone()); | 446 timezone_.reset(known_timezone->clone()); |
| 445 } | 447 } |
| 446 | 448 |
| 447 } // namespace | 449 } // namespace |
| (...skipping 14 matching lines...) Expand all Loading... |
| 462 | 464 |
| 463 // static | 465 // static |
| 464 base::string16 TimezoneSettings::GetTimezoneID(const icu::TimeZone& timezone) { | 466 base::string16 TimezoneSettings::GetTimezoneID(const icu::TimeZone& timezone) { |
| 465 icu::UnicodeString id; | 467 icu::UnicodeString id; |
| 466 timezone.getID(id); | 468 timezone.getID(id); |
| 467 return base::string16(id.getBuffer(), id.length()); | 469 return base::string16(id.getBuffer(), id.length()); |
| 468 } | 470 } |
| 469 | 471 |
| 470 } // namespace system | 472 } // namespace system |
| 471 } // namespace chromeos | 473 } // namespace chromeos |
| OLD | NEW |