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

Side by Side Diff: chrome/browser/chooser_controller/mock_chooser_controller.cc

Issue 2242943002: Update device name in chooser when device changes name (desktops) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: updated device name in chooser when device changes name Created 4 years, 4 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
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
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 for (auto it = option_names_.begin(); it != option_names_.end(); ++it) {
msw 2016/08/12 22:19:33 optional nit: use std::find here too.
juncai 2016/08/15 18:11:19 Done.
98 if (*it == option_name) { 100 if (*it == option_name) {
99 size_t index = it - option_names_.begin(); 101 size_t index = it - option_names_.begin();
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; 105 return;
104 } 106 }
105 } 107 }
106 } 108 }
107 109
110 void MockChooserController::OptionUpdated(
111 const base::string16& previous_option_name,
112 const base::string16& new_option_name) {
113 auto it = std::find(option_names_.begin(), option_names_.end(),
114 previous_option_name);
115 DCHECK(it != option_names_.end());
116 size_t index = std::distance(option_names_.begin(), it);
117 *it = new_option_name;
118 if (view())
119 view()->OnOptionUpdated(index);
120 }
121
108 void MockChooserController::ClearAllOptions() { 122 void MockChooserController::ClearAllOptions() {
109 option_names_.clear(); 123 option_names_.clear();
110 } 124 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698