Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(401)

Side by Side Diff: remoting/host/it2me/it2me_confirmation_dialog_proxy.cc

Issue 816903002: It2Me Confirmation Dialog (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix windows bot failure. Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 #include "base/thread_task_runner_handle.h"
11
12 namespace remoting {
13
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();
21
22 // Shows the wrapped dialog. Must be called on the UI thread.
23 void Show();
24
25 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner() {
26 return ui_task_runner_;
27 }
28
29 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner() {
30 return caller_task_runner_;
31 }
32
33 private:
34 // Reports the dialog result on the caller's thread.
35 void ReportResult(It2MeConfirmationDialog::Result result);
36
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_;
41
42 DISALLOW_COPY_AND_ASSIGN(Core);
43 };
44
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()) {
54 }
55
56 It2MeConfirmationDialogProxy::Core::~Core() {
57 DCHECK(ui_task_runner_->BelongsToCurrentThread());
58 }
59
60 void It2MeConfirmationDialogProxy::Core::Show() {
61 DCHECK(ui_task_runner_->BelongsToCurrentThread());
62
63 dialog_->Show(base::Bind(&It2MeConfirmationDialogProxy::Core::ReportResult,
64 base::Unretained(this)));
65 }
66
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));
73 }
74
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()));
81 }
82
83 It2MeConfirmationDialogProxy::~It2MeConfirmationDialogProxy() {
84 DCHECK(core_->caller_task_runner()->BelongsToCurrentThread());
85
86 auto ui_task_runner = core_->ui_task_runner();
87 ui_task_runner->DeleteSoon(FROM_HERE, core_.release());
88 }
89
90 void It2MeConfirmationDialogProxy::Show(
91 const It2MeConfirmationDialog::ResultCallback& callback) {
92 DCHECK(core_->caller_task_runner()->BelongsToCurrentThread());
93
94 callback_ = callback;
95 core_->ui_task_runner()->PostTask(FROM_HERE,
96 base::Bind(&Core::Show,
97 base::Unretained(core_.get())));
98 }
99
100 void It2MeConfirmationDialogProxy::ReportResult(
101 It2MeConfirmationDialog::Result result) {
102 DCHECK(core_->caller_task_runner()->BelongsToCurrentThread());
103 base::ResetAndReturn(&callback_).Run(result);
104 }
105
106 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/it2me/it2me_confirmation_dialog_proxy.h ('k') | remoting/host/it2me/it2me_confirmation_dialog_proxy_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698