| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/cros/login_library.h" | 5 #include "chrome/browser/chromeos/cros/login_library.h" |
| 6 | 6 |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "base/timer.h" |
| 8 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 9 #include "chrome/browser/chromeos/cros/cros_library.h" | 10 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 10 #include "chrome/browser/chromeos/login/signed_settings_temp_storage.h" | 11 #include "chrome/browser/chromeos/login/signed_settings_temp_storage.h" |
| 11 #include "chrome/browser/prefs/pref_service.h" | 12 #include "chrome/browser/prefs/pref_service.h" |
| 12 #include "content/browser/browser_thread.h" | 13 #include "content/browser/browser_thread.h" |
| 14 #include "content/common/notification_observer.h" |
| 15 #include "content/common/notification_registrar.h" |
| 13 #include "content/common/notification_service.h" | 16 #include "content/common/notification_service.h" |
| 14 #include "content/common/notification_type.h" | 17 #include "content/common/notification_type.h" |
| 15 | 18 |
| 16 namespace chromeos { | 19 namespace chromeos { |
| 17 | 20 |
| 18 class LoginLibraryImpl : public LoginLibrary { | 21 class LoginLibraryImpl : public LoginLibrary { |
| 19 public: | 22 public: |
| 20 LoginLibraryImpl() | 23 LoginLibraryImpl() |
| 21 : set_owner_key_callback_(NULL), | 24 : set_owner_key_callback_(NULL), |
| 22 whitelist_op_callback_(NULL), | 25 whitelist_op_callback_(NULL), |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 bool StopSession(const std::string& unique_id /* unused */) { | 127 bool StopSession(const std::string& unique_id /* unused */) { |
| 125 // only pass unique_id through once we use it for something. | 128 // only pass unique_id through once we use it for something. |
| 126 return chromeos::StopSession(""); | 129 return chromeos::StopSession(""); |
| 127 } | 130 } |
| 128 | 131 |
| 129 bool RestartEntd() { | 132 bool RestartEntd() { |
| 130 return chromeos::RestartEntd(); | 133 return chromeos::RestartEntd(); |
| 131 } | 134 } |
| 132 | 135 |
| 133 bool RestartJob(int pid, const std::string& command_line) { | 136 bool RestartJob(int pid, const std::string& command_line) { |
| 134 if (g_browser_process && g_browser_process->local_state()) { | 137 job_restart_request_.reset(new JobRestartRequest(pid, command_line)); |
| 135 // XXX: normally this call must not be needed, however it turned out that | 138 return true; |
| 136 // without this explicit call to SavePersistentPrefs it is possible for | |
| 137 // preferences to be lost. See http://crosbug.com/13102 | |
| 138 g_browser_process->local_state()->SavePersistentPrefs(); | |
| 139 } | |
| 140 return chromeos::RestartJob(pid, command_line.c_str()); | |
| 141 } | 139 } |
| 142 | 140 |
| 143 private: | 141 private: |
| 142 class JobRestartRequest : public NotificationObserver { |
| 143 public: |
| 144 JobRestartRequest(int pid, const std::string& command_line) |
| 145 : pid_(pid), |
| 146 command_line_(command_line), |
| 147 local_state_(g_browser_process->local_state()) { |
| 148 if (local_state_) { |
| 149 notification_registrar_.Add(this, NotificationType::PREF_COMMITTED, |
| 150 Source<PrefService>(local_state_)); |
| 151 // XXX: normally this call must not be needed, however RestartJob |
| 152 // just kills us so settings may be lost. See http://crosbug.com/13102 |
| 153 local_state_->CommitPendingWrite(); |
| 154 timer_.Start( |
| 155 base::TimeDelta::FromSeconds(3), this, |
| 156 &JobRestartRequest::RestartJob); |
| 157 } else { |
| 158 RestartJob(); |
| 159 } |
| 160 } |
| 161 |
| 162 private: |
| 163 void RestartJob() { |
| 164 if (!chromeos::RestartJob(pid_, command_line_.c_str())) |
| 165 NOTREACHED(); |
| 166 } |
| 167 |
| 168 // NotificationObserver implementation. |
| 169 virtual void Observe(NotificationType type, |
| 170 const NotificationSource& source, |
| 171 const NotificationDetails& details) { |
| 172 if (local_state_ && |
| 173 type.value == NotificationType::PREF_COMMITTED && |
| 174 source == Source<PrefService>(local_state_)) { |
| 175 RestartJob(); |
| 176 } else { |
| 177 NOTREACHED(); |
| 178 } |
| 179 } |
| 180 |
| 181 int pid_; |
| 182 std::string command_line_; |
| 183 NotificationRegistrar notification_registrar_; |
| 184 PrefService* local_state_; |
| 185 base::OneShotTimer<JobRestartRequest> timer_; |
| 186 }; |
| 187 |
| 144 static void Handler(void* object, const OwnershipEvent& event) { | 188 static void Handler(void* object, const OwnershipEvent& event) { |
| 145 LoginLibraryImpl* self = static_cast<LoginLibraryImpl*>(object); | 189 LoginLibraryImpl* self = static_cast<LoginLibraryImpl*>(object); |
| 146 switch (event) { | 190 switch (event) { |
| 147 case SetKeySuccess: | 191 case SetKeySuccess: |
| 148 self->CompleteSetOwnerKey(true); | 192 self->CompleteSetOwnerKey(true); |
| 149 break; | 193 break; |
| 150 case SetKeyFailure: | 194 case SetKeyFailure: |
| 151 self->CompleteSetOwnerKey(false); | 195 self->CompleteSetOwnerKey(false); |
| 152 break; | 196 break; |
| 153 case WhitelistOpSuccess: | 197 case WhitelistOpSuccess: |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 } | 245 } |
| 202 | 246 |
| 203 void CompletePropertyOp(bool result) { | 247 void CompletePropertyOp(bool result) { |
| 204 if (property_op_callback_) { | 248 if (property_op_callback_) { |
| 205 property_op_callback_->OnComplete(result); | 249 property_op_callback_->OnComplete(result); |
| 206 property_op_callback_ = NULL; | 250 property_op_callback_ = NULL; |
| 207 } | 251 } |
| 208 } | 252 } |
| 209 | 253 |
| 210 chromeos::SessionConnection session_connection_; | 254 chromeos::SessionConnection session_connection_; |
| 255 scoped_ptr<JobRestartRequest> job_restart_request_; |
| 211 | 256 |
| 212 Delegate* set_owner_key_callback_; | 257 Delegate* set_owner_key_callback_; |
| 213 Delegate* whitelist_op_callback_; | 258 Delegate* whitelist_op_callback_; |
| 214 Delegate* property_op_callback_; | 259 Delegate* property_op_callback_; |
| 215 | 260 |
| 216 DISALLOW_COPY_AND_ASSIGN(LoginLibraryImpl); | 261 DISALLOW_COPY_AND_ASSIGN(LoginLibraryImpl); |
| 217 }; | 262 }; |
| 218 | 263 |
| 219 class LoginLibraryStubImpl : public LoginLibrary { | 264 class LoginLibraryStubImpl : public LoginLibrary { |
| 220 public: | 265 public: |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 | 323 |
| 279 // static | 324 // static |
| 280 LoginLibrary* LoginLibrary::GetImpl(bool stub) { | 325 LoginLibrary* LoginLibrary::GetImpl(bool stub) { |
| 281 if (stub) | 326 if (stub) |
| 282 return new LoginLibraryStubImpl(); | 327 return new LoginLibraryStubImpl(); |
| 283 else | 328 else |
| 284 return new LoginLibraryImpl(); | 329 return new LoginLibraryImpl(); |
| 285 } | 330 } |
| 286 | 331 |
| 287 } // namespace chromeos | 332 } // namespace chromeos |
| OLD | NEW |