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

Side by Side Diff: chrome/browser/prefs/pref_metrics_service.cc

Issue 23903040: Fix memory leak in PrefMetricsService (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 | « base/values.cc ('k') | 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/prefs/pref_metrics_service.h" 5 #include "chrome/browser/prefs/pref_metrics_service.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/json/json_string_value_serializer.h" 9 #include "base/json/json_string_value_serializer.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 return hash_pref_path; 347 return hash_pref_path;
348 } 348 }
349 349
350 std::string PrefMetricsService::GetHashedPrefValue( 350 std::string PrefMetricsService::GetHashedPrefValue(
351 const char* path, 351 const char* path,
352 const base::Value* value) { 352 const base::Value* value) {
353 DCHECK(value); 353 DCHECK(value);
354 354
355 // Dictionary values may contain empty lists and sub-dictionaries. Create 355 // Dictionary values may contain empty lists and sub-dictionaries. Create
356 // a deep copy with those stripped to make the hash more stable. 356 // a deep copy with those stripped to make the hash more stable.
357 DictionaryValue* dict_value = 357 scoped_ptr<DictionaryValue> dict_value;
358 static_cast<DictionaryValue*>(const_cast<Value*>(value)); 358 if (value->IsType(Value::TYPE_DICTIONARY)) {
359 if (dict_value) 359 dict_value.reset(static_cast<const DictionaryValue*>(value)
360 value = dict_value->DeepCopyWithoutEmptyChildren(); 360 ->DeepCopyWithoutEmptyChildren());
361 value = dict_value.get();
362 }
361 363
362 std::string string_to_hash(device_id_); 364 std::string string_to_hash(device_id_);
363 string_to_hash.append(path); 365 string_to_hash.append(path);
364 JSONStringValueSerializer serializer(&string_to_hash); 366 JSONStringValueSerializer serializer(&string_to_hash);
365 serializer.Serialize(*value); 367 serializer.Serialize(*value);
366 368
367 crypto::HMAC hmac(crypto::HMAC::SHA256); 369 crypto::HMAC hmac(crypto::HMAC::SHA256);
368 unsigned char digest[kSHA256DigestSize]; 370 unsigned char digest[kSHA256DigestSize];
369 if (!hmac.Init(pref_hash_seed_) || 371 if (!hmac.Init(pref_hash_seed_) ||
370 !hmac.Sign(string_to_hash, digest, kSHA256DigestSize)) { 372 !hmac.Sign(string_to_hash, digest, kSHA256DigestSize)) {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 } 424 }
423 425
424 bool PrefMetricsService::Factory::ServiceIsNULLWhileTesting() const { 426 bool PrefMetricsService::Factory::ServiceIsNULLWhileTesting() const {
425 return false; 427 return false;
426 } 428 }
427 429
428 content::BrowserContext* PrefMetricsService::Factory::GetBrowserContextToUse( 430 content::BrowserContext* PrefMetricsService::Factory::GetBrowserContextToUse(
429 content::BrowserContext* context) const { 431 content::BrowserContext* context) const {
430 return chrome::GetBrowserContextRedirectedInIncognito(context); 432 return chrome::GetBrowserContextRedirectedInIncognito(context);
431 } 433 }
OLDNEW
« no previous file with comments | « base/values.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698