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

Side by Side Diff: chrome/browser/chromeos/input_method/input_method_syncer.cc

Issue 1223153003: Move JoinString to the base namespace (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: windows Created 5 years, 5 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 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 "chrome/browser/chromeos/input_method/input_method_syncer.h" 5 #include "chrome/browser/chromeos/input_method/input_method_syncer.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 accept_language_codes.end(), 85 accept_language_codes.end(),
86 resolved_locale)) { 86 resolved_locale)) {
87 *value_iter = resolved_locale; 87 *value_iter = resolved_locale;
88 ++value_iter; 88 ++value_iter;
89 continue; 89 continue;
90 } 90 }
91 } 91 }
92 value_iter = values.erase(value_iter); 92 value_iter = values.erase(value_iter);
93 } 93 }
94 94
95 return JoinString(values, ','); 95 return base::JoinString(values, ",");
96 } 96 }
97 97
98 // Appends tokens from |src| that are not in |dest| to |dest|. 98 // Appends tokens from |src| that are not in |dest| to |dest|.
99 void MergeLists(std::vector<std::string>* dest, 99 void MergeLists(std::vector<std::string>* dest,
100 const std::vector<std::string>& src) { 100 const std::vector<std::string>& src) {
101 // Keep track of already-added tokens. 101 // Keep track of already-added tokens.
102 std::set<std::string> unique_tokens(dest->begin(), dest->end()); 102 std::set<std::string> unique_tokens(dest->begin(), dest->end());
103 103
104 for (const std::string& token : src) { 104 for (const std::string& token : src) {
105 // Skip token if it's already in |dest|. 105 // Skip token if it's already in |dest|.
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 std::vector<std::string> synced_tokens; 190 std::vector<std::string> synced_tokens;
191 std::vector<std::string> new_tokens; 191 std::vector<std::string> new_tokens;
192 192
193 // First, set the syncable prefs to the union of the local and synced prefs. 193 // First, set the syncable prefs to the union of the local and synced prefs.
194 base::SplitString( 194 base::SplitString(
195 preferred_languages_syncable_.GetValue(), ',', &synced_tokens); 195 preferred_languages_syncable_.GetValue(), ',', &synced_tokens);
196 base::SplitString(preferred_languages_.GetValue(), ',', &new_tokens); 196 base::SplitString(preferred_languages_.GetValue(), ',', &new_tokens);
197 197
198 // Append the synced values to the current values. 198 // Append the synced values to the current values.
199 MergeLists(&new_tokens, synced_tokens); 199 MergeLists(&new_tokens, synced_tokens);
200 preferred_languages_syncable_.SetValue(JoinString(new_tokens, ',')); 200 preferred_languages_syncable_.SetValue(base::JoinString(new_tokens, ","));
201 201
202 base::SplitString( 202 base::SplitString(
203 enabled_extension_imes_syncable_.GetValue(), ',', &synced_tokens); 203 enabled_extension_imes_syncable_.GetValue(), ',', &synced_tokens);
204 base::SplitString(enabled_extension_imes_.GetValue(), ',', &new_tokens); 204 base::SplitString(enabled_extension_imes_.GetValue(), ',', &new_tokens);
205 205
206 MergeLists(&new_tokens, synced_tokens); 206 MergeLists(&new_tokens, synced_tokens);
207 enabled_extension_imes_syncable_.SetValue(JoinString(new_tokens, ',')); 207 enabled_extension_imes_syncable_.SetValue(base::JoinString(new_tokens, ","));
208 208
209 // Revert preload engines to legacy component IDs. 209 // Revert preload engines to legacy component IDs.
210 base::SplitString(preload_engines_.GetValue(), ',', &new_tokens); 210 base::SplitString(preload_engines_.GetValue(), ',', &new_tokens);
211 std::transform(new_tokens.begin(), new_tokens.end(), new_tokens.begin(), 211 std::transform(new_tokens.begin(), new_tokens.end(), new_tokens.begin(),
212 extension_ime_util::GetComponentIDByInputMethodID); 212 extension_ime_util::GetComponentIDByInputMethodID);
213 base::SplitString( 213 base::SplitString(
214 preload_engines_syncable_.GetValue(), ',', &synced_tokens); 214 preload_engines_syncable_.GetValue(), ',', &synced_tokens);
215 215
216 MergeLists(&new_tokens, synced_tokens); 216 MergeLists(&new_tokens, synced_tokens);
217 preload_engines_syncable_.SetValue(JoinString(new_tokens, ',')); 217 preload_engines_syncable_.SetValue(base::JoinString(new_tokens, ","));
218 218
219 // Second, set the local prefs, incorporating new values from the sync server. 219 // Second, set the local prefs, incorporating new values from the sync server.
220 preload_engines_.SetValue( 220 preload_engines_.SetValue(
221 AddSupportedInputMethodValues(preload_engines_.GetValue(), 221 AddSupportedInputMethodValues(preload_engines_.GetValue(),
222 preload_engines_syncable, 222 preload_engines_syncable,
223 prefs::kLanguagePreloadEngines)); 223 prefs::kLanguagePreloadEngines));
224 enabled_extension_imes_.SetValue( 224 enabled_extension_imes_.SetValue(
225 AddSupportedInputMethodValues(enabled_extension_imes_.GetValue(), 225 AddSupportedInputMethodValues(enabled_extension_imes_.GetValue(),
226 enabled_extension_imes_syncable, 226 enabled_extension_imes_syncable,
227 prefs::kLanguageEnabledExtensionImes)); 227 prefs::kLanguageEnabledExtensionImes));
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 ime_state_->GetInputMethodExtensions(supported_descriptors.get()); 271 ime_state_->GetInputMethodExtensions(supported_descriptors.get());
272 } 272 }
273 CheckAndResolveInputMethodIDs(*supported_descriptors, &new_tokens); 273 CheckAndResolveInputMethodIDs(*supported_descriptors, &new_tokens);
274 } else if (pref_name != prefs::kLanguagePreferredLanguages) { 274 } else if (pref_name != prefs::kLanguagePreferredLanguages) {
275 NOTREACHED() << "Attempting to merge an invalid preference."; 275 NOTREACHED() << "Attempting to merge an invalid preference.";
276 // kLanguagePreferredLanguages is checked in CheckAndResolveLocales(). 276 // kLanguagePreferredLanguages is checked in CheckAndResolveLocales().
277 } 277 }
278 278
279 // Do the actual merging. 279 // Do the actual merging.
280 MergeLists(&old_tokens, new_tokens); 280 MergeLists(&old_tokens, new_tokens);
281 return JoinString(old_tokens, ','); 281 return base::JoinString(old_tokens, ",");
282 } 282 }
283 283
284 void InputMethodSyncer::FinishMerge(const std::string& languages) { 284 void InputMethodSyncer::FinishMerge(const std::string& languages) {
285 // Since the merge only removed locales that are unsupported on this system, 285 // Since the merge only removed locales that are unsupported on this system,
286 // we don't need to update the syncable prefs. If the local preference changes 286 // we don't need to update the syncable prefs. If the local preference changes
287 // later, the sync server will lose the values we dropped. That's okay since 287 // later, the sync server will lose the values we dropped. That's okay since
288 // the values from this device should then become the new defaults anyway. 288 // the values from this device should then become the new defaults anyway.
289 preferred_languages_.SetValue(languages); 289 preferred_languages_.SetValue(languages);
290 290
291 // We've finished merging. 291 // We've finished merging.
(...skipping 12 matching lines...) Expand all
304 // e.g., use a stale languages setting but push a new preload engines setting. 304 // e.g., use a stale languages setting but push a new preload engines setting.
305 preferred_languages_syncable_.SetValue(preferred_languages_.GetValue()); 305 preferred_languages_syncable_.SetValue(preferred_languages_.GetValue());
306 enabled_extension_imes_syncable_.SetValue(enabled_extension_imes_.GetValue()); 306 enabled_extension_imes_syncable_.SetValue(enabled_extension_imes_.GetValue());
307 307
308 // For preload engines, use legacy xkb IDs so the preference can sync 308 // For preload engines, use legacy xkb IDs so the preference can sync
309 // across Chrome OS and Chromium OS. 309 // across Chrome OS and Chromium OS.
310 std::vector<std::string> engines; 310 std::vector<std::string> engines;
311 base::SplitString(preload_engines_.GetValue(), ',', &engines); 311 base::SplitString(preload_engines_.GetValue(), ',', &engines);
312 std::transform(engines.begin(), engines.end(), engines.begin(), 312 std::transform(engines.begin(), engines.end(), engines.begin(),
313 extension_ime_util::GetComponentIDByInputMethodID); 313 extension_ime_util::GetComponentIDByInputMethodID);
314 preload_engines_syncable_.SetValue(JoinString(engines, ',')); 314 preload_engines_syncable_.SetValue(base::JoinString(engines, ","));
315 } 315 }
316 316
317 void InputMethodSyncer::OnIsSyncingChanged() { 317 void InputMethodSyncer::OnIsSyncingChanged() {
318 if (prefs_->GetBoolean(prefs::kLanguageShouldMergeInputMethods) && 318 if (prefs_->GetBoolean(prefs::kLanguageShouldMergeInputMethods) &&
319 prefs_->IsSyncing()) { 319 prefs_->IsSyncing()) {
320 MergeSyncedPrefs(); 320 MergeSyncedPrefs();
321 } 321 }
322 } 322 }
323 323
324 } // namespace input_method 324 } // namespace input_method
325 } // namespace chromeos 325 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698