Chromium Code Reviews| 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/printing/printer_query.h" | 5 #include "chrome/browser/printing/printer_query.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/threading/thread_restrictions.h" | 10 #include "base/threading/thread_restrictions.h" |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 23 | 23 |
| 24 PrinterQuery::~PrinterQuery() { | 24 PrinterQuery::~PrinterQuery() { |
| 25 // The job should be finished (or at least canceled) when it is destroyed. | 25 // The job should be finished (or at least canceled) when it is destroyed. |
| 26 DCHECK(!is_print_dialog_box_shown_); | 26 DCHECK(!is_print_dialog_box_shown_); |
| 27 // If this fires, it is that this pending printer context has leaked. | 27 // If this fires, it is that this pending printer context has leaked. |
| 28 DCHECK(!worker_.get()); | 28 DCHECK(!worker_.get()); |
| 29 } | 29 } |
| 30 | 30 |
| 31 void PrinterQuery::GetSettingsDone(const PrintSettings& new_settings, | 31 void PrinterQuery::GetSettingsDone(const PrintSettings& new_settings, |
| 32 PrintingContext::Result result) { | 32 PrintingContext::Result result) { |
| 33 | |
| 34 if (result == PrintingContext::TEST) { | |
| 35 LOG(INFO) << "DGN - GetSettingsDone - Received TEST"; | |
| 36 return; | |
| 37 } | |
| 38 | |
| 33 is_print_dialog_box_shown_ = false; | 39 is_print_dialog_box_shown_ = false; |
| 34 last_status_ = result; | 40 last_status_ = result; |
| 35 if (result != PrintingContext::FAILED) { | 41 if (result != PrintingContext::FAILED) { |
| 36 settings_ = new_settings; | 42 settings_ = new_settings; |
| 37 cookie_ = PrintSettings::NewCookie(); | 43 cookie_ = PrintSettings::NewCookie(); |
| 38 } else { | 44 } else { |
| 39 // Failure. | 45 // Failure. |
| 40 cookie_ = 0; | 46 cookie_ = 0; |
| 41 } | 47 } |
| 42 | 48 |
| 43 if (!callback_.is_null()) { | 49 if (!callback_.is_null()) { |
| 44 // This may cause reentrancy like to call StopWorker(). | 50 // This may cause reentrancy like to call StopWorker(). |
| 51 LOG(INFO) << "DGN - GetSettingsDone - Calling PrinterQuery(" | |
| 52 << cookie_ <<")'s stored callback"; | |
| 53 | |
| 54 callback_.Run(); | |
| 55 callback_.Reset(); | |
| 56 } | |
| 57 } | |
| 58 | |
| 59 void PrinterQuery::ShowSystemDialogDone(PrintingContext::Result result) { | |
| 60 LOG(INFO) << "DGN - ShowSystemDialogDone " << result; | |
| 61 | |
| 62 if (!callback_.is_null()) { | |
| 63 // This may cause reentrancy like to call StopWorker(). | |
| 45 callback_.Run(); | 64 callback_.Run(); |
| 46 callback_.Reset(); | 65 callback_.Reset(); |
|
dgn
2014/11/25 17:07:42
callback reset here. I can't rely on something cal
| |
| 47 } | 66 } |
| 48 } | 67 } |
| 49 | 68 |
| 69 | |
| 50 PrintJobWorker* PrinterQuery::DetachWorker(PrintJobWorkerOwner* new_owner) { | 70 PrintJobWorker* PrinterQuery::DetachWorker(PrintJobWorkerOwner* new_owner) { |
| 51 DCHECK(callback_.is_null()); | 71 DCHECK(callback_.is_null()); |
| 52 DCHECK(worker_.get()); | 72 DCHECK(worker_.get()); |
| 53 | 73 |
| 54 worker_->SetNewOwner(new_owner); | 74 worker_->SetNewOwner(new_owner); |
| 55 return worker_.release(); | 75 return worker_.release(); |
| 56 } | 76 } |
| 57 | 77 |
| 58 const PrintSettings& PrinterQuery::settings() const { | 78 const PrintSettings& PrinterQuery::settings() const { |
| 59 return settings_; | 79 return settings_; |
| 60 } | 80 } |
| 61 | 81 |
| 62 int PrinterQuery::cookie() const { | 82 int PrinterQuery::cookie() const { |
| 63 return cookie_; | 83 return cookie_; |
| 64 } | 84 } |
| 65 | 85 |
| 66 void PrinterQuery::GetSettings( | 86 void PrinterQuery::GetSettings( |
| 67 GetSettingsAskParam ask_user_for_settings, | 87 GetSettingsAskParam ask_user_for_settings, |
| 68 int expected_page_count, | 88 int expected_page_count, |
| 69 bool has_selection, | 89 bool has_selection, |
| 70 MarginType margin_type, | 90 MarginType margin_type, |
| 71 const base::Closure& callback) { | 91 const base::Closure& callback) { |
| 72 DCHECK(RunsTasksOnCurrentThread()); | 92 DCHECK(RunsTasksOnCurrentThread()); |
| 73 DCHECK(!is_print_dialog_box_shown_); | 93 DCHECK(!is_print_dialog_box_shown_); |
| 74 | 94 |
| 75 StartWorker(callback); | 95 StartWorker(callback); |
| 76 | 96 |
| 77 // Real work is done in PrintJobWorker::GetSettings(). | 97 // Real work is done in PrintJobWorker::GetSettings(). |
| 78 is_print_dialog_box_shown_ = ask_user_for_settings == ASK_USER; | |
| 79 worker_->PostTask(FROM_HERE, | 98 worker_->PostTask(FROM_HERE, |
| 80 base::Bind(&PrintJobWorker::GetSettings, | 99 base::Bind(&PrintJobWorker::GetSettings, |
| 81 base::Unretained(worker_.get()), | 100 base::Unretained(worker_.get()), |
| 82 is_print_dialog_box_shown_, | 101 ask_user_for_settings, |
| 83 expected_page_count, | 102 expected_page_count, |
| 84 has_selection, | 103 has_selection, |
| 85 margin_type)); | 104 margin_type)); |
| 105 | |
| 106 | |
| 86 } | 107 } |
| 87 | 108 |
| 88 void PrinterQuery::SetSettings(scoped_ptr<base::DictionaryValue> new_settings, | 109 void PrinterQuery::SetSettings(scoped_ptr<base::DictionaryValue> new_settings, |
| 89 const base::Closure& callback) { | 110 const base::Closure& callback) { |
| 90 StartWorker(callback); | 111 StartWorker(callback); |
| 91 | 112 |
| 92 worker_->PostTask(FROM_HERE, | 113 worker_->PostTask(FROM_HERE, |
| 93 base::Bind(&PrintJobWorker::SetSettings, | 114 base::Bind(&PrintJobWorker::SetSettings, |
| 94 base::Unretained(worker_.get()), | 115 base::Unretained(worker_.get()), |
| 95 base::Passed(&new_settings))); | 116 base::Passed(&new_settings))); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 119 | 140 |
| 120 bool PrinterQuery::is_callback_pending() const { | 141 bool PrinterQuery::is_callback_pending() const { |
| 121 return !callback_.is_null(); | 142 return !callback_.is_null(); |
| 122 } | 143 } |
| 123 | 144 |
| 124 bool PrinterQuery::is_valid() const { | 145 bool PrinterQuery::is_valid() const { |
| 125 return worker_.get() != NULL; | 146 return worker_.get() != NULL; |
| 126 } | 147 } |
| 127 | 148 |
| 128 } // namespace printing | 149 } // namespace printing |
| OLD | NEW |