| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "remoting/host/it2me/it2me_confirmation_dialog_proxy.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/callback_helpers.h" |
| 9 #include "base/location.h" |
| 10 |
| 11 namespace remoting { |
| 12 |
| 13 It2MeConfirmationDialogProxy::It2MeConfirmationDialogProxy( |
| 14 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, |
| 15 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner, |
| 16 scoped_ptr<It2MeConfirmationDialog> dialog) |
| 17 : weak_factory_(this) { |
| 18 core_ = new Core(ui_task_runner, caller_task_runner, |
| 19 weak_factory_.GetWeakPtr(), dialog.Pass()); |
| 20 } |
| 21 |
| 22 It2MeConfirmationDialogProxy::~It2MeConfirmationDialogProxy() {} |
| 23 |
| 24 void It2MeConfirmationDialogProxy::Show( |
| 25 const It2MeConfirmationDialog::ResultCallback& callback) { |
| 26 callback_ = callback; |
| 27 core_->Show(); |
| 28 } |
| 29 |
| 30 It2MeConfirmationDialogProxy::Core::Core( |
| 31 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, |
| 32 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner, |
| 33 base::WeakPtr<It2MeConfirmationDialogProxy> parent, |
| 34 scoped_ptr<It2MeConfirmationDialog> dialog) |
| 35 : ui_task_runner_(ui_task_runner), |
| 36 caller_task_runner_(caller_task_runner), |
| 37 parent_(parent), |
| 38 dialog_(dialog.Pass()) { |
| 39 } |
| 40 |
| 41 void It2MeConfirmationDialogProxy::Core::Show() { |
| 42 if (!ui_task_runner_->BelongsToCurrentThread()) { |
| 43 ui_task_runner_->PostTask( |
| 44 FROM_HERE, |
| 45 base::Bind(&It2MeConfirmationDialogProxy::Core::Show, this)); |
| 46 return; |
| 47 } |
| 48 dialog_->Show( |
| 49 base::Bind(&It2MeConfirmationDialogProxy::Core::ReportResult, this)); |
| 50 } |
| 51 |
| 52 It2MeConfirmationDialogProxy::Core::~Core() {} |
| 53 |
| 54 void It2MeConfirmationDialogProxy::Core::ReportResult( |
| 55 It2MeConfirmationDialog::Result result) { |
| 56 if (!caller_task_runner_->BelongsToCurrentThread()) { |
| 57 caller_task_runner_->PostTask( |
| 58 FROM_HERE, |
| 59 base::Bind(&It2MeConfirmationDialogProxy::Core::ReportResult, this, |
| 60 result)); |
| 61 return; |
| 62 } |
| 63 |
| 64 if (parent_) |
| 65 parent_->ReportResult(result); |
| 66 } |
| 67 |
| 68 void It2MeConfirmationDialogProxy::ReportResult( |
| 69 It2MeConfirmationDialog::Result result) { |
| 70 base::ResetAndReturn(&callback_).Run(result); |
| 71 } |
| 72 |
| 73 } // namespace remoting |
| OLD | NEW |