| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "remoting/host/it2me/it2me_confirmation_dialog_proxy.h" | 5 #include "remoting/host/it2me/it2me_confirmation_dialog_proxy.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
| 11 #include "base/location.h" | 11 #include "base/location.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/thread_task_runner_handle.h" | 13 #include "base/thread_task_runner_handle.h" |
| 14 | 14 |
| 15 namespace remoting { | 15 namespace remoting { |
| 16 | 16 |
| 17 class It2MeConfirmationDialogProxy::Core { | 17 class It2MeConfirmationDialogProxy::Core { |
| 18 public: | 18 public: |
| 19 Core(scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, | 19 Core(scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, |
| 20 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner, | 20 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner, |
| 21 base::WeakPtr<It2MeConfirmationDialogProxy> parent, | 21 base::WeakPtr<It2MeConfirmationDialogProxy> parent, |
| 22 scoped_ptr<It2MeConfirmationDialog> dialog); | 22 std::unique_ptr<It2MeConfirmationDialog> dialog); |
| 23 ~Core(); | 23 ~Core(); |
| 24 | 24 |
| 25 // Shows the wrapped dialog. Must be called on the UI thread. | 25 // Shows the wrapped dialog. Must be called on the UI thread. |
| 26 void Show(); | 26 void Show(); |
| 27 | 27 |
| 28 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner() { | 28 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner() { |
| 29 return ui_task_runner_; | 29 return ui_task_runner_; |
| 30 } | 30 } |
| 31 | 31 |
| 32 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner() { | 32 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner() { |
| 33 return caller_task_runner_; | 33 return caller_task_runner_; |
| 34 } | 34 } |
| 35 | 35 |
| 36 private: | 36 private: |
| 37 // Reports the dialog result on the caller's thread. | 37 // Reports the dialog result on the caller's thread. |
| 38 void ReportResult(It2MeConfirmationDialog::Result result); | 38 void ReportResult(It2MeConfirmationDialog::Result result); |
| 39 | 39 |
| 40 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; | 40 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; |
| 41 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner_; | 41 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner_; |
| 42 base::WeakPtr<It2MeConfirmationDialogProxy> parent_; | 42 base::WeakPtr<It2MeConfirmationDialogProxy> parent_; |
| 43 scoped_ptr<It2MeConfirmationDialog> dialog_; | 43 std::unique_ptr<It2MeConfirmationDialog> dialog_; |
| 44 | 44 |
| 45 DISALLOW_COPY_AND_ASSIGN(Core); | 45 DISALLOW_COPY_AND_ASSIGN(Core); |
| 46 }; | 46 }; |
| 47 | 47 |
| 48 It2MeConfirmationDialogProxy::Core::Core( | 48 It2MeConfirmationDialogProxy::Core::Core( |
| 49 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, | 49 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, |
| 50 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner, | 50 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner, |
| 51 base::WeakPtr<It2MeConfirmationDialogProxy> parent, | 51 base::WeakPtr<It2MeConfirmationDialogProxy> parent, |
| 52 scoped_ptr<It2MeConfirmationDialog> dialog) | 52 std::unique_ptr<It2MeConfirmationDialog> dialog) |
| 53 : ui_task_runner_(ui_task_runner), | 53 : ui_task_runner_(ui_task_runner), |
| 54 caller_task_runner_(caller_task_runner), | 54 caller_task_runner_(caller_task_runner), |
| 55 parent_(parent), | 55 parent_(parent), |
| 56 dialog_(std::move(dialog)) { | 56 dialog_(std::move(dialog)) {} |
| 57 } | |
| 58 | 57 |
| 59 It2MeConfirmationDialogProxy::Core::~Core() { | 58 It2MeConfirmationDialogProxy::Core::~Core() { |
| 60 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | 59 DCHECK(ui_task_runner_->BelongsToCurrentThread()); |
| 61 } | 60 } |
| 62 | 61 |
| 63 void It2MeConfirmationDialogProxy::Core::Show() { | 62 void It2MeConfirmationDialogProxy::Core::Show() { |
| 64 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | 63 DCHECK(ui_task_runner_->BelongsToCurrentThread()); |
| 65 | 64 |
| 66 dialog_->Show(base::Bind(&It2MeConfirmationDialogProxy::Core::ReportResult, | 65 dialog_->Show(base::Bind(&It2MeConfirmationDialogProxy::Core::ReportResult, |
| 67 base::Unretained(this))); | 66 base::Unretained(this))); |
| 68 } | 67 } |
| 69 | 68 |
| 70 void It2MeConfirmationDialogProxy::Core::ReportResult( | 69 void It2MeConfirmationDialogProxy::Core::ReportResult( |
| 71 It2MeConfirmationDialog::Result result) { | 70 It2MeConfirmationDialog::Result result) { |
| 72 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | 71 DCHECK(ui_task_runner_->BelongsToCurrentThread()); |
| 73 caller_task_runner_->PostTask( | 72 caller_task_runner_->PostTask( |
| 74 FROM_HERE, | 73 FROM_HERE, |
| 75 base::Bind(&It2MeConfirmationDialogProxy::ReportResult, parent_, result)); | 74 base::Bind(&It2MeConfirmationDialogProxy::ReportResult, parent_, result)); |
| 76 } | 75 } |
| 77 | 76 |
| 78 It2MeConfirmationDialogProxy::It2MeConfirmationDialogProxy( | 77 It2MeConfirmationDialogProxy::It2MeConfirmationDialogProxy( |
| 79 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, | 78 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, |
| 80 scoped_ptr<It2MeConfirmationDialog> dialog) | 79 std::unique_ptr<It2MeConfirmationDialog> dialog) |
| 81 : weak_factory_(this) { | 80 : weak_factory_(this) { |
| 82 core_.reset(new Core(ui_task_runner, base::ThreadTaskRunnerHandle::Get(), | 81 core_.reset(new Core(ui_task_runner, base::ThreadTaskRunnerHandle::Get(), |
| 83 weak_factory_.GetWeakPtr(), std::move(dialog))); | 82 weak_factory_.GetWeakPtr(), std::move(dialog))); |
| 84 } | 83 } |
| 85 | 84 |
| 86 It2MeConfirmationDialogProxy::~It2MeConfirmationDialogProxy() { | 85 It2MeConfirmationDialogProxy::~It2MeConfirmationDialogProxy() { |
| 87 DCHECK(core_->caller_task_runner()->BelongsToCurrentThread()); | 86 DCHECK(core_->caller_task_runner()->BelongsToCurrentThread()); |
| 88 | 87 |
| 89 auto ui_task_runner = core_->ui_task_runner(); | 88 auto ui_task_runner = core_->ui_task_runner(); |
| 90 ui_task_runner->DeleteSoon(FROM_HERE, core_.release()); | 89 ui_task_runner->DeleteSoon(FROM_HERE, core_.release()); |
| 91 } | 90 } |
| 92 | 91 |
| 93 void It2MeConfirmationDialogProxy::Show( | 92 void It2MeConfirmationDialogProxy::Show( |
| 94 const It2MeConfirmationDialog::ResultCallback& callback) { | 93 const It2MeConfirmationDialog::ResultCallback& callback) { |
| 95 DCHECK(core_->caller_task_runner()->BelongsToCurrentThread()); | 94 DCHECK(core_->caller_task_runner()->BelongsToCurrentThread()); |
| 96 | 95 |
| 97 callback_ = callback; | 96 callback_ = callback; |
| 98 core_->ui_task_runner()->PostTask(FROM_HERE, | 97 core_->ui_task_runner()->PostTask(FROM_HERE, |
| 99 base::Bind(&Core::Show, | 98 base::Bind(&Core::Show, |
| 100 base::Unretained(core_.get()))); | 99 base::Unretained(core_.get()))); |
| 101 } | 100 } |
| 102 | 101 |
| 103 void It2MeConfirmationDialogProxy::ReportResult( | 102 void It2MeConfirmationDialogProxy::ReportResult( |
| 104 It2MeConfirmationDialog::Result result) { | 103 It2MeConfirmationDialog::Result result) { |
| 105 DCHECK(core_->caller_task_runner()->BelongsToCurrentThread()); | 104 DCHECK(core_->caller_task_runner()->BelongsToCurrentThread()); |
| 106 base::ResetAndReturn(&callback_).Run(result); | 105 base::ResetAndReturn(&callback_).Run(result); |
| 107 } | 106 } |
| 108 | 107 |
| 109 } // namespace remoting | 108 } // namespace remoting |
| OLD | NEW |