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

Side by Side Diff: components/webdata/common/web_database_backend.cc

Issue 2107493002: Offer user to send feedback from profile error dialog (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: ios compile error Created 4 years, 5 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
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 "components/webdata/common/web_database_backend.h" 5 #include "components/webdata/common/web_database_backend.h"
6 6
7 #include <algorithm>
7 #include <utility> 8 #include <utility>
8 9
9 #include "base/bind.h" 10 #include "base/bind.h"
10 #include "base/location.h" 11 #include "base/location.h"
12 #include "base/strings/stringprintf.h"
11 #include "components/webdata/common/web_data_request_manager.h" 13 #include "components/webdata/common/web_data_request_manager.h"
12 #include "components/webdata/common/web_database.h" 14 #include "components/webdata/common/web_database.h"
13 #include "components/webdata/common/web_database_table.h" 15 #include "components/webdata/common/web_database_table.h"
16 #include "sql/error_delegate_util.h"
14 17
15 using base::Bind; 18 using base::Bind;
16 using base::FilePath; 19 using base::FilePath;
17 20
18 WebDatabaseBackend::WebDatabaseBackend( 21 WebDatabaseBackend::WebDatabaseBackend(
19 const FilePath& path, 22 const FilePath& path,
20 Delegate* delegate, 23 Delegate* delegate,
21 const scoped_refptr<base::SingleThreadTaskRunner>& db_thread) 24 const scoped_refptr<base::SingleThreadTaskRunner>& db_thread)
22 : base::RefCountedDeleteOnMessageLoop<WebDatabaseBackend>(db_thread), 25 : base::RefCountedDeleteOnMessageLoop<WebDatabaseBackend>(db_thread),
23 db_path_(path), 26 db_path_(path),
24 request_manager_(new WebDataRequestManager()), 27 request_manager_(new WebDataRequestManager()),
25 init_status_(sql::INIT_FAILURE), 28 init_status_(sql::INIT_FAILURE),
26 init_complete_(false), 29 init_complete_(false),
27 delegate_(delegate) { 30 delegate_(delegate) {
28 } 31 }
29 32
30 void WebDatabaseBackend::AddTable(std::unique_ptr<WebDatabaseTable> table) { 33 void WebDatabaseBackend::AddTable(std::unique_ptr<WebDatabaseTable> table) {
31 DCHECK(!db_.get()); 34 DCHECK(!db_.get());
32 tables_.push_back(table.release()); 35 tables_.push_back(table.release());
33 } 36 }
34 37
35 void WebDatabaseBackend::InitDatabase() { 38 void WebDatabaseBackend::InitDatabase() {
36 LoadDatabaseIfNecessary(); 39 LoadDatabaseIfNecessary();
37 if (delegate_) { 40 if (delegate_) {
38 delegate_->DBLoaded(init_status_); 41 delegate_->DBLoaded(init_status_, db_diagnostics_);
39 } 42 }
40 } 43 }
41 44
42 sql::InitStatus WebDatabaseBackend::LoadDatabaseIfNecessary() { 45 sql::InitStatus WebDatabaseBackend::LoadDatabaseIfNecessary() {
43 if (init_complete_ || db_path_.empty()) { 46 if (init_complete_ || db_path_.empty()) {
44 return init_status_; 47 return init_status_;
45 } 48 }
46 init_complete_ = true; 49 init_complete_ = true;
47 db_.reset(new WebDatabase()); 50 db_.reset(new WebDatabase());
48 51
49 for (ScopedVector<WebDatabaseTable>::iterator it = tables_.begin(); 52 for (const auto& table : tables_)
50 it != tables_.end(); ++it) { 53 db_->AddTable(table);
51 db_->AddTable(*it);
52 }
53 54
55 db_->set_error_callback(
56 base::Bind(&WebDatabaseBackend::DatabaseErrorCallback, this));
54 init_status_ = db_->Init(db_path_); 57 init_status_ = db_->Init(db_path_);
55 if (init_status_ != sql::INIT_OK) { 58 if (init_status_ != sql::INIT_OK) {
56 LOG(ERROR) << "Cannot initialize the web database: " << init_status_; 59 LOG(ERROR) << "Cannot initialize the web database: " << init_status_;
60 const std::string corrupted_file_name =
61 db_path_.DirName().BaseName().AsUTF8Unsafe() + "/" +
62 db_path_.BaseName().AsUTF8Unsafe();
63 base::StringAppendF(&db_diagnostics_, "Corrupted file: %s\n",
michaeln 2016/07/15 23:30:57 Ah, i guess the filename being appended here inste
afakhry 2016/07/18 17:43:51 Yes, that's one of the reasons, plus we the error
64 corrupted_file_name.c_str());
57 db_.reset(NULL); 65 db_.reset(NULL);
58 return init_status_; 66 return init_status_;
59 } 67 }
60 68
61 db_->BeginTransaction(); 69 db_->BeginTransaction();
62 return init_status_; 70 return init_status_;
63 } 71 }
64 72
65 void WebDatabaseBackend::ShutdownDatabase() { 73 void WebDatabaseBackend::ShutdownDatabase() {
66 if (db_ && init_status_ == sql::INIT_OK) 74 if (db_ && init_status_ == sql::INIT_OK)
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 if (db_ && init_status_ == sql::INIT_OK) { 114 if (db_ && init_status_ == sql::INIT_OK) {
107 return task.Run(db_.get()); 115 return task.Run(db_.get());
108 } 116 }
109 return nullptr; 117 return nullptr;
110 } 118 }
111 119
112 WebDatabaseBackend::~WebDatabaseBackend() { 120 WebDatabaseBackend::~WebDatabaseBackend() {
113 ShutdownDatabase(); 121 ShutdownDatabase();
114 } 122 }
115 123
124 void WebDatabaseBackend::DatabaseErrorCallback(int error,
125 sql::Statement* stmt) {
126 // We ignore any further error callbacks on the first catastrophic error.
127 static bool should_ignore_errors = false;
128 if (!should_ignore_errors && sql::IsErrorCatastrophic(error)) {
129 should_ignore_errors = true;
130 db_diagnostics_ = db_->GetDiagnosticInfo(error, stmt);
afakhry 2016/07/13 19:57:59 Question to (shess | michaeln): Should we RazeAndC
michaeln 2016/07/15 23:30:57 maybe? if so lets leave that for a seperate cl wh
afakhry 2016/07/18 17:43:51 Right now for the Web databases, we do nothing (un
michaeln 2016/07/18 20:05:49 agreed that the system should dig out of the error
afakhry 2016/07/18 20:21:28 Sure, thanks! I'll do it as a follow-up CL.
131 }
132 }
133
116 void WebDatabaseBackend::Commit() { 134 void WebDatabaseBackend::Commit() {
117 DCHECK(db_); 135 DCHECK(db_);
118 DCHECK_EQ(sql::INIT_OK, init_status_); 136 DCHECK_EQ(sql::INIT_OK, init_status_);
119 db_->CommitTransaction(); 137 db_->CommitTransaction();
120 db_->BeginTransaction(); 138 db_->BeginTransaction();
121 } 139 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698