OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/translate/translate_prefs.h" | 5 #include "chrome/browser/translate/translate_prefs.h" |
6 | 6 |
7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
8 #include "base/strings/string_split.h" | 8 #include "base/strings/string_split.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 std::vector<std::string> accept_languages; | 349 std::vector<std::string> accept_languages; |
350 base::SplitString(accept_languages_str, ',', &accept_languages); | 350 base::SplitString(accept_languages_str, ',', &accept_languages); |
351 | 351 |
352 std::vector<std::string> blocked_languages; | 352 std::vector<std::string> blocked_languages; |
353 CreateBlockedLanguages(&blocked_languages, | 353 CreateBlockedLanguages(&blocked_languages, |
354 blacklisted_languages, | 354 blacklisted_languages, |
355 accept_languages); | 355 accept_languages); |
356 | 356 |
357 // Create the new preference kPrefTranslateBlockedLanguages. | 357 // Create the new preference kPrefTranslateBlockedLanguages. |
358 { | 358 { |
359 ListValue* blocked_languages_list = new ListValue(); | 359 ListValue blocked_languages_list; |
360 for (std::vector<std::string>::const_iterator it = | 360 for (std::vector<std::string>::const_iterator it = |
361 blocked_languages.begin(); | 361 blocked_languages.begin(); |
362 it != blocked_languages.end(); ++it) { | 362 it != blocked_languages.end(); ++it) { |
363 blocked_languages_list->Append(new StringValue(*it)); | 363 blocked_languages_list.Append(new StringValue(*it)); |
364 } | 364 } |
365 ListPrefUpdate update(user_prefs, kPrefTranslateBlockedLanguages); | 365 ListPrefUpdate update(user_prefs, kPrefTranslateBlockedLanguages); |
366 ListValue* list = update.Get(); | 366 ListValue* list = update.Get(); |
367 DCHECK(list != NULL); | 367 DCHECK(list != NULL); |
368 list->Swap(blocked_languages_list); | 368 list->Swap(&blocked_languages_list); |
369 } | 369 } |
370 | 370 |
371 // Update kAcceptLanguages | 371 // Update kAcceptLanguages |
372 for (std::vector<std::string>::const_iterator it = | 372 for (std::vector<std::string>::const_iterator it = |
373 blocked_languages.begin(); | 373 blocked_languages.begin(); |
374 it != blocked_languages.end(); ++it) { | 374 it != blocked_languages.end(); ++it) { |
375 std::string lang = *it; | 375 std::string lang = *it; |
376 TranslateUtil::ToChromeLanguageSynonym(&lang); | 376 TranslateUtil::ToChromeLanguageSynonym(&lang); |
377 bool not_found = | 377 bool not_found = |
378 std::find(accept_languages.begin(), accept_languages.end(), lang) == | 378 std::find(accept_languages.begin(), accept_languages.end(), lang) == |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 | 477 |
478 bool TranslatePrefs::IsListEmpty(const char* pref_id) const { | 478 bool TranslatePrefs::IsListEmpty(const char* pref_id) const { |
479 const ListValue* blacklist = prefs_->GetList(pref_id); | 479 const ListValue* blacklist = prefs_->GetList(pref_id); |
480 return (blacklist == NULL || blacklist->empty()); | 480 return (blacklist == NULL || blacklist->empty()); |
481 } | 481 } |
482 | 482 |
483 bool TranslatePrefs::IsDictionaryEmpty(const char* pref_id) const { | 483 bool TranslatePrefs::IsDictionaryEmpty(const char* pref_id) const { |
484 const DictionaryValue* dict = prefs_->GetDictionary(pref_id); | 484 const DictionaryValue* dict = prefs_->GetDictionary(pref_id); |
485 return (dict == NULL || dict->empty()); | 485 return (dict == NULL || dict->empty()); |
486 } | 486 } |
OLD | NEW |