OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "chrome/browser/chooser_controller/mock_chooser_controller.h" | 5 #include "chrome/browser/chooser_controller/mock_chooser_controller.h" |
6 | 6 |
| 7 #include <algorithm> |
| 8 |
7 #include "base/logging.h" | 9 #include "base/logging.h" |
8 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
9 #include "chrome/grit/generated_resources.h" | 11 #include "chrome/grit/generated_resources.h" |
10 #include "ui/base/l10n/l10n_util.h" | 12 #include "ui/base/l10n/l10n_util.h" |
11 | 13 |
12 MockChooserController::MockChooserController(content::RenderFrameHost* owner) | 14 MockChooserController::MockChooserController(content::RenderFrameHost* owner) |
13 : ChooserController(owner, | 15 : ChooserController(owner, |
14 IDS_USB_DEVICE_CHOOSER_PROMPT_ORIGIN, | 16 IDS_USB_DEVICE_CHOOSER_PROMPT_ORIGIN, |
15 IDS_USB_DEVICE_CHOOSER_PROMPT_EXTENSION_NAME), | 17 IDS_USB_DEVICE_CHOOSER_PROMPT_EXTENSION_NAME), |
16 no_options_text_(l10n_util::GetStringUTF16( | 18 no_options_text_(l10n_util::GetStringUTF16( |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 status_text_ = | 82 status_text_ = |
81 l10n_util::GetStringUTF16(IDS_BLUETOOTH_DEVICE_CHOOSER_RE_SCAN); | 83 l10n_util::GetStringUTF16(IDS_BLUETOOTH_DEVICE_CHOOSER_RE_SCAN); |
82 if (view()) { | 84 if (view()) { |
83 view()->OnRefreshStateChanged( | 85 view()->OnRefreshStateChanged( |
84 false /* Refreshing options is complete */); | 86 false /* Refreshing options is complete */); |
85 } | 87 } |
86 break; | 88 break; |
87 } | 89 } |
88 } | 90 } |
89 | 91 |
90 void MockChooserController::OptionAdded(const base::string16 option_name) { | 92 void MockChooserController::OptionAdded(const base::string16& option_name) { |
91 option_names_.push_back(option_name); | 93 option_names_.push_back(option_name); |
92 if (view()) | 94 if (view()) |
93 view()->OnOptionAdded(option_names_.size() - 1); | 95 view()->OnOptionAdded(option_names_.size() - 1); |
94 } | 96 } |
95 | 97 |
96 void MockChooserController::OptionRemoved(const base::string16 option_name) { | 98 void MockChooserController::OptionRemoved(const base::string16& option_name) { |
97 for (auto it = option_names_.begin(); it != option_names_.end(); ++it) { | 99 auto it = std::find(option_names_.begin(), option_names_.end(), option_name); |
98 if (*it == option_name) { | 100 if (it != option_names_.end()) { |
99 size_t index = it - option_names_.begin(); | 101 size_t index = std::distance(option_names_.begin(), it); |
100 option_names_.erase(it); | 102 option_names_.erase(it); |
101 if (view()) | 103 if (view()) |
102 view()->OnOptionRemoved(index); | 104 view()->OnOptionRemoved(index); |
103 return; | |
104 } | |
105 } | 105 } |
106 } | 106 } |
107 | 107 |
| 108 void MockChooserController::OptionUpdated( |
| 109 const base::string16& previous_option_name, |
| 110 const base::string16& new_option_name) { |
| 111 auto it = std::find(option_names_.begin(), option_names_.end(), |
| 112 previous_option_name); |
| 113 DCHECK(it != option_names_.end()); |
| 114 size_t index = std::distance(option_names_.begin(), it); |
| 115 *it = new_option_name; |
| 116 if (view()) |
| 117 view()->OnOptionUpdated(index); |
| 118 } |
| 119 |
108 void MockChooserController::ClearAllOptions() { | 120 void MockChooserController::ClearAllOptions() { |
109 option_names_.clear(); | 121 option_names_.clear(); |
110 } | 122 } |
OLD | NEW |