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

Side by Side Diff: chrome/browser/translate/translate_prefs.cc

Issue 23606034: Fix a memory leak in translate_prefs.cc. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698