| 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/threading/thread_task_runner_handle.h" | 13 #include "base/threading/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 std::unique_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(const std::string& remote_user_email); |
| 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: |
| (...skipping 15 matching lines...) Expand all Loading... |
| 52 std::unique_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 | 57 |
| 58 It2MeConfirmationDialogProxy::Core::~Core() { | 58 It2MeConfirmationDialogProxy::Core::~Core() { |
| 59 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | 59 DCHECK(ui_task_runner_->BelongsToCurrentThread()); |
| 60 } | 60 } |
| 61 | 61 |
| 62 void It2MeConfirmationDialogProxy::Core::Show() { | 62 void It2MeConfirmationDialogProxy::Core::Show( |
| 63 const std::string& remote_user_email) { |
| 63 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | 64 DCHECK(ui_task_runner_->BelongsToCurrentThread()); |
| 64 | 65 |
| 65 dialog_->Show(base::Bind(&It2MeConfirmationDialogProxy::Core::ReportResult, | 66 dialog_->Show(remote_user_email, |
| 67 base::Bind(&It2MeConfirmationDialogProxy::Core::ReportResult, |
| 66 base::Unretained(this))); | 68 base::Unretained(this))); |
| 67 } | 69 } |
| 68 | 70 |
| 69 void It2MeConfirmationDialogProxy::Core::ReportResult( | 71 void It2MeConfirmationDialogProxy::Core::ReportResult( |
| 70 It2MeConfirmationDialog::Result result) { | 72 It2MeConfirmationDialog::Result result) { |
| 71 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | 73 DCHECK(ui_task_runner_->BelongsToCurrentThread()); |
| 72 caller_task_runner_->PostTask( | 74 caller_task_runner_->PostTask( |
| 73 FROM_HERE, | 75 FROM_HERE, |
| 74 base::Bind(&It2MeConfirmationDialogProxy::ReportResult, parent_, result)); | 76 base::Bind(&It2MeConfirmationDialogProxy::ReportResult, parent_, result)); |
| 75 } | 77 } |
| 76 | 78 |
| 77 It2MeConfirmationDialogProxy::It2MeConfirmationDialogProxy( | 79 It2MeConfirmationDialogProxy::It2MeConfirmationDialogProxy( |
| 78 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, | 80 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, |
| 79 std::unique_ptr<It2MeConfirmationDialog> dialog) | 81 std::unique_ptr<It2MeConfirmationDialog> dialog) |
| 80 : weak_factory_(this) { | 82 : weak_factory_(this) { |
| 81 core_.reset(new Core(ui_task_runner, base::ThreadTaskRunnerHandle::Get(), | 83 core_.reset(new Core(ui_task_runner, base::ThreadTaskRunnerHandle::Get(), |
| 82 weak_factory_.GetWeakPtr(), std::move(dialog))); | 84 weak_factory_.GetWeakPtr(), std::move(dialog))); |
| 83 } | 85 } |
| 84 | 86 |
| 85 It2MeConfirmationDialogProxy::~It2MeConfirmationDialogProxy() { | 87 It2MeConfirmationDialogProxy::~It2MeConfirmationDialogProxy() { |
| 86 DCHECK(core_->caller_task_runner()->BelongsToCurrentThread()); | 88 DCHECK(core_->caller_task_runner()->BelongsToCurrentThread()); |
| 87 | 89 |
| 88 auto ui_task_runner = core_->ui_task_runner(); | 90 auto ui_task_runner = core_->ui_task_runner(); |
| 89 ui_task_runner->DeleteSoon(FROM_HERE, core_.release()); | 91 ui_task_runner->DeleteSoon(FROM_HERE, core_.release()); |
| 90 } | 92 } |
| 91 | 93 |
| 92 void It2MeConfirmationDialogProxy::Show( | 94 void It2MeConfirmationDialogProxy::Show( |
| 95 const std::string& remote_user_email, |
| 93 const It2MeConfirmationDialog::ResultCallback& callback) { | 96 const It2MeConfirmationDialog::ResultCallback& callback) { |
| 94 DCHECK(core_->caller_task_runner()->BelongsToCurrentThread()); | 97 DCHECK(core_->caller_task_runner()->BelongsToCurrentThread()); |
| 95 | 98 |
| 96 callback_ = callback; | 99 callback_ = callback; |
| 97 core_->ui_task_runner()->PostTask(FROM_HERE, | 100 core_->ui_task_runner()->PostTask( |
| 98 base::Bind(&Core::Show, | 101 FROM_HERE, base::Bind(&Core::Show, base::Unretained(core_.get()), |
| 99 base::Unretained(core_.get()))); | 102 remote_user_email)); |
| 100 } | 103 } |
| 101 | 104 |
| 102 void It2MeConfirmationDialogProxy::ReportResult( | 105 void It2MeConfirmationDialogProxy::ReportResult( |
| 103 It2MeConfirmationDialog::Result result) { | 106 It2MeConfirmationDialog::Result result) { |
| 104 DCHECK(core_->caller_task_runner()->BelongsToCurrentThread()); | 107 DCHECK(core_->caller_task_runner()->BelongsToCurrentThread()); |
| 105 base::ResetAndReturn(&callback_).Run(result); | 108 base::ResetAndReturn(&callback_).Run(result); |
| 106 } | 109 } |
| 107 | 110 |
| 108 } // namespace remoting | 111 } // namespace remoting |
| OLD | NEW |