| 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) { |
| 46 DCHECK(!remote_user_email.empty()); |
| 42 callback_ = callback; | 47 callback_ = callback; |
| 43 | 48 |
| 44 message_box_.reset(new MessageBox( | 49 message_box_.reset(new MessageBox( |
| 45 l10n_util::GetStringUTF16(IDS_MODE_IT2ME), | 50 l10n_util::GetStringUTF16(IDS_MODE_IT2ME), |
| 46 l10n_util::GetStringUTF16(IDS_SHARE_CONFIRM_DIALOG_MESSAGE), | 51 base::i18n::MessageFormatter::FormatWithNumberedArgs( |
| 52 l10n_util::GetStringUTF16( |
| 53 IDS_SHARE_CONFIRM_DIALOG_MESSAGE_WITH_USERNAME), |
| 54 base::UTF8ToUTF16(remote_user_email)), |
| 47 l10n_util::GetStringUTF16(IDS_SHARE_CONFIRM_DIALOG_CONFIRM), | 55 l10n_util::GetStringUTF16(IDS_SHARE_CONFIRM_DIALOG_CONFIRM), |
| 48 l10n_util::GetStringUTF16(IDS_SHARE_CONFIRM_DIALOG_DECLINE), | 56 l10n_util::GetStringUTF16(IDS_SHARE_CONFIRM_DIALOG_DECLINE), |
| 49 base::Bind(&It2MeConfirmationDialogChromeOS::OnMessageBoxResult, | 57 base::Bind(&It2MeConfirmationDialogChromeOS::OnMessageBoxResult, |
| 50 base::Unretained(this)))); | 58 base::Unretained(this)))); |
| 51 | 59 |
| 52 message_box_->Show(); | 60 message_box_->Show(); |
| 53 } | 61 } |
| 54 | 62 |
| 55 void It2MeConfirmationDialogChromeOS::OnMessageBoxResult( | 63 void It2MeConfirmationDialogChromeOS::OnMessageBoxResult( |
| 56 MessageBox::Result result) { | 64 MessageBox::Result result) { |
| 57 message_box_->Hide(); | 65 message_box_->Hide(); |
| 58 base::ResetAndReturn(&callback_).Run(result == MessageBox::OK ? | 66 base::ResetAndReturn(&callback_).Run(result == MessageBox::OK ? |
| 59 Result::OK : Result::CANCEL); | 67 Result::OK : Result::CANCEL); |
| 60 } | 68 } |
| 61 | 69 |
| 62 std::unique_ptr<It2MeConfirmationDialog> | 70 std::unique_ptr<It2MeConfirmationDialog> |
| 63 It2MeConfirmationDialogFactory::Create() { | 71 It2MeConfirmationDialogFactory::Create() { |
| 64 return std::unique_ptr<It2MeConfirmationDialog>( | 72 return std::unique_ptr<It2MeConfirmationDialog>( |
| 65 new It2MeConfirmationDialogChromeOS()); | 73 new It2MeConfirmationDialogChromeOS()); |
| 66 } | 74 } |
| 67 | 75 |
| 68 } // namespace remoting | 76 } // namespace remoting |
| OLD | NEW |