| 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/task.h" |
| 9 #include "base/timer.h" |
| 8 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| 9 #include "chrome/browser/chromeos/cros/cros_library.h" | 11 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 10 #include "chrome/browser/chromeos/login/signed_settings_temp_storage.h" | 12 #include "chrome/browser/chromeos/login/signed_settings_temp_storage.h" |
| 11 #include "chrome/browser/prefs/pref_service.h" | 13 #include "chrome/browser/prefs/pref_service.h" |
| 12 #include "content/browser/browser_thread.h" | 14 #include "content/browser/browser_thread.h" |
| 13 #include "content/common/notification_service.h" | 15 #include "content/common/notification_service.h" |
| 14 #include "content/common/notification_type.h" | 16 #include "content/common/notification_type.h" |
| 15 | 17 |
| 16 namespace chromeos { | 18 namespace chromeos { |
| 17 | 19 |
| 18 class LoginLibraryImpl : public LoginLibrary { | 20 class LoginLibraryImpl : public LoginLibrary { |
| 19 public: | 21 public: |
| 20 LoginLibraryImpl() | 22 LoginLibraryImpl() |
| 21 : set_owner_key_callback_(NULL), | 23 : job_restart_request_(NULL), |
| 24 set_owner_key_callback_(NULL), |
| 22 whitelist_op_callback_(NULL), | 25 whitelist_op_callback_(NULL), |
| 23 property_op_callback_(NULL) { | 26 property_op_callback_(NULL) { |
| 24 if (CrosLibrary::Get()->EnsureLoaded()) | 27 if (CrosLibrary::Get()->EnsureLoaded()) |
| 25 Init(); | 28 Init(); |
| 26 } | 29 } |
| 30 |
| 27 virtual ~LoginLibraryImpl() { | 31 virtual ~LoginLibraryImpl() { |
| 28 if (session_connection_) { | 32 if (session_connection_) { |
| 29 chromeos::DisconnectSession(session_connection_); | 33 chromeos::DisconnectSession(session_connection_); |
| 30 } | 34 } |
| 31 } | 35 } |
| 32 | 36 |
| 33 bool EmitLoginPromptReady() { | 37 bool EmitLoginPromptReady() { |
| 34 return chromeos::EmitLoginPromptReady(); | 38 return chromeos::EmitLoginPromptReady(); |
| 35 } | 39 } |
| 36 | 40 |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 bool StopSession(const std::string& unique_id /* unused */) { | 128 bool StopSession(const std::string& unique_id /* unused */) { |
| 125 // only pass unique_id through once we use it for something. | 129 // only pass unique_id through once we use it for something. |
| 126 return chromeos::StopSession(""); | 130 return chromeos::StopSession(""); |
| 127 } | 131 } |
| 128 | 132 |
| 129 bool RestartEntd() { | 133 bool RestartEntd() { |
| 130 return chromeos::RestartEntd(); | 134 return chromeos::RestartEntd(); |
| 131 } | 135 } |
| 132 | 136 |
| 133 bool RestartJob(int pid, const std::string& command_line) { | 137 bool RestartJob(int pid, const std::string& command_line) { |
| 134 if (g_browser_process && g_browser_process->local_state()) { | 138 if (job_restart_request_) { |
| 135 // XXX: normally this call must not be needed, however it turned out that | 139 NOTREACHED(); |
| 136 // without this explicit call to SavePersistentPrefs it is possible for | 140 return false; |
| 137 // preferences to be lost. See http://crosbug.com/13102 | |
| 138 g_browser_process->local_state()->SavePersistentPrefs(); | |
| 139 } | 141 } |
| 140 return chromeos::RestartJob(pid, command_line.c_str()); | 142 job_restart_request_ = new JobRestartRequest(pid, command_line); |
| 143 return true; |
| 141 } | 144 } |
| 142 | 145 |
| 143 private: | 146 private: |
| 147 class JobRestartRequest |
| 148 : public base::RefCountedThreadSafe<JobRestartRequest> { |
| 149 public: |
| 150 JobRestartRequest(int pid, const std::string& command_line) |
| 151 : pid_(pid), |
| 152 command_line_(command_line), |
| 153 local_state_(g_browser_process->local_state()) { |
| 154 AddRef(); |
| 155 if (local_state_) { |
| 156 // XXX: normally this call must not be needed, however RestartJob |
| 157 // just kills us so settings may be lost. See http://crosbug.com/13102 |
| 158 local_state_->CommitPendingWrite(); |
| 159 timer_.Start( |
| 160 base::TimeDelta::FromSeconds(3), this, |
| 161 &JobRestartRequest::RestartJob); |
| 162 // Post task on file thread thus it occurs last on task queue, so it |
| 163 // would be executed after committing pending write on file thread. |
| 164 BrowserThread::PostTask( |
| 165 BrowserThread::FILE, FROM_HERE, |
| 166 NewRunnableMethod(this, &JobRestartRequest::RestartJob)); |
| 167 } else { |
| 168 RestartJob(); |
| 169 } |
| 170 } |
| 171 |
| 172 private: |
| 173 void RestartJob() { |
| 174 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 175 if (!chromeos::RestartJob(pid_, command_line_.c_str())) |
| 176 NOTREACHED(); |
| 177 } else { |
| 178 BrowserThread::PostTask( |
| 179 BrowserThread::UI, FROM_HERE, |
| 180 NewRunnableMethod(this, &JobRestartRequest::RestartJob)); |
| 181 MessageLoop::current()->AssertIdle(); |
| 182 } |
| 183 } |
| 184 |
| 185 int pid_; |
| 186 std::string command_line_; |
| 187 PrefService* local_state_; |
| 188 base::OneShotTimer<JobRestartRequest> timer_; |
| 189 }; |
| 190 |
| 144 static void Handler(void* object, const OwnershipEvent& event) { | 191 static void Handler(void* object, const OwnershipEvent& event) { |
| 145 LoginLibraryImpl* self = static_cast<LoginLibraryImpl*>(object); | 192 LoginLibraryImpl* self = static_cast<LoginLibraryImpl*>(object); |
| 146 switch (event) { | 193 switch (event) { |
| 147 case SetKeySuccess: | 194 case SetKeySuccess: |
| 148 self->CompleteSetOwnerKey(true); | 195 self->CompleteSetOwnerKey(true); |
| 149 break; | 196 break; |
| 150 case SetKeyFailure: | 197 case SetKeyFailure: |
| 151 self->CompleteSetOwnerKey(false); | 198 self->CompleteSetOwnerKey(false); |
| 152 break; | 199 break; |
| 153 case WhitelistOpSuccess: | 200 case WhitelistOpSuccess: |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 } | 248 } |
| 202 | 249 |
| 203 void CompletePropertyOp(bool result) { | 250 void CompletePropertyOp(bool result) { |
| 204 if (property_op_callback_) { | 251 if (property_op_callback_) { |
| 205 property_op_callback_->OnComplete(result); | 252 property_op_callback_->OnComplete(result); |
| 206 property_op_callback_ = NULL; | 253 property_op_callback_ = NULL; |
| 207 } | 254 } |
| 208 } | 255 } |
| 209 | 256 |
| 210 chromeos::SessionConnection session_connection_; | 257 chromeos::SessionConnection session_connection_; |
| 258 JobRestartRequest* job_restart_request_; |
| 211 | 259 |
| 212 Delegate* set_owner_key_callback_; | 260 Delegate* set_owner_key_callback_; |
| 213 Delegate* whitelist_op_callback_; | 261 Delegate* whitelist_op_callback_; |
| 214 Delegate* property_op_callback_; | 262 Delegate* property_op_callback_; |
| 215 | 263 |
| 216 DISALLOW_COPY_AND_ASSIGN(LoginLibraryImpl); | 264 DISALLOW_COPY_AND_ASSIGN(LoginLibraryImpl); |
| 217 }; | 265 }; |
| 218 | 266 |
| 219 class LoginLibraryStubImpl : public LoginLibrary { | 267 class LoginLibraryStubImpl : public LoginLibrary { |
| 220 public: | 268 public: |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 | 326 |
| 279 // static | 327 // static |
| 280 LoginLibrary* LoginLibrary::GetImpl(bool stub) { | 328 LoginLibrary* LoginLibrary::GetImpl(bool stub) { |
| 281 if (stub) | 329 if (stub) |
| 282 return new LoginLibraryStubImpl(); | 330 return new LoginLibraryStubImpl(); |
| 283 else | 331 else |
| 284 return new LoginLibraryImpl(); | 332 return new LoginLibraryImpl(); |
| 285 } | 333 } |
| 286 | 334 |
| 287 } // namespace chromeos | 335 } // namespace chromeos |
| OLD | NEW |