| OLD | NEW |
| 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 "sql/connection.h" | 5 #include "sql/connection.h" |
| 6 | 6 |
| 7 #include <limits.h> | 7 #include <limits.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 #include <string.h> | 10 #include <string.h> |
| 11 #include <utility> |
| 11 | 12 |
| 12 #include "base/bind.h" | 13 #include "base/bind.h" |
| 13 #include "base/debug/dump_without_crashing.h" | 14 #include "base/debug/dump_without_crashing.h" |
| 14 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
| 15 #include "base/files/file_util.h" | 16 #include "base/files/file_util.h" |
| 16 #include "base/format_macros.h" | 17 #include "base/format_macros.h" |
| 17 #include "base/json/json_file_value_serializer.h" | 18 #include "base/json/json_file_value_serializer.h" |
| 18 #include "base/lazy_instance.h" | 19 #include "base/lazy_instance.h" |
| 19 #include "base/logging.h" | 20 #include "base/logging.h" |
| 20 #include "base/message_loop/message_loop.h" | 21 #include "base/message_loop/message_loop.h" |
| (...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 688 // already bad. | 689 // already bad. |
| 689 base::AutoLock lock(g_sqlite_init_lock.Get()); | 690 base::AutoLock lock(g_sqlite_init_lock.Get()); |
| 690 | 691 |
| 691 scoped_ptr<base::Value> root; | 692 scoped_ptr<base::Value> root; |
| 692 if (!base::PathExists(breadcrumb_path)) { | 693 if (!base::PathExists(breadcrumb_path)) { |
| 693 scoped_ptr<base::DictionaryValue> root_dict(new base::DictionaryValue()); | 694 scoped_ptr<base::DictionaryValue> root_dict(new base::DictionaryValue()); |
| 694 root_dict->SetInteger(kVersionKey, kVersion); | 695 root_dict->SetInteger(kVersionKey, kVersion); |
| 695 | 696 |
| 696 scoped_ptr<base::ListValue> dumps(new base::ListValue); | 697 scoped_ptr<base::ListValue> dumps(new base::ListValue); |
| 697 dumps->AppendString(histogram_tag_); | 698 dumps->AppendString(histogram_tag_); |
| 698 root_dict->Set(kDiagnosticDumpsKey, dumps.Pass()); | 699 root_dict->Set(kDiagnosticDumpsKey, std::move(dumps)); |
| 699 | 700 |
| 700 root = root_dict.Pass(); | 701 root = std::move(root_dict); |
| 701 } else { | 702 } else { |
| 702 // Failure to read a valid dictionary implies that something is going wrong | 703 // Failure to read a valid dictionary implies that something is going wrong |
| 703 // on the system. | 704 // on the system. |
| 704 JSONFileValueDeserializer deserializer(breadcrumb_path); | 705 JSONFileValueDeserializer deserializer(breadcrumb_path); |
| 705 scoped_ptr<base::Value> read_root( | 706 scoped_ptr<base::Value> read_root( |
| 706 deserializer.Deserialize(nullptr, nullptr)); | 707 deserializer.Deserialize(nullptr, nullptr)); |
| 707 if (!read_root.get()) | 708 if (!read_root.get()) |
| 708 return false; | 709 return false; |
| 709 scoped_ptr<base::DictionaryValue> root_dict = | 710 scoped_ptr<base::DictionaryValue> root_dict = |
| 710 base::DictionaryValue::From(read_root.Pass()); | 711 base::DictionaryValue::From(std::move(read_root)); |
| 711 if (!root_dict) | 712 if (!root_dict) |
| 712 return false; | 713 return false; |
| 713 | 714 |
| 714 // Don't upload if the version is missing or newer. | 715 // Don't upload if the version is missing or newer. |
| 715 int version = 0; | 716 int version = 0; |
| 716 if (!root_dict->GetInteger(kVersionKey, &version) || version > kVersion) | 717 if (!root_dict->GetInteger(kVersionKey, &version) || version > kVersion) |
| 717 return false; | 718 return false; |
| 718 | 719 |
| 719 base::ListValue* dumps = nullptr; | 720 base::ListValue* dumps = nullptr; |
| 720 if (!root_dict->GetList(kDiagnosticDumpsKey, &dumps)) | 721 if (!root_dict->GetList(kDiagnosticDumpsKey, &dumps)) |
| 721 return false; | 722 return false; |
| 722 | 723 |
| 723 const size_t size = dumps->GetSize(); | 724 const size_t size = dumps->GetSize(); |
| 724 for (size_t i = 0; i < size; ++i) { | 725 for (size_t i = 0; i < size; ++i) { |
| 725 std::string s; | 726 std::string s; |
| 726 | 727 |
| 727 // Don't upload if the value isn't a string, or indicates a prior upload. | 728 // Don't upload if the value isn't a string, or indicates a prior upload. |
| 728 if (!dumps->GetString(i, &s) || s == histogram_tag_) | 729 if (!dumps->GetString(i, &s) || s == histogram_tag_) |
| 729 return false; | 730 return false; |
| 730 } | 731 } |
| 731 | 732 |
| 732 // Record intention to proceed with upload. | 733 // Record intention to proceed with upload. |
| 733 dumps->AppendString(histogram_tag_); | 734 dumps->AppendString(histogram_tag_); |
| 734 root = root_dict.Pass(); | 735 root = std::move(root_dict); |
| 735 } | 736 } |
| 736 | 737 |
| 737 const base::FilePath breadcrumb_new = | 738 const base::FilePath breadcrumb_new = |
| 738 breadcrumb_path.AddExtension(FILE_PATH_LITERAL("new")); | 739 breadcrumb_path.AddExtension(FILE_PATH_LITERAL("new")); |
| 739 base::DeleteFile(breadcrumb_new, false); | 740 base::DeleteFile(breadcrumb_new, false); |
| 740 | 741 |
| 741 // No upload if the breadcrumb file cannot be updated. | 742 // No upload if the breadcrumb file cannot be updated. |
| 742 // TODO(shess): Consider ImportantFileWriter::WriteFileAtomically() to land | 743 // TODO(shess): Consider ImportantFileWriter::WriteFileAtomically() to land |
| 743 // the data on disk. For now, losing the data is not a big problem, so the | 744 // the data on disk. For now, losing the data is not a big problem, so the |
| 744 // sync overhead would probably not be worth it. | 745 // sync overhead would probably not be worth it. |
| (...skipping 1238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1983 ignore_result(Execute(kNoWritableSchema)); | 1984 ignore_result(Execute(kNoWritableSchema)); |
| 1984 | 1985 |
| 1985 return ret; | 1986 return ret; |
| 1986 } | 1987 } |
| 1987 | 1988 |
| 1988 base::TimeTicks TimeSource::Now() { | 1989 base::TimeTicks TimeSource::Now() { |
| 1989 return base::TimeTicks::Now(); | 1990 return base::TimeTicks::Now(); |
| 1990 } | 1991 } |
| 1991 | 1992 |
| 1992 } // namespace sql | 1993 } // namespace sql |
| OLD | NEW |