| 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 "content/browser/media/webrtc_identity_store_backend.h" | 5 #include "content/browser/media/webrtc_identity_store_backend.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 }; | 105 }; |
| 106 | 106 |
| 107 // The class encapsulates the database operations. All members except ctor and | 107 // The class encapsulates the database operations. All members except ctor and |
| 108 // dtor should be accessed on the DB thread. | 108 // dtor should be accessed on the DB thread. |
| 109 // It can be created/destroyed on any thread. | 109 // It can be created/destroyed on any thread. |
| 110 class WebRTCIdentityStoreBackend::SqlLiteStorage | 110 class WebRTCIdentityStoreBackend::SqlLiteStorage |
| 111 : public base::RefCountedThreadSafe<SqlLiteStorage> { | 111 : public base::RefCountedThreadSafe<SqlLiteStorage> { |
| 112 public: | 112 public: |
| 113 SqlLiteStorage(base::TimeDelta validity_period, | 113 SqlLiteStorage(base::TimeDelta validity_period, |
| 114 const base::FilePath& path, | 114 const base::FilePath& path, |
| 115 quota::SpecialStoragePolicy* policy) | 115 storage::SpecialStoragePolicy* policy) |
| 116 : validity_period_(validity_period), special_storage_policy_(policy) { | 116 : validity_period_(validity_period), special_storage_policy_(policy) { |
| 117 if (!path.empty()) | 117 if (!path.empty()) |
| 118 path_ = path.Append(kWebRTCIdentityStoreDirectory); | 118 path_ = path.Append(kWebRTCIdentityStoreDirectory); |
| 119 } | 119 } |
| 120 | 120 |
| 121 void Load(IdentityMap* out_map); | 121 void Load(IdentityMap* out_map); |
| 122 void Close(); | 122 void Close(); |
| 123 void AddIdentity(const GURL& origin, | 123 void AddIdentity(const GURL& origin, |
| 124 const std::string& identity_name, | 124 const std::string& identity_name, |
| 125 const Identity& identity); | 125 const Identity& identity); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 void OnDatabaseError(int error, sql::Statement* stmt); | 162 void OnDatabaseError(int error, sql::Statement* stmt); |
| 163 void BatchOperation(OperationType type, | 163 void BatchOperation(OperationType type, |
| 164 const GURL& origin, | 164 const GURL& origin, |
| 165 const std::string& identity_name, | 165 const std::string& identity_name, |
| 166 const Identity& identity); | 166 const Identity& identity); |
| 167 void Commit(); | 167 void Commit(); |
| 168 | 168 |
| 169 base::TimeDelta validity_period_; | 169 base::TimeDelta validity_period_; |
| 170 // The file path of the DB. Empty if temporary. | 170 // The file path of the DB. Empty if temporary. |
| 171 base::FilePath path_; | 171 base::FilePath path_; |
| 172 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy_; | 172 scoped_refptr<storage::SpecialStoragePolicy> special_storage_policy_; |
| 173 scoped_ptr<sql::Connection> db_; | 173 scoped_ptr<sql::Connection> db_; |
| 174 // Batched DB operations pending to commit. | 174 // Batched DB operations pending to commit. |
| 175 PendingOperationList pending_operations_; | 175 PendingOperationList pending_operations_; |
| 176 | 176 |
| 177 DISALLOW_COPY_AND_ASSIGN(SqlLiteStorage); | 177 DISALLOW_COPY_AND_ASSIGN(SqlLiteStorage); |
| 178 }; | 178 }; |
| 179 | 179 |
| 180 WebRTCIdentityStoreBackend::WebRTCIdentityStoreBackend( | 180 WebRTCIdentityStoreBackend::WebRTCIdentityStoreBackend( |
| 181 const base::FilePath& path, | 181 const base::FilePath& path, |
| 182 quota::SpecialStoragePolicy* policy, | 182 storage::SpecialStoragePolicy* policy, |
| 183 base::TimeDelta validity_period) | 183 base::TimeDelta validity_period) |
| 184 : validity_period_(validity_period), | 184 : validity_period_(validity_period), |
| 185 state_(NOT_STARTED), | 185 state_(NOT_STARTED), |
| 186 sql_lite_storage_(new SqlLiteStorage(validity_period, path, policy)) {} | 186 sql_lite_storage_(new SqlLiteStorage(validity_period, path, policy)) { |
| 187 } |
| 187 | 188 |
| 188 bool WebRTCIdentityStoreBackend::FindIdentity( | 189 bool WebRTCIdentityStoreBackend::FindIdentity( |
| 189 const GURL& origin, | 190 const GURL& origin, |
| 190 const std::string& identity_name, | 191 const std::string& identity_name, |
| 191 const std::string& common_name, | 192 const std::string& common_name, |
| 192 const FindIdentityCallback& callback) { | 193 const FindIdentityCallback& callback) { |
| 193 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 194 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 194 if (state_ == CLOSED) | 195 if (state_ == CLOSED) |
| 195 return false; | 196 return false; |
| 196 | 197 |
| (...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 594 NOTREACHED(); | 595 NOTREACHED(); |
| 595 break; | 596 break; |
| 596 } | 597 } |
| 597 } | 598 } |
| 598 | 599 |
| 599 if (!transaction.Commit()) | 600 if (!transaction.Commit()) |
| 600 DVLOG(2) << "Failed to commit the transaction."; | 601 DVLOG(2) << "Failed to commit the transaction."; |
| 601 } | 602 } |
| 602 | 603 |
| 603 } // namespace content | 604 } // namespace content |
| OLD | NEW |