diff options
-rw-r--r-- | base/thread.cc | 3 | ||||
-rw-r--r-- | base/thread_unittest.cc | 2 | ||||
-rw-r--r-- | chrome/browser/printing/print_job.cc | 12 | ||||
-rw-r--r-- | chrome/browser/printing/print_job.h | 9 | ||||
-rw-r--r-- | chrome/browser/printing/print_job_unittest.cc | 117 | ||||
-rw-r--r-- | chrome/renderer/render_view.cc | 1 | ||||
-rw-r--r-- | chrome/test/unit/unit_tests.scons | 1 | ||||
-rw-r--r-- | chrome/test/unit/unittests.vcproj | 4 |
8 files changed, 6 insertions, 143 deletions
diff --git a/base/thread.cc b/base/thread.cc index 9bc81a4..fd076a4 100644 --- a/base/thread.cc +++ b/base/thread.cc @@ -131,6 +131,9 @@ void Thread::StopSoon() { DCHECK(message_loop_); message_loop_->PostTask(FROM_HERE, new ThreadQuitTask()); + + // The thread can't receive messages anymore. + message_loop_ = NULL; } void Thread::ThreadMain() { diff --git a/base/thread_unittest.cc b/base/thread_unittest.cc index f11cb8d..c1971c2 100644 --- a/base/thread_unittest.cc +++ b/base/thread_unittest.cc @@ -97,8 +97,8 @@ TEST_F(ThreadTest, StopSoon) { EXPECT_TRUE(a.Start()); EXPECT_TRUE(a.message_loop()); a.StopSoon(); + EXPECT_FALSE(a.message_loop()); a.StopSoon(); - a.Stop(); EXPECT_FALSE(a.message_loop()); } diff --git a/chrome/browser/printing/print_job.cc b/chrome/browser/printing/print_job.cc index 14a487cd..a2d07fd 100644 --- a/chrome/browser/printing/print_job.cc +++ b/chrome/browser/printing/print_job.cc @@ -24,8 +24,6 @@ PrintJob::PrintJob(PrintedPagesSource* source) is_job_pending_(false), is_print_dialog_box_shown_(false), is_canceling_(false) { - DCHECK(ui_message_loop_); - ui_message_loop_->AddDestructionObserver(this); } PrintJob::PrintJob() @@ -36,18 +34,14 @@ PrintJob::PrintJob() is_job_pending_(false), is_print_dialog_box_shown_(false), is_canceling_(false) { - DCHECK(ui_message_loop_); - ui_message_loop_->AddDestructionObserver(this); } PrintJob::~PrintJob() { - ui_message_loop_->RemoveDestructionObserver(this); // The job should be finished (or at least canceled) when it is destroyed. DCHECK(!is_job_pending_); DCHECK(!is_print_dialog_box_shown_); DCHECK(!is_canceling_); - if (worker_.get()) - DCHECK(worker_->message_loop() == NULL); + DCHECK(worker_->message_loop() == NULL); DCHECK_EQ(ui_message_loop_, MessageLoop::current()); } @@ -148,10 +142,6 @@ int PrintJob::cookie() const { return document_->cookie(); } -void PrintJob::WillDestroyCurrentMessageLoop() { - NOTREACHED(); -} - void PrintJob::GetSettings(GetSettingsAskParam ask_user_for_settings, HWND parent_window) { DCHECK_EQ(ui_message_loop_, MessageLoop::current()); diff --git a/chrome/browser/printing/print_job.h b/chrome/browser/printing/print_job.h index 4c334b9..e18d52c 100644 --- a/chrome/browser/printing/print_job.h +++ b/chrome/browser/printing/print_job.h @@ -5,7 +5,6 @@ #ifndef CHROME_BROWSER_PRINTING_PRINT_JOB_H_ #define CHROME_BROWSER_PRINTING_PRINT_JOB_H_ -#include "base/message_loop.h" #include "base/ref_counted.h" #include "chrome/browser/printing/print_job_worker_owner.h" #include "chrome/common/notification_service.h" @@ -33,8 +32,7 @@ class PrinterQuery; // runs in the UI thread. class PrintJob : public base::RefCountedThreadSafe<PrintJob>, public NotificationObserver, - public PrintJobWorkerOwner, - public MessageLoop::DestructionObserver { + public PrintJobWorkerOwner { public: // GetSettings() UI parameter. enum GetSettingsAskParam { @@ -50,8 +48,6 @@ class PrintJob : public base::RefCountedThreadSafe<PrintJob>, PrintJob(); virtual ~PrintJob(); - // Grabs the ownership of the PrintJobWorker from another job, which is - // usually a PrinterQuery. void Initialize(PrintJobWorkerOwner* job, PrintedPagesSource* source); // NotificationObserver @@ -73,9 +69,6 @@ class PrintJob : public base::RefCountedThreadSafe<PrintJob>, virtual const PrintSettings& settings() const { return settings_; } virtual int cookie() const; - // DestructionObserver - virtual void WillDestroyCurrentMessageLoop(); - // Initializes the printing context. This can be done synchronously or not. It // is fine to call this function multiple times to reinitialize the settings. // |parent_window| parameter will be the owner of the print setting dialog diff --git a/chrome/browser/printing/print_job_unittest.cc b/chrome/browser/printing/print_job_unittest.cc deleted file mode 100644 index 6c65a5d..0000000 --- a/chrome/browser/printing/print_job_unittest.cc +++ /dev/null @@ -1,117 +0,0 @@ -// Copyright (c) 2008 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "base/message_loop.h" -#include "chrome/browser/printing/print_job.h" -#include "chrome/browser/printing/printed_pages_source.h" -#include "googleurl/src/gurl.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace { - -class TestSource : public printing::PrintedPagesSource { - public: - virtual void RenderOnePrintedPage(printing::PrintedDocument* document, - int page_number) { - } - virtual std::wstring RenderSourceName() { - return L""; - } - virtual GURL RenderSourceUrl() { - return GURL(); - } -}; - -class TestPrintJob : public printing::PrintJob { - public: - TestPrintJob(printing::PrintedPagesSource* source, volatile bool* check) - : printing::PrintJob(source), check_(check) { - } - TestPrintJob(volatile bool* check) : check_(check) { - } - ~TestPrintJob() { - *check_ = true; - } - private: - volatile bool* check_; -}; - -class TestPrintNotifObserv : public NotificationObserver { - public: - // NotificationObserver - virtual void Observe(NotificationType type, - const NotificationSource& source, - const NotificationDetails& details) { - ASSERT_EQ(NOTIFY_PRINT_JOB_EVENT, type); - printing::JobEventDetails::Type event_type = - Details<printing::JobEventDetails>(details)->type(); - EXPECT_NE(printing::JobEventDetails::NEW_DOC, event_type); - EXPECT_NE(printing::JobEventDetails::NEW_PAGE, event_type); - EXPECT_NE(printing::JobEventDetails::PAGE_DONE, event_type); - EXPECT_NE(printing::JobEventDetails::DOC_DONE, event_type); - EXPECT_NE(printing::JobEventDetails::JOB_DONE, event_type); - EXPECT_NE(printing::JobEventDetails::ALL_PAGES_REQUESTED, event_type); - if (event_type == printing::JobEventDetails::USER_INIT_DONE || - event_type == printing::JobEventDetails::USER_INIT_CANCELED || - event_type == printing::JobEventDetails::DEFAULT_INIT_DONE || - event_type == printing::JobEventDetails::FAILED) { - MessageLoop::current()->Quit(); - return; - } - } -}; - -} // namespace - -TEST(PrintJobTest, SimplePrint) { - // Test the multithreaded nature of PrintJob to make sure we can use it with - // known livetime. - TestPrintNotifObserv observ; - MessageLoop current; - NotificationService::current()->AddObserver( - &observ, NOTIFY_ALL, - NotificationService::AllSources()); - TestSource source; - volatile bool check = false; - scoped_refptr<printing::PrintJob> job(new TestPrintJob(&source, &check)); - job->GetSettings(printing::PrintJob::DEFAULTS, NULL); - EXPECT_EQ(MessageLoop::current(), job->message_loop()); - current.Run(); - job->Stop(); - job = NULL; - EXPECT_TRUE(check); -} - -TEST(PrintJobTest, SimplePrintLateInit) { - volatile bool check = false; - MessageLoop current; - scoped_refptr<printing::PrintJob> job(new TestPrintJob(&check)); - job = NULL; - EXPECT_TRUE(check); - /* TODO(maruel): Test these. - job->Initialize() - job->Observe(); - job->GetSettingsDone(); - job->DetachWorker(); - job->message_loop(); - job->settings(); - job->cookie(); - job->GetSettings(printing::DEFAULTS, printing::ASK_USER, NULL); - job->StartPrinting(); - job->Stop(); - job->Cancel(); - job->RequestMissingPages(); - job->FlushJob(timeout_ms); - job->DisconnectSource(); - job->is_job_pending(); - job->is_print_dialog_box_shown(); - job->document(); - // Private - job->UpdatePrintedDocument(NULL); - scoped_refptr<printing::JobEventDetails> event_details; - job->OnNotifyPrintJobEvent(event_details); - job->OnDocumentDone(); - job->ControlledWorkerShutdown(); - */ -} diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc index d1737a6..835e73f 100644 --- a/chrome/renderer/render_view.cc +++ b/chrome/renderer/render_view.cc @@ -453,7 +453,6 @@ int RenderView::SwitchFrameToPrintMediaType(const ViewMsg_Print_Params& params, NOTREACHED(); pages = 0; } else { - DCHECK_GT(printed_document_width_, 0); // Force to recalculate the height, otherwise it reuse the current window // height as the default. float effective_shrink = printed_document_width_ / paper_width; diff --git a/chrome/test/unit/unit_tests.scons b/chrome/test/unit/unit_tests.scons index c90a0be..be3558b 100644 --- a/chrome/test/unit/unit_tests.scons +++ b/chrome/test/unit/unit_tests.scons @@ -175,7 +175,6 @@ if env['PLATFORM'] == 'win32': '$CHROME_DIR/browser/password_form_manager_unittest.cc', '$CHROME_DIR/browser/printing/page_number_unittest.cc', '$CHROME_DIR/browser/printing/page_overlays_unittest.cc', - '$CHROME_DIR/browser/printing/print_job_unittest.cc', '$CHROME_DIR/browser/printing/win_printing_context_unittest.cc', '$CHROME_DIR/browser/profile_manager_unittest.cc', '$CHROME_DIR/browser/renderer_security_policy_unittest.cc', diff --git a/chrome/test/unit/unittests.vcproj b/chrome/test/unit/unittests.vcproj index 17b9dc29..0b131c0 100644 --- a/chrome/test/unit/unittests.vcproj +++ b/chrome/test/unit/unittests.vcproj @@ -782,10 +782,6 @@ > </File> <File - RelativePath="..\..\browser\printing\print_job_unittest.cc" - > - </File> - <File RelativePath="..\..\browser\printing\printing_test.h" > </File> |