| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/profiles/profile.h" | 5 #include "chrome/browser/profiles/profile.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
| 10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
| 11 #include "base/metrics/field_trial.h" | |
| 12 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
| 13 #include "base/sequenced_task_runner.h" | 12 #include "base/sequenced_task_runner.h" |
| 14 #include "base/synchronization/waitable_event.h" | 13 #include "base/synchronization/waitable_event.h" |
| 15 #include "base/values.h" | 14 #include "base/values.h" |
| 16 #include "base/version.h" | 15 #include "base/version.h" |
| 17 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
| 18 #include "chrome/browser/chrome_notification_types.h" | 17 #include "chrome/browser/chrome_notification_types.h" |
| 19 #include "chrome/browser/profiles/chrome_version_service.h" | 18 #include "chrome/browser/profiles/chrome_version_service.h" |
| 20 #include "chrome/browser/profiles/profile_impl.h" | 19 #include "chrome/browser/profiles/profile_impl.h" |
| 21 #include "chrome/browser/profiles/profile_manager.h" | 20 #include "chrome/browser/profiles/profile_manager.h" |
| (...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 // Make sure that the prefs file was written with the expected key/value. | 390 // Make sure that the prefs file was written with the expected key/value. |
| 392 ASSERT_EQ(GetExitTypePreferenceFromDisk(profile), "SessionEnded"); | 391 ASSERT_EQ(GetExitTypePreferenceFromDisk(profile), "SessionEnded"); |
| 393 | 392 |
| 394 // Mark the success. | 393 // Mark the success. |
| 395 succeeded = true; | 394 succeeded = true; |
| 396 } | 395 } |
| 397 | 396 |
| 398 ASSERT_TRUE(succeeded) << "profile->EndSession() timed out too often."; | 397 ASSERT_TRUE(succeeded) << "profile->EndSession() timed out too often."; |
| 399 } | 398 } |
| 400 | 399 |
| 401 IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, | |
| 402 EndSessionBrokenSynchronizationExperiment) { | |
| 403 base::ScopedTempDir temp_dir; | |
| 404 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | |
| 405 | |
| 406 // Select into the field trial group. | |
| 407 base::FieldTrialList::CreateFieldTrial("WindowsLogoffRace", | |
| 408 "BrokenSynchronization"); | |
| 409 | |
| 410 ProfileManager* profile_manager = g_browser_process->profile_manager(); | |
| 411 ASSERT_TRUE(profile_manager); | |
| 412 std::vector<Profile*> loaded_profiles = profile_manager->GetLoadedProfiles(); | |
| 413 | |
| 414 ASSERT_NE(loaded_profiles.size(), 0UL); | |
| 415 Profile* profile = loaded_profiles[0]; | |
| 416 | |
| 417 bool mis_wrote = false; | |
| 418 // This retry loop reduces flakiness due to the fact that this ultimately | |
| 419 // tests whether or not a code path hits a timed wait. | |
| 420 for (size_t retries = 0; retries < 3; ++retries) { | |
| 421 // Flush the profile data to disk for all loaded profiles. | |
| 422 profile->SetExitType(Profile::EXIT_CRASHED); | |
| 423 FlushTaskRunner(profile->GetIOTaskRunner().get()); | |
| 424 | |
| 425 // Make sure that the prefs file was written with the expected key/value. | |
| 426 ASSERT_EQ(GetExitTypePreferenceFromDisk(profile), "Crashed"); | |
| 427 | |
| 428 base::WaitableEvent is_blocked(false, false); | |
| 429 base::WaitableEvent* unblock = new base::WaitableEvent(false, false); | |
| 430 | |
| 431 // Block the profile's IO thread. | |
| 432 profile->GetIOTaskRunner()->PostTask(FROM_HERE, | |
| 433 base::Bind(&BlockThread, &is_blocked, base::Owned(unblock))); | |
| 434 // Wait for the IO thread to actually be blocked. | |
| 435 is_blocked.Wait(); | |
| 436 | |
| 437 // The blocking wait in EndSession has a timeout, so a non-write can only be | |
| 438 // concluded if it happens in less time than the timeout. | |
| 439 base::Time start = base::Time::Now(); | |
| 440 | |
| 441 // With the broken synchronization this is expected to return without | |
| 442 // blocking for the Profile's IO thread. | |
| 443 g_browser_process->EndSession(); | |
| 444 | |
| 445 base::Time end = base::Time::Now(); | |
| 446 | |
| 447 // The EndSession timeout is 10 seconds, we take a 5 second run-through as | |
| 448 // sufficient proof that we didn't hit the timed wait. | |
| 449 if (end - start < base::TimeDelta::FromSeconds(5)) { | |
| 450 // Make sure that the prefs file is unmodified with the expected | |
| 451 // key/value. | |
| 452 EXPECT_EQ(GetExitTypePreferenceFromDisk(profile), "Crashed"); | |
| 453 mis_wrote = true; | |
| 454 } | |
| 455 | |
| 456 // Release the IO thread thread. | |
| 457 unblock->Signal(); | |
| 458 } | |
| 459 | |
| 460 ASSERT_TRUE(mis_wrote); | |
| 461 } | |
| 462 | |
| 463 #endif // defined(USE_X11) || defined(OS_WIN) | 400 #endif // defined(USE_X11) || defined(OS_WIN) |
| OLD | NEW |