Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: trunk/src/chrome/browser/metrics/thread_watcher_unittest.cc

Issue 188643006: Revert 255322 "ThreadWatcher: fixes Start/StopWatchingAll." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « trunk/src/chrome/browser/metrics/thread_watcher.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <math.h> 5 #include <math.h>
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "base/message_loop/message_loop_proxy.h" 12 #include "base/message_loop/message_loop_proxy.h"
13 #include "base/run_loop.h"
14 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
15 #include "base/strings/string_split.h" 14 #include "base/strings/string_split.h"
16 #include "base/strings/string_tokenizer.h" 15 #include "base/strings/string_tokenizer.h"
17 #include "base/synchronization/condition_variable.h" 16 #include "base/synchronization/condition_variable.h"
18 #include "base/synchronization/lock.h" 17 #include "base/synchronization/lock.h"
19 #include "base/threading/platform_thread.h" 18 #include "base/threading/platform_thread.h"
20 #include "base/time/time.h" 19 #include "base/time/time.h"
21 #include "build/build_config.h" 20 #include "build/build_config.h"
22 #include "chrome/browser/metrics/thread_watcher.h" 21 #include "chrome/browser/metrics/thread_watcher.h"
23 #include "chrome/common/chrome_switches.h" 22 #include "chrome/common/chrome_switches.h"
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 base::Bind(&ThreadWatcher::DeActivateThreadWatching, 622 base::Bind(&ThreadWatcher::DeActivateThreadWatching,
624 base::Unretained(io_watcher_))); 623 base::Unretained(io_watcher_)));
625 WatchDogThread::PostTask( 624 WatchDogThread::PostTask(
626 FROM_HERE, 625 FROM_HERE,
627 base::Bind(&ThreadWatcher::DeActivateThreadWatching, 626 base::Bind(&ThreadWatcher::DeActivateThreadWatching,
628 base::Unretained(db_watcher_))); 627 base::Unretained(db_watcher_)));
629 628
630 // Wait for the io_watcher_'s VeryLongMethod to finish. 629 // Wait for the io_watcher_'s VeryLongMethod to finish.
631 io_watcher_->WaitForWaitStateChange(kUnresponsiveTime * 10, ALL_DONE); 630 io_watcher_->WaitForWaitStateChange(kUnresponsiveTime * 10, ALL_DONE);
632 } 631 }
633
634 TEST(ThreadWatcherListTest, Restart) {
635 ThreadWatcherList::g_initialize_delay_seconds = 1;
636
637 base::MessageLoopForUI message_loop_for_ui;
638 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop_for_ui);
639
640 scoped_ptr<WatchDogThread> watchdog_thread_(new WatchDogThread());
641 watchdog_thread_->Start();
642
643 EXPECT_FALSE(ThreadWatcherList::g_thread_watcher_list_);
644
645 // See http://crbug.com/347887.
646 // StartWatchingAll() will PostDelayedTask to create g_thread_watcher_list_,
647 // whilst StopWatchingAll() will just PostTask to destroy it.
648 // Ensure that when Stop is called, Start will NOT create
649 // g_thread_watcher_list_ later on.
650 ThreadWatcherList::StartWatchingAll(*CommandLine::ForCurrentProcess());
651 ThreadWatcherList::StopWatchingAll();
652 message_loop_for_ui.PostDelayedTask(
653 FROM_HERE,
654 message_loop_for_ui.QuitClosure(),
655 base::TimeDelta::FromSeconds(
656 ThreadWatcherList::g_initialize_delay_seconds));
657 message_loop_for_ui.Run();
658 EXPECT_FALSE(ThreadWatcherList::g_thread_watcher_list_);
659 EXPECT_TRUE(ThreadWatcherList::g_stopped_);
660
661 // Proceed with just |StartWatchingAll| and ensure it'll be started.
662 ThreadWatcherList::StartWatchingAll(*CommandLine::ForCurrentProcess());
663 message_loop_for_ui.PostDelayedTask(
664 FROM_HERE,
665 message_loop_for_ui.QuitClosure(),
666 base::TimeDelta::FromSeconds(
667 ThreadWatcherList::g_initialize_delay_seconds + 1));
668 message_loop_for_ui.Run();
669 EXPECT_TRUE(ThreadWatcherList::g_thread_watcher_list_);
670 EXPECT_FALSE(ThreadWatcherList::g_stopped_);
671
672 // Finally, StopWatchingAll() must stop.
673 ThreadWatcherList::StopWatchingAll();
674 message_loop_for_ui.PostDelayedTask(
675 FROM_HERE,
676 message_loop_for_ui.QuitClosure(),
677 base::TimeDelta::FromSeconds(
678 ThreadWatcherList::g_initialize_delay_seconds));
679 message_loop_for_ui.Run();
680 EXPECT_FALSE(ThreadWatcherList::g_thread_watcher_list_);
681 EXPECT_TRUE(ThreadWatcherList::g_stopped_);
682 }
OLDNEW
« no previous file with comments | « trunk/src/chrome/browser/metrics/thread_watcher.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698