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

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

Issue 1886913002: Convert //chrome/browser/metrics from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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
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 "chrome/browser/metrics/thread_watcher.h"
6
5 #include <math.h> 7 #include <math.h>
6 #include <stdint.h> 8 #include <stdint.h>
7 9
10 #include <memory>
11
8 #include "base/bind.h" 12 #include "base/bind.h"
9 #include "base/location.h" 13 #include "base/location.h"
10 #include "base/logging.h" 14 #include "base/logging.h"
11 #include "base/macros.h" 15 #include "base/macros.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/message_loop/message_loop.h" 16 #include "base/message_loop/message_loop.h"
14 #include "base/run_loop.h" 17 #include "base/run_loop.h"
15 #include "base/single_thread_task_runner.h" 18 #include "base/single_thread_task_runner.h"
16 #include "base/strings/string_number_conversions.h" 19 #include "base/strings/string_number_conversions.h"
17 #include "base/strings/string_split.h" 20 #include "base/strings/string_split.h"
18 #include "base/strings/string_tokenizer.h" 21 #include "base/strings/string_tokenizer.h"
19 #include "base/synchronization/condition_variable.h" 22 #include "base/synchronization/condition_variable.h"
20 #include "base/synchronization/lock.h" 23 #include "base/synchronization/lock.h"
21 #include "base/synchronization/spin_wait.h" 24 #include "base/synchronization/spin_wait.h"
22 #include "base/synchronization/waitable_event.h" 25 #include "base/synchronization/waitable_event.h"
23 #include "base/threading/platform_thread.h" 26 #include "base/threading/platform_thread.h"
24 #include "base/time/time.h" 27 #include "base/time/time.h"
25 #include "build/build_config.h" 28 #include "build/build_config.h"
26 #include "chrome/browser/metrics/thread_watcher.h"
27 #include "chrome/common/chrome_switches.h" 29 #include "chrome/common/chrome_switches.h"
28 #include "content/public/test/test_browser_thread.h" 30 #include "content/public/test/test_browser_thread.h"
29 #include "testing/gtest/include/gtest/gtest.h" 31 #include "testing/gtest/include/gtest/gtest.h"
30 #include "testing/platform_test.h" 32 #include "testing/platform_test.h"
31 33
32 using base::TimeDelta; 34 using base::TimeDelta;
33 using base::TimeTicks; 35 using base::TimeTicks;
34 using content::BrowserThread; 36 using content::BrowserThread;
35 37
36 enum State { 38 enum State {
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 db_thread_.reset(); 315 db_thread_.reset();
314 watchdog_thread_.reset(); 316 watchdog_thread_.reset();
315 thread_watcher_list_ = nullptr; 317 thread_watcher_list_ = nullptr;
316 } 318 }
317 319
318 private: 320 private:
319 base::MessageLoop message_loop_; 321 base::MessageLoop message_loop_;
320 base::Lock lock_; 322 base::Lock lock_;
321 base::ConditionVariable setup_complete_; 323 base::ConditionVariable setup_complete_;
322 bool initialized_; 324 bool initialized_;
323 scoped_ptr<content::TestBrowserThread> db_thread_; 325 std::unique_ptr<content::TestBrowserThread> db_thread_;
324 scoped_ptr<content::TestBrowserThread> io_thread_; 326 std::unique_ptr<content::TestBrowserThread> io_thread_;
325 scoped_ptr<WatchDogThread> watchdog_thread_; 327 std::unique_ptr<WatchDogThread> watchdog_thread_;
326 }; 328 };
327 329
328 // Define static constants. 330 // Define static constants.
329 const TimeDelta ThreadWatcherTest::kSleepTime = 331 const TimeDelta ThreadWatcherTest::kSleepTime =
330 TimeDelta::FromMilliseconds(50); 332 TimeDelta::FromMilliseconds(50);
331 const TimeDelta ThreadWatcherTest::kUnresponsiveTime = 333 const TimeDelta ThreadWatcherTest::kUnresponsiveTime =
332 TimeDelta::FromMilliseconds(500); 334 TimeDelta::FromMilliseconds(500);
333 const BrowserThread::ID ThreadWatcherTest::io_thread_id = BrowserThread::IO; 335 const BrowserThread::ID ThreadWatcherTest::io_thread_id = BrowserThread::IO;
334 const std::string ThreadWatcherTest::io_thread_name = "IO"; 336 const std::string ThreadWatcherTest::io_thread_name = "IO";
335 const BrowserThread::ID ThreadWatcherTest::db_thread_id = BrowserThread::DB; 337 const BrowserThread::ID ThreadWatcherTest::db_thread_id = BrowserThread::DB;
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
684 bool has_thread_watcher_list_; 686 bool has_thread_watcher_list_;
685 bool stopped_; 687 bool stopped_;
686 }; 688 };
687 689
688 TEST_F(ThreadWatcherListTest, Restart) { 690 TEST_F(ThreadWatcherListTest, Restart) {
689 ThreadWatcherList::g_initialize_delay_seconds = 1; 691 ThreadWatcherList::g_initialize_delay_seconds = 1;
690 692
691 base::MessageLoopForUI message_loop_for_ui; 693 base::MessageLoopForUI message_loop_for_ui;
692 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop_for_ui); 694 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop_for_ui);
693 695
694 scoped_ptr<WatchDogThread> watchdog_thread_(new WatchDogThread()); 696 std::unique_ptr<WatchDogThread> watchdog_thread_(new WatchDogThread());
695 watchdog_thread_->StartAndWaitForTesting(); 697 watchdog_thread_->StartAndWaitForTesting();
696 698
697 // See http://crbug.com/347887. 699 // See http://crbug.com/347887.
698 // StartWatchingAll() will PostDelayedTask to create g_thread_watcher_list_, 700 // StartWatchingAll() will PostDelayedTask to create g_thread_watcher_list_,
699 // whilst StopWatchingAll() will just PostTask to destroy it. 701 // whilst StopWatchingAll() will just PostTask to destroy it.
700 // Ensure that when Stop is called, Start will NOT create 702 // Ensure that when Stop is called, Start will NOT create
701 // g_thread_watcher_list_ later on. 703 // g_thread_watcher_list_ later on.
702 ThreadWatcherList::StartWatchingAll(*base::CommandLine::ForCurrentProcess()); 704 ThreadWatcherList::StartWatchingAll(*base::CommandLine::ForCurrentProcess());
703 ThreadWatcherList::StopWatchingAll(); 705 ThreadWatcherList::StopWatchingAll();
704 message_loop_for_ui.task_runner()->PostDelayedTask( 706 message_loop_for_ui.task_runner()->PostDelayedTask(
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
787 789
788 static void PostAndWaitForWatchdogThread(base::WaitableEvent* event) { 790 static void PostAndWaitForWatchdogThread(base::WaitableEvent* event) {
789 WatchDogThread::PostDelayedTask( 791 WatchDogThread::PostDelayedTask(
790 FROM_HERE, 792 FROM_HERE,
791 base::Bind(&JankTimeBombTest::OnJankTimeBombTask, event), 793 base::Bind(&JankTimeBombTest::OnJankTimeBombTask, event),
792 base::TimeDelta::FromSeconds(0)); 794 base::TimeDelta::FromSeconds(0));
793 795
794 event->Wait(); 796 event->Wait();
795 } 797 }
796 798
797 scoped_ptr<WatchDogThread> watchdog_thread_; 799 std::unique_ptr<WatchDogThread> watchdog_thread_;
798 800
799 DISALLOW_COPY_AND_ASSIGN(JankTimeBombTest); 801 DISALLOW_COPY_AND_ASSIGN(JankTimeBombTest);
800 }; 802 };
801 803
802 // JankTimeBomb minimal constructor/destructor test.. 804 // JankTimeBomb minimal constructor/destructor test..
803 TEST_F(JankTimeBombTest, StartShutdownTest) { 805 TEST_F(JankTimeBombTest, StartShutdownTest) {
804 // Disarm's itself when it goes out of scope. 806 // Disarm's itself when it goes out of scope.
805 TestingJankTimeBomb timebomb1(TimeDelta::FromMinutes(5)); 807 TestingJankTimeBomb timebomb1(TimeDelta::FromMinutes(5));
806 TestingJankTimeBomb timebomb2(TimeDelta::FromMinutes(5)); 808 TestingJankTimeBomb timebomb2(TimeDelta::FromMinutes(5));
807 WaitForWatchDogThreadPostTask(); 809 WaitForWatchDogThreadPostTask();
808 EXPECT_FALSE(timebomb1.alarm_invoked()); 810 EXPECT_FALSE(timebomb1.alarm_invoked());
809 EXPECT_FALSE(timebomb2.alarm_invoked()); 811 EXPECT_FALSE(timebomb2.alarm_invoked());
810 } 812 }
811 813
812 TEST_F(JankTimeBombTest, ArmTest) { 814 TEST_F(JankTimeBombTest, ArmTest) {
813 // Test firing of Alarm by passing empty delay. 815 // Test firing of Alarm by passing empty delay.
814 TestingJankTimeBomb timebomb((base::TimeDelta())); 816 TestingJankTimeBomb timebomb((base::TimeDelta()));
815 if (!timebomb.IsEnabled()) 817 if (!timebomb.IsEnabled())
816 return; 818 return;
817 WaitForWatchDogThreadPostTask(); 819 WaitForWatchDogThreadPostTask();
818 EXPECT_TRUE(timebomb.alarm_invoked()); 820 EXPECT_TRUE(timebomb.alarm_invoked());
819 } 821 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698