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 <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" |
11 #include "components/webdata/common/web_data_request_manager.h" | 12 #include "components/webdata/common/web_data_request_manager.h" |
12 #include "components/webdata/common/web_database.h" | 13 #include "components/webdata/common/web_database.h" |
13 #include "components/webdata/common/web_database_table.h" | 14 #include "components/webdata/common/web_database_table.h" |
14 | 15 |
15 using base::Bind; | 16 using base::Bind; |
16 using base::FilePath; | 17 using base::FilePath; |
(...skipping 11 matching lines...) Expand all Loading... |
28 } | 29 } |
29 | 30 |
30 void WebDatabaseBackend::AddTable(std::unique_ptr<WebDatabaseTable> table) { | 31 void WebDatabaseBackend::AddTable(std::unique_ptr<WebDatabaseTable> table) { |
31 DCHECK(!db_.get()); | 32 DCHECK(!db_.get()); |
32 tables_.push_back(table.release()); | 33 tables_.push_back(table.release()); |
33 } | 34 } |
34 | 35 |
35 void WebDatabaseBackend::InitDatabase() { | 36 void WebDatabaseBackend::InitDatabase() { |
36 LoadDatabaseIfNecessary(); | 37 LoadDatabaseIfNecessary(); |
37 if (delegate_) { | 38 if (delegate_) { |
38 delegate_->DBLoaded(init_status_); | 39 delegate_->DBLoaded(init_status_, db_diagnostics_); |
39 } | 40 } |
40 } | 41 } |
41 | 42 |
42 sql::InitStatus WebDatabaseBackend::LoadDatabaseIfNecessary() { | 43 sql::InitStatus WebDatabaseBackend::LoadDatabaseIfNecessary() { |
43 if (init_complete_ || db_path_.empty()) { | 44 if (init_complete_ || db_path_.empty()) { |
44 return init_status_; | 45 return init_status_; |
45 } | 46 } |
46 init_complete_ = true; | 47 init_complete_ = true; |
47 db_.reset(new WebDatabase()); | 48 db_.reset(new WebDatabase()); |
48 | 49 |
49 for (ScopedVector<WebDatabaseTable>::iterator it = tables_.begin(); | 50 for (const auto& table : tables_) |
50 it != tables_.end(); ++it) { | 51 db_->AddTable(table); |
51 db_->AddTable(*it); | |
52 } | |
53 | 52 |
54 init_status_ = db_->Init(db_path_); | 53 init_status_ = db_->Init(db_path_); |
55 if (init_status_ != sql::INIT_OK) { | 54 if (init_status_ != sql::INIT_OK) { |
56 LOG(ERROR) << "Cannot initialize the web database: " << init_status_; | 55 LOG(ERROR) << "Cannot initialize the web database: " << init_status_; |
| 56 db_diagnostics_ = db_->GetDiagnosticMap(); |
| 57 std::vector<base::FilePath::StringType> path_components; |
| 58 db_path_.GetComponents(&path_components); |
| 59 |
| 60 #if defined(OS_WIN) |
| 61 const base::FilePath::StringType default_dir(L"Default"); |
| 62 #else |
| 63 const base::FilePath::StringType default_dir("Default"); |
| 64 #endif // defined(OS_WIN) |
| 65 |
| 66 auto itr = |
| 67 std::find(path_components.begin(), path_components.end(), default_dir); |
| 68 const std::string corrupted_file_name = |
| 69 db_path_.BaseName().AsUTF8Unsafe() + (itr != path_components.end() |
| 70 ? " [Default profile]" |
| 71 : " [User profile]"); |
| 72 db_diagnostics_["Corrupted file"] = corrupted_file_name; |
57 db_.reset(NULL); | 73 db_.reset(NULL); |
58 return init_status_; | 74 return init_status_; |
59 } | 75 } |
60 | 76 |
61 db_->BeginTransaction(); | 77 db_->BeginTransaction(); |
62 return init_status_; | 78 return init_status_; |
63 } | 79 } |
64 | 80 |
65 void WebDatabaseBackend::ShutdownDatabase() { | 81 void WebDatabaseBackend::ShutdownDatabase() { |
66 if (db_ && init_status_ == sql::INIT_OK) | 82 if (db_ && init_status_ == sql::INIT_OK) |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 WebDatabaseBackend::~WebDatabaseBackend() { | 128 WebDatabaseBackend::~WebDatabaseBackend() { |
113 ShutdownDatabase(); | 129 ShutdownDatabase(); |
114 } | 130 } |
115 | 131 |
116 void WebDatabaseBackend::Commit() { | 132 void WebDatabaseBackend::Commit() { |
117 DCHECK(db_); | 133 DCHECK(db_); |
118 DCHECK_EQ(sql::INIT_OK, init_status_); | 134 DCHECK_EQ(sql::INIT_OK, init_status_); |
119 db_->CommitTransaction(); | 135 db_->CommitTransaction(); |
120 db_->BeginTransaction(); | 136 db_->BeginTransaction(); |
121 } | 137 } |
OLD | NEW |