Chromium Code Reviews| 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 <memory> | |
| 6 #include <string> | |
| 7 | |
| 5 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/callback.h" | |
| 6 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
| 7 #include "base/location.h" | 11 #include "base/i18n/message_formatter.h" |
| 8 #include "base/macros.h" | 12 #include "base/macros.h" |
| 9 #include "base/memory/weak_ptr.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/single_thread_task_runner.h" | |
| 11 #include "base/threading/thread_task_runner_handle.h" | |
| 12 #include "remoting/base/string_resources.h" | 14 #include "remoting/base/string_resources.h" |
| 13 #include "remoting/host/chromeos/message_box.h" | 15 #include "remoting/host/chromeos/message_box.h" |
| 14 #include "remoting/host/it2me/it2me_confirmation_dialog.h" | 16 #include "remoting/host/it2me/it2me_confirmation_dialog.h" |
| 15 #include "ui/base/l10n/l10n_util.h" | 17 #include "ui/base/l10n/l10n_util.h" |
| 16 | 18 |
| 17 namespace remoting { | 19 namespace remoting { |
| 18 | 20 |
| 19 class It2MeConfirmationDialogChromeOS : public It2MeConfirmationDialog { | 21 class It2MeConfirmationDialogChromeOS : public It2MeConfirmationDialog { |
| 20 public: | 22 public: |
| 21 It2MeConfirmationDialogChromeOS(); | 23 It2MeConfirmationDialogChromeOS(); |
| 22 ~It2MeConfirmationDialogChromeOS() override; | 24 ~It2MeConfirmationDialogChromeOS() override; |
| 23 | 25 |
| 24 // It2MeConfirmationDialog implementation. | 26 // It2MeConfirmationDialog implementation. |
| 25 void Show(const ResultCallback& callback) override; | 27 void Show(const std::string& remote_user_email, |
| 28 const ResultCallback& callback) override; | |
| 26 | 29 |
| 27 private: | 30 private: |
| 28 // Handles result from |message_box_|. | 31 // Handles result from |message_box_|. |
| 29 void OnMessageBoxResult(MessageBox::Result result); | 32 void OnMessageBoxResult(MessageBox::Result result); |
| 30 | 33 |
| 31 std::unique_ptr<MessageBox> message_box_; | 34 std::unique_ptr<MessageBox> message_box_; |
| 32 ResultCallback callback_; | 35 ResultCallback callback_; |
| 33 | 36 |
| 34 DISALLOW_COPY_AND_ASSIGN(It2MeConfirmationDialogChromeOS); | 37 DISALLOW_COPY_AND_ASSIGN(It2MeConfirmationDialogChromeOS); |
| 35 }; | 38 }; |
| 36 | 39 |
| 37 It2MeConfirmationDialogChromeOS::It2MeConfirmationDialogChromeOS() {} | 40 It2MeConfirmationDialogChromeOS::It2MeConfirmationDialogChromeOS() {} |
| 38 | 41 |
| 39 It2MeConfirmationDialogChromeOS::~It2MeConfirmationDialogChromeOS() {} | 42 It2MeConfirmationDialogChromeOS::~It2MeConfirmationDialogChromeOS() {} |
| 40 | 43 |
| 41 void It2MeConfirmationDialogChromeOS::Show(const ResultCallback& callback) { | 44 void It2MeConfirmationDialogChromeOS::Show(const std::string& remote_user_email, |
| 45 const ResultCallback& callback) { | |
| 42 callback_ = callback; | 46 callback_ = callback; |
| 43 | 47 |
| 48 base::string16 dialog_message; | |
| 49 if (!remote_user_email.empty()) { | |
|
Sergey Ulanov
2016/09/09 18:46:57
maybe add a TODO to remove the case when email is
joedow
2016/09/10 02:50:36
I added this code in case we did not receive an em
| |
| 50 dialog_message = base::i18n::MessageFormatter::FormatWithNumberedArgs( | |
| 51 l10n_util::GetStringUTF16( | |
| 52 IDS_SHARE_CONFIRM_DIALOG_MESSAGE_WITH_USERNAME), | |
| 53 base::UTF8ToUTF16(remote_user_email)); | |
| 54 } else { | |
| 55 dialog_message = | |
| 56 l10n_util::GetStringUTF16(IDS_SHARE_CONFIRM_DIALOG_MESSAGE); | |
| 57 } | |
| 58 | |
| 44 message_box_.reset(new MessageBox( | 59 message_box_.reset(new MessageBox( |
| 45 l10n_util::GetStringUTF16(IDS_MODE_IT2ME), | 60 l10n_util::GetStringUTF16(IDS_MODE_IT2ME), dialog_message, |
| 46 l10n_util::GetStringUTF16(IDS_SHARE_CONFIRM_DIALOG_MESSAGE), | |
| 47 l10n_util::GetStringUTF16(IDS_SHARE_CONFIRM_DIALOG_CONFIRM), | 61 l10n_util::GetStringUTF16(IDS_SHARE_CONFIRM_DIALOG_CONFIRM), |
| 48 l10n_util::GetStringUTF16(IDS_SHARE_CONFIRM_DIALOG_DECLINE), | 62 l10n_util::GetStringUTF16(IDS_SHARE_CONFIRM_DIALOG_DECLINE), |
| 49 base::Bind(&It2MeConfirmationDialogChromeOS::OnMessageBoxResult, | 63 base::Bind(&It2MeConfirmationDialogChromeOS::OnMessageBoxResult, |
| 50 base::Unretained(this)))); | 64 base::Unretained(this)))); |
| 51 | 65 |
| 52 message_box_->Show(); | 66 message_box_->Show(); |
| 53 } | 67 } |
| 54 | 68 |
| 55 void It2MeConfirmationDialogChromeOS::OnMessageBoxResult( | 69 void It2MeConfirmationDialogChromeOS::OnMessageBoxResult( |
| 56 MessageBox::Result result) { | 70 MessageBox::Result result) { |
| 57 message_box_->Hide(); | 71 message_box_->Hide(); |
| 58 base::ResetAndReturn(&callback_).Run(result == MessageBox::OK ? | 72 base::ResetAndReturn(&callback_).Run(result == MessageBox::OK ? |
| 59 Result::OK : Result::CANCEL); | 73 Result::OK : Result::CANCEL); |
| 60 } | 74 } |
| 61 | 75 |
| 62 std::unique_ptr<It2MeConfirmationDialog> | 76 std::unique_ptr<It2MeConfirmationDialog> |
| 63 It2MeConfirmationDialogFactory::Create() { | 77 It2MeConfirmationDialogFactory::Create() { |
| 64 return std::unique_ptr<It2MeConfirmationDialog>( | 78 return std::unique_ptr<It2MeConfirmationDialog>( |
| 65 new It2MeConfirmationDialogChromeOS()); | 79 new It2MeConfirmationDialogChromeOS()); |
| 66 } | 80 } |
| 67 | 81 |
| 68 } // namespace remoting | 82 } // namespace remoting |
| OLD | NEW |