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

Side by Side Diff: sql/connection.cc

Issue 1851913002: Convert //sql to use std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: IWYU fixup in precache_url_table_unittest.cc Created 4 years, 8 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
« no previous file with comments | « sql/connection.h ('k') | sql/connection_unittest.cc » ('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 "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
11 #include <utility> 12 #include <utility>
12 13
13 #include "base/bind.h" 14 #include "base/bind.h"
14 #include "base/debug/dump_without_crashing.h" 15 #include "base/debug/dump_without_crashing.h"
15 #include "base/files/file_path.h" 16 #include "base/files/file_path.h"
16 #include "base/files/file_util.h" 17 #include "base/files/file_util.h"
17 #include "base/format_macros.h" 18 #include "base/format_macros.h"
18 #include "base/json/json_file_value_serializer.h" 19 #include "base/json/json_file_value_serializer.h"
19 #include "base/lazy_instance.h" 20 #include "base/lazy_instance.h"
20 #include "base/logging.h" 21 #include "base/logging.h"
(...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 sqlite3_file* file = NULL; 536 sqlite3_file* file = NULL;
536 sqlite3_int64 file_size = 0; 537 sqlite3_int64 file_size = 0;
537 int rc = GetSqlite3FileAndSize(db_, &file, &file_size); 538 int rc = GetSqlite3FileAndSize(db_, &file, &file_size);
538 if (rc != SQLITE_OK) 539 if (rc != SQLITE_OK)
539 return; 540 return;
540 541
541 // Don't preload more than the file contains. 542 // Don't preload more than the file contains.
542 if (preload_size > file_size) 543 if (preload_size > file_size)
543 preload_size = file_size; 544 preload_size = file_size;
544 545
545 scoped_ptr<char[]> buf(new char[page_size]); 546 std::unique_ptr<char[]> buf(new char[page_size]);
546 for (sqlite3_int64 pos = 0; pos < preload_size; pos += page_size) { 547 for (sqlite3_int64 pos = 0; pos < preload_size; pos += page_size) {
547 rc = file->pMethods->xRead(file, buf.get(), page_size, pos); 548 rc = file->pMethods->xRead(file, buf.get(), page_size, pos);
548 549
549 // TODO(shess): Consider calling OnSqliteError(). 550 // TODO(shess): Consider calling OnSqliteError().
550 if (rc != SQLITE_OK) 551 if (rc != SQLITE_OK)
551 return; 552 return;
552 } 553 }
553 } 554 }
554 555
555 // SQLite keeps unused pages associated with a connection in a cache. It asks 556 // SQLite keeps unused pages associated with a connection in a cache. It asks
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
672 db_path.DirName().Append(FILE_PATH_LITERAL("sqlite-diag"))); 673 db_path.DirName().Append(FILE_PATH_LITERAL("sqlite-diag")));
673 674
674 // Lock against multiple updates to the diagnostics file. This code should 675 // Lock against multiple updates to the diagnostics file. This code should
675 // seldom be called in the first place, and when called it should seldom be 676 // seldom be called in the first place, and when called it should seldom be
676 // called for multiple databases, and when called for multiple databases there 677 // called for multiple databases, and when called for multiple databases there
677 // is _probably_ something systemic wrong with the user's system. So the lock 678 // is _probably_ something systemic wrong with the user's system. So the lock
678 // should never be contended, but when it is the database experience is 679 // should never be contended, but when it is the database experience is
679 // already bad. 680 // already bad.
680 base::AutoLock lock(g_sqlite_init_lock.Get()); 681 base::AutoLock lock(g_sqlite_init_lock.Get());
681 682
682 scoped_ptr<base::Value> root; 683 std::unique_ptr<base::Value> root;
683 if (!base::PathExists(breadcrumb_path)) { 684 if (!base::PathExists(breadcrumb_path)) {
684 scoped_ptr<base::DictionaryValue> root_dict(new base::DictionaryValue()); 685 std::unique_ptr<base::DictionaryValue> root_dict(
686 new base::DictionaryValue());
685 root_dict->SetInteger(kVersionKey, kVersion); 687 root_dict->SetInteger(kVersionKey, kVersion);
686 688
687 scoped_ptr<base::ListValue> dumps(new base::ListValue); 689 std::unique_ptr<base::ListValue> dumps(new base::ListValue);
688 dumps->AppendString(histogram_tag_); 690 dumps->AppendString(histogram_tag_);
689 root_dict->Set(kDiagnosticDumpsKey, std::move(dumps)); 691 root_dict->Set(kDiagnosticDumpsKey, std::move(dumps));
690 692
691 root = std::move(root_dict); 693 root = std::move(root_dict);
692 } else { 694 } else {
693 // Failure to read a valid dictionary implies that something is going wrong 695 // Failure to read a valid dictionary implies that something is going wrong
694 // on the system. 696 // on the system.
695 JSONFileValueDeserializer deserializer(breadcrumb_path); 697 JSONFileValueDeserializer deserializer(breadcrumb_path);
696 scoped_ptr<base::Value> read_root( 698 std::unique_ptr<base::Value> read_root(
697 deserializer.Deserialize(nullptr, nullptr)); 699 deserializer.Deserialize(nullptr, nullptr));
698 if (!read_root.get()) 700 if (!read_root.get())
699 return false; 701 return false;
700 scoped_ptr<base::DictionaryValue> root_dict = 702 std::unique_ptr<base::DictionaryValue> root_dict =
701 base::DictionaryValue::From(std::move(read_root)); 703 base::DictionaryValue::From(std::move(read_root));
702 if (!root_dict) 704 if (!root_dict)
703 return false; 705 return false;
704 706
705 // Don't upload if the version is missing or newer. 707 // Don't upload if the version is missing or newer.
706 int version = 0; 708 int version = 0;
707 if (!root_dict->GetInteger(kVersionKey, &version) || version > kVersion) 709 if (!root_dict->GetInteger(kVersionKey, &version) || version > kVersion)
708 return false; 710 return false;
709 711
710 base::ListValue* dumps = nullptr; 712 base::ListValue* dumps = nullptr;
(...skipping 1269 matching lines...) Expand 10 before | Expand all | Expand 10 after
1980 ignore_result(Execute(kNoWritableSchema)); 1982 ignore_result(Execute(kNoWritableSchema));
1981 1983
1982 return ret; 1984 return ret;
1983 } 1985 }
1984 1986
1985 base::TimeTicks TimeSource::Now() { 1987 base::TimeTicks TimeSource::Now() {
1986 return base::TimeTicks::Now(); 1988 return base::TimeTicks::Now();
1987 } 1989 }
1988 1990
1989 } // namespace sql 1991 } // namespace sql
OLDNEW
« no previous file with comments | « sql/connection.h ('k') | sql/connection_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698