Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 28 } | 28 } |
| 29 | 29 |
| 30 void WebDatabaseBackend::AddTable(std::unique_ptr<WebDatabaseTable> table) { | 30 void WebDatabaseBackend::AddTable(std::unique_ptr<WebDatabaseTable> table) { |
| 31 DCHECK(!db_.get()); | 31 DCHECK(!db_.get()); |
| 32 tables_.push_back(table.release()); | 32 tables_.push_back(table.release()); |
| 33 } | 33 } |
| 34 | 34 |
| 35 void WebDatabaseBackend::InitDatabase() { | 35 void WebDatabaseBackend::InitDatabase() { |
| 36 LoadDatabaseIfNecessary(); | 36 LoadDatabaseIfNecessary(); |
| 37 if (delegate_) { | 37 if (delegate_) { |
| 38 delegate_->DBLoaded(init_status_); | 38 delegate_->DBLoaded(init_status_, db_diagnostics_); |
| 39 } | 39 } |
| 40 } | 40 } |
| 41 | 41 |
| 42 sql::InitStatus WebDatabaseBackend::LoadDatabaseIfNecessary() { | 42 sql::InitStatus WebDatabaseBackend::LoadDatabaseIfNecessary() { |
| 43 if (init_complete_ || db_path_.empty()) { | 43 if (init_complete_ || db_path_.empty()) { |
| 44 return init_status_; | 44 return init_status_; |
| 45 } | 45 } |
| 46 init_complete_ = true; | 46 init_complete_ = true; |
| 47 db_.reset(new WebDatabase()); | 47 db_.reset(new WebDatabase()); |
| 48 | 48 |
| 49 for (ScopedVector<WebDatabaseTable>::iterator it = tables_.begin(); | 49 for (const auto& table : tables_) |
| 50 it != tables_.end(); ++it) { | 50 db_->AddTable(table); |
| 51 db_->AddTable(*it); | |
| 52 } | |
| 53 | 51 |
| 54 init_status_ = db_->Init(db_path_); | 52 init_status_ = db_->Init(db_path_); |
| 55 if (init_status_ != sql::INIT_OK) { | 53 if (init_status_ != sql::INIT_OK) { |
| 56 LOG(ERROR) << "Cannot initialize the web database: " << init_status_; | 54 LOG(ERROR) << "Cannot initialize the web database: " << init_status_; |
| 55 db_diagnostics_ = db_->GetDiagnosticMap(); | |
| 56 db_diagnostics_["Corrupted file"] = db_path_.AsUTF8Unsafe(); | |
|
michaeln
2016/07/09 03:00:38
we don't want to send the full path as part of a b
Scott Hess - ex-Googler
2016/07/10 05:16:52
I think I had earlier comments about this - we sho
afakhry
2016/07/11 16:47:45
Done.
afakhry
2016/07/11 16:47:45
Yes, I needed to think about a way to distinguish
| |
| 57 db_.reset(NULL); | 57 db_.reset(NULL); |
| 58 return init_status_; | 58 return init_status_; |
| 59 } | 59 } |
| 60 | 60 |
| 61 db_->BeginTransaction(); | 61 db_->BeginTransaction(); |
| 62 return init_status_; | 62 return init_status_; |
| 63 } | 63 } |
| 64 | 64 |
| 65 void WebDatabaseBackend::ShutdownDatabase() { | 65 void WebDatabaseBackend::ShutdownDatabase() { |
| 66 if (db_ && init_status_ == sql::INIT_OK) | 66 if (db_ && init_status_ == sql::INIT_OK) |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 112 WebDatabaseBackend::~WebDatabaseBackend() { | 112 WebDatabaseBackend::~WebDatabaseBackend() { |
| 113 ShutdownDatabase(); | 113 ShutdownDatabase(); |
| 114 } | 114 } |
| 115 | 115 |
| 116 void WebDatabaseBackend::Commit() { | 116 void WebDatabaseBackend::Commit() { |
| 117 DCHECK(db_); | 117 DCHECK(db_); |
| 118 DCHECK_EQ(sql::INIT_OK, init_status_); | 118 DCHECK_EQ(sql::INIT_OK, init_status_); |
| 119 db_->CommitTransaction(); | 119 db_->CommitTransaction(); |
| 120 db_->BeginTransaction(); | 120 db_->BeginTransaction(); |
| 121 } | 121 } |
| OLD | NEW |