Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / remoting / host / it2me / it2me_confirmation_dialog_proxy.cc
blob0e26b7d7a1bf7ed603b1e0c9fc6b9a2d547cfc48
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.
5 #include "remoting/host/it2me/it2me_confirmation_dialog_proxy.h"
7 #include "base/bind.h"
8 #include "base/callback_helpers.h"
9 #include "base/location.h"
10 #include "base/thread_task_runner_handle.h"
12 namespace remoting {
14 class It2MeConfirmationDialogProxy::Core {
15 public:
16 Core(scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
17 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner,
18 base::WeakPtr<It2MeConfirmationDialogProxy> parent,
19 scoped_ptr<It2MeConfirmationDialog> dialog);
20 ~Core();
22 // Shows the wrapped dialog. Must be called on the UI thread.
23 void Show();
25 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner() {
26 return ui_task_runner_;
29 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner() {
30 return caller_task_runner_;
33 private:
34 // Reports the dialog result on the caller's thread.
35 void ReportResult(It2MeConfirmationDialog::Result result);
37 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_;
38 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner_;
39 base::WeakPtr<It2MeConfirmationDialogProxy> parent_;
40 scoped_ptr<It2MeConfirmationDialog> dialog_;
42 DISALLOW_COPY_AND_ASSIGN(Core);
45 It2MeConfirmationDialogProxy::Core::Core(
46 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
47 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner,
48 base::WeakPtr<It2MeConfirmationDialogProxy> parent,
49 scoped_ptr<It2MeConfirmationDialog> dialog)
50 : ui_task_runner_(ui_task_runner),
51 caller_task_runner_(caller_task_runner),
52 parent_(parent),
53 dialog_(dialog.Pass()) {
56 It2MeConfirmationDialogProxy::Core::~Core() {
57 DCHECK(ui_task_runner_->BelongsToCurrentThread());
60 void It2MeConfirmationDialogProxy::Core::Show() {
61 DCHECK(ui_task_runner_->BelongsToCurrentThread());
63 dialog_->Show(base::Bind(&It2MeConfirmationDialogProxy::Core::ReportResult,
64 base::Unretained(this)));
67 void It2MeConfirmationDialogProxy::Core::ReportResult(
68 It2MeConfirmationDialog::Result result) {
69 DCHECK(ui_task_runner_->BelongsToCurrentThread());
70 caller_task_runner_->PostTask(
71 FROM_HERE,
72 base::Bind(&It2MeConfirmationDialogProxy::ReportResult, parent_, result));
75 It2MeConfirmationDialogProxy::It2MeConfirmationDialogProxy(
76 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
77 scoped_ptr<It2MeConfirmationDialog> dialog)
78 : weak_factory_(this) {
79 core_.reset(new Core(ui_task_runner, base::ThreadTaskRunnerHandle::Get(),
80 weak_factory_.GetWeakPtr(), dialog.Pass()));
83 It2MeConfirmationDialogProxy::~It2MeConfirmationDialogProxy() {
84 DCHECK(core_->caller_task_runner()->BelongsToCurrentThread());
86 auto ui_task_runner = core_->ui_task_runner();
87 ui_task_runner->DeleteSoon(FROM_HERE, core_.release());
90 void It2MeConfirmationDialogProxy::Show(
91 const It2MeConfirmationDialog::ResultCallback& callback) {
92 DCHECK(core_->caller_task_runner()->BelongsToCurrentThread());
94 callback_ = callback;
95 core_->ui_task_runner()->PostTask(FROM_HERE,
96 base::Bind(&Core::Show,
97 base::Unretained(core_.get())));
100 void It2MeConfirmationDialogProxy::ReportResult(
101 It2MeConfirmationDialog::Result result) {
102 DCHECK(core_->caller_task_runner()->BelongsToCurrentThread());
103 base::ResetAndReturn(&callback_).Run(result);
106 } // namespace remoting