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

Side by Side Diff: base/prefs/pref_service.cc

Issue 1544033003: Switch to standard integer types in base/prefs/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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
« no previous file with comments | « base/prefs/pref_service.h ('k') | base/prefs/pref_service_factory.h » ('j') | 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/prefs/pref_service.h" 5 #include "base/prefs/pref_service.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 23 matching lines...) Expand all
34 void OnError(PersistentPrefStore::PrefReadError error) override { 34 void OnError(PersistentPrefStore::PrefReadError error) override {
35 callback_.Run(error); 35 callback_.Run(error);
36 } 36 }
37 37
38 private: 38 private:
39 base::Callback<void(PersistentPrefStore::PrefReadError)> callback_; 39 base::Callback<void(PersistentPrefStore::PrefReadError)> callback_;
40 }; 40 };
41 41
42 // Returns the WriteablePrefStore::PrefWriteFlags for the pref with the given 42 // Returns the WriteablePrefStore::PrefWriteFlags for the pref with the given
43 // |path|. 43 // |path|.
44 uint32 GetWriteFlags(const PrefService::Preference* pref) { 44 uint32_t GetWriteFlags(const PrefService::Preference* pref) {
45 uint32 write_flags = WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS; 45 uint32_t write_flags = WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS;
46 46
47 if (!pref) 47 if (!pref)
48 return write_flags; 48 return write_flags;
49 49
50 if (pref->registration_flags() & PrefRegistry::LOSSY_PREF) 50 if (pref->registration_flags() & PrefRegistry::LOSSY_PREF)
51 write_flags |= WriteablePrefStore::LOSSY_PREF_WRITE_FLAG; 51 write_flags |= WriteablePrefStore::LOSSY_PREF_WRITE_FLAG;
52 return write_flags; 52 return write_flags;
53 } 53 }
54 54
55 } // namespace 55 } // namespace
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 396
397 void PrefService::SetString(const std::string& path, const std::string& value) { 397 void PrefService::SetString(const std::string& path, const std::string& value) {
398 SetUserPrefValue(path, new base::StringValue(value)); 398 SetUserPrefValue(path, new base::StringValue(value));
399 } 399 }
400 400
401 void PrefService::SetFilePath(const std::string& path, 401 void PrefService::SetFilePath(const std::string& path,
402 const base::FilePath& value) { 402 const base::FilePath& value) {
403 SetUserPrefValue(path, base::CreateFilePathValue(value)); 403 SetUserPrefValue(path, base::CreateFilePathValue(value));
404 } 404 }
405 405
406 void PrefService::SetInt64(const std::string& path, int64 value) { 406 void PrefService::SetInt64(const std::string& path, int64_t value) {
407 SetUserPrefValue(path, new base::StringValue(base::Int64ToString(value))); 407 SetUserPrefValue(path, new base::StringValue(base::Int64ToString(value)));
408 } 408 }
409 409
410 int64 PrefService::GetInt64(const std::string& path) const { 410 int64_t PrefService::GetInt64(const std::string& path) const {
411 DCHECK(CalledOnValidThread()); 411 DCHECK(CalledOnValidThread());
412 412
413 const base::Value* value = GetPreferenceValue(path); 413 const base::Value* value = GetPreferenceValue(path);
414 if (!value) { 414 if (!value) {
415 NOTREACHED() << "Trying to read an unregistered pref: " << path; 415 NOTREACHED() << "Trying to read an unregistered pref: " << path;
416 return 0; 416 return 0;
417 } 417 }
418 std::string result("0"); 418 std::string result("0");
419 bool rv = value->GetAsString(&result); 419 bool rv = value->GetAsString(&result);
420 DCHECK(rv); 420 DCHECK(rv);
421 421
422 int64 val; 422 int64_t val;
423 base::StringToInt64(result, &val); 423 base::StringToInt64(result, &val);
424 return val; 424 return val;
425 } 425 }
426 426
427 void PrefService::SetUint64(const std::string& path, uint64 value) { 427 void PrefService::SetUint64(const std::string& path, uint64_t value) {
428 SetUserPrefValue(path, new base::StringValue(base::Uint64ToString(value))); 428 SetUserPrefValue(path, new base::StringValue(base::Uint64ToString(value)));
429 } 429 }
430 430
431 uint64 PrefService::GetUint64(const std::string& path) const { 431 uint64_t PrefService::GetUint64(const std::string& path) const {
432 DCHECK(CalledOnValidThread()); 432 DCHECK(CalledOnValidThread());
433 433
434 const base::Value* value = GetPreferenceValue(path); 434 const base::Value* value = GetPreferenceValue(path);
435 if (!value) { 435 if (!value) {
436 NOTREACHED() << "Trying to read an unregistered pref: " << path; 436 NOTREACHED() << "Trying to read an unregistered pref: " << path;
437 return 0; 437 return 0;
438 } 438 }
439 std::string result("0"); 439 std::string result("0");
440 bool rv = value->GetAsString(&result); 440 bool rv = value->GetAsString(&result);
441 DCHECK(rv); 441 DCHECK(rv);
442 442
443 uint64 val; 443 uint64_t val;
444 base::StringToUint64(result, &val); 444 base::StringToUint64(result, &val);
445 return val; 445 return val;
446 } 446 }
447 447
448 base::Value* PrefService::GetMutableUserPref(const std::string& path, 448 base::Value* PrefService::GetMutableUserPref(const std::string& path,
449 base::Value::Type type) { 449 base::Value::Type type) {
450 CHECK(type == base::Value::TYPE_DICTIONARY || type == base::Value::TYPE_LIST); 450 CHECK(type == base::Value::TYPE_DICTIONARY || type == base::Value::TYPE_LIST);
451 DCHECK(CalledOnValidThread()); 451 DCHECK(CalledOnValidThread());
452 452
453 const Preference* pref = FindPreference(path); 453 const Preference* pref = FindPreference(path);
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
607 DCHECK(found_value->IsType(default_type)); 607 DCHECK(found_value->IsType(default_type));
608 return found_value; 608 return found_value;
609 } else { 609 } else {
610 // Every registered preference has at least a default value. 610 // Every registered preference has at least a default value.
611 NOTREACHED() << "no valid value found for registered pref " << path; 611 NOTREACHED() << "no valid value found for registered pref " << path;
612 } 612 }
613 } 613 }
614 614
615 return NULL; 615 return NULL;
616 } 616 }
OLDNEW
« no previous file with comments | « base/prefs/pref_service.h ('k') | base/prefs/pref_service_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698