| 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_data_service_backend.h" | 5 #include "components/webdata/common/web_data_service_backend.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "components/webdata/common/web_data_request_manager.h" | 9 #include "components/webdata/common/web_data_request_manager.h" |
| 10 #include "components/webdata/common/web_database.h" | 10 #include "components/webdata/common/web_database.h" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 db_.reset(NULL); | 66 db_.reset(NULL); |
| 67 init_complete_ = !should_reinit; // Setting init_complete_ to true will ensure | 67 init_complete_ = !should_reinit; // Setting init_complete_ to true will ensure |
| 68 // that the init sequence is not re-run. | 68 // that the init sequence is not re-run. |
| 69 | 69 |
| 70 init_status_ = sql::INIT_FAILURE; | 70 init_status_ = sql::INIT_FAILURE; |
| 71 } | 71 } |
| 72 | 72 |
| 73 void WebDataServiceBackend::DBWriteTaskWrapper( | 73 void WebDataServiceBackend::DBWriteTaskWrapper( |
| 74 const WebDatabaseService::WriteTask& task, | 74 const WebDatabaseService::WriteTask& task, |
| 75 scoped_ptr<WebDataRequest> request) { | 75 scoped_ptr<WebDataRequest> request) { |
| 76 if (request->IsCancelled()) |
| 77 return; |
| 78 |
| 79 ExecuteWriteTask(task); |
| 80 request_manager_->RequestCompleted(request.Pass()); |
| 81 } |
| 82 |
| 83 void WebDataServiceBackend::ExecuteWriteTask( |
| 84 const WebDatabaseService::WriteTask& task) { |
| 76 LoadDatabaseIfNecessary(); | 85 LoadDatabaseIfNecessary(); |
| 77 if (db_ && init_status_ == sql::INIT_OK && !request->IsCancelled()) { | 86 if (db_ && init_status_ == sql::INIT_OK) { |
| 78 WebDatabase::State state = task.Run(db_.get()); | 87 WebDatabase::State state = task.Run(db_.get()); |
| 79 if (state == WebDatabase::COMMIT_NEEDED) | 88 if (state == WebDatabase::COMMIT_NEEDED) |
| 80 Commit(); | 89 Commit(); |
| 81 } | 90 } |
| 82 request_manager_->RequestCompleted(request.Pass()); | |
| 83 } | 91 } |
| 84 | 92 |
| 85 void WebDataServiceBackend::DBReadTaskWrapper( | 93 void WebDataServiceBackend::DBReadTaskWrapper( |
| 86 const WebDatabaseService::ReadTask& task, | 94 const WebDatabaseService::ReadTask& task, |
| 87 scoped_ptr<WebDataRequest> request) { | 95 scoped_ptr<WebDataRequest> request) { |
| 88 LoadDatabaseIfNecessary(); | 96 if (request->IsCancelled()) |
| 89 if (db_ && init_status_ == sql::INIT_OK && !request->IsCancelled()) { | 97 return; |
| 90 request->SetResult(task.Run(db_.get()).Pass()); | 98 |
| 91 } | 99 request->SetResult(ExecuteReadTask(task).Pass()); |
| 92 request_manager_->RequestCompleted(request.Pass()); | 100 request_manager_->RequestCompleted(request.Pass()); |
| 93 } | 101 } |
| 94 | 102 |
| 103 scoped_ptr<WDTypedResult> WebDataServiceBackend::ExecuteReadTask( |
| 104 const WebDatabaseService::ReadTask& task) { |
| 105 LoadDatabaseIfNecessary(); |
| 106 if (db_ && init_status_ == sql::INIT_OK) { |
| 107 return task.Run(db_.get()); |
| 108 } |
| 109 return scoped_ptr<WDTypedResult>(NULL); |
| 110 } |
| 111 |
| 95 WebDataServiceBackend::~WebDataServiceBackend() { | 112 WebDataServiceBackend::~WebDataServiceBackend() { |
| 96 ShutdownDatabase(false); | 113 ShutdownDatabase(false); |
| 97 } | 114 } |
| 98 | 115 |
| 99 void WebDataServiceBackend::Commit() { | 116 void WebDataServiceBackend::Commit() { |
| 100 if (db_ && init_status_ == sql::INIT_OK) { | 117 if (db_ && init_status_ == sql::INIT_OK) { |
| 101 db_->CommitTransaction(); | 118 db_->CommitTransaction(); |
| 102 db_->BeginTransaction(); | 119 db_->BeginTransaction(); |
| 103 } else { | 120 } else { |
| 104 NOTREACHED() << "Commit scheduled after Shutdown()"; | 121 NOTREACHED() << "Commit scheduled after Shutdown()"; |
| 105 } | 122 } |
| 106 } | 123 } |
| OLD | NEW |