| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "chrome/browser/chromeos/system/system_clock.h" | 5 #include "chrome/browser/chromeos/system/system_clock.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 } | 115 } |
| 116 case chrome::NOTIFICATION_SESSION_STARTED: { | 116 case chrome::NOTIFICATION_SESSION_STARTED: { |
| 117 OnActiveProfileChanged(ProfileManager::GetActiveUserProfile()); | 117 OnActiveProfileChanged(ProfileManager::GetActiveUserProfile()); |
| 118 break; | 118 break; |
| 119 } | 119 } |
| 120 default: | 120 default: |
| 121 NOTREACHED(); | 121 NOTREACHED(); |
| 122 } | 122 } |
| 123 } | 123 } |
| 124 | 124 |
| 125 void SystemClock::ActiveUserChanged(const user_manager::User* /*user*/) { | 125 void SystemClock::ActiveUserChanged(const user_manager::User* active_user) { |
| 126 UpdateClockType(); | 126 if (active_user && active_user->is_profile_created()) |
| 127 UpdateClockType(); |
| 127 } | 128 } |
| 128 | 129 |
| 129 void SystemClock::AddObserver(SystemClockObserver* observer) { | 130 void SystemClock::AddObserver(SystemClockObserver* observer) { |
| 130 observer_list_.AddObserver(observer); | 131 observer_list_.AddObserver(observer); |
| 131 } | 132 } |
| 132 | 133 |
| 133 void SystemClock::RemoveObserver(SystemClockObserver* observer) { | 134 void SystemClock::RemoveObserver(SystemClockObserver* observer) { |
| 134 observer_list_.RemoveObserver(observer); | 135 observer_list_.RemoveObserver(observer); |
| 135 } | 136 } |
| 136 | 137 |
| 137 void SystemClock::OnActiveProfileChanged(Profile* profile) { | 138 void SystemClock::OnActiveProfileChanged(Profile* profile) { |
| 138 user_profile_ = profile; | 139 user_profile_ = profile; |
| 139 PrefService* prefs = profile->GetPrefs(); | 140 PrefService* prefs = profile->GetPrefs(); |
| 140 user_pref_registrar_.reset(new PrefChangeRegistrar); | 141 user_pref_registrar_.reset(new PrefChangeRegistrar); |
| 141 user_pref_registrar_->Init(prefs); | 142 user_pref_registrar_->Init(prefs); |
| 142 user_pref_registrar_->Add( | 143 user_pref_registrar_->Add( |
| 143 prefs::kUse24HourClock, | 144 prefs::kUse24HourClock, |
| 144 base::Bind(&SystemClock::UpdateClockType, base::Unretained(this))); | 145 base::Bind(&SystemClock::UpdateClockType, base::Unretained(this))); |
| 146 UpdateClockType(); |
| 145 } | 147 } |
| 146 | 148 |
| 147 bool SystemClock::OnProfileDestroyed(Profile* profile) { | 149 bool SystemClock::OnProfileDestroyed(Profile* profile) { |
| 148 if (profile != user_profile_) | 150 if (profile != user_profile_) |
| 149 return false; | 151 return false; |
| 150 user_pref_registrar_.reset(); | 152 user_pref_registrar_.reset(); |
| 151 user_profile_ = NULL; | 153 user_profile_ = NULL; |
| 152 return true; | 154 return true; |
| 153 } | 155 } |
| 154 | 156 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 // This also works for enterprise-managed devices because they never have | 214 // This also works for enterprise-managed devices because they never have |
| 213 // a local owner. | 215 // a local owner. |
| 214 if (user_manager::UserManager::Get()->IsCurrentUserOwner()) | 216 if (user_manager::UserManager::Get()->IsCurrentUserOwner()) |
| 215 SetShouldUse24HourClock(ShouldUse24HourClock()); | 217 SetShouldUse24HourClock(ShouldUse24HourClock()); |
| 216 for (auto& observer : observer_list_) | 218 for (auto& observer : observer_list_) |
| 217 observer.OnSystemClockChanged(this); | 219 observer.OnSystemClockChanged(this); |
| 218 } | 220 } |
| 219 | 221 |
| 220 } // namespace system | 222 } // namespace system |
| 221 } // namespace chromeos | 223 } // namespace chromeos |
| OLD | NEW |