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

Side by Side Diff: content/browser/indexed_db/indexed_db_factory.cc

Issue 15984016: Call scoped_refptr<T>::get() rather than relying on implicit "operator T*" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 7 years, 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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/indexed_db/indexed_db_factory.h" 5 #include "content/browser/indexed_db/indexed_db_factory.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "content/browser/indexed_db/indexed_db_backing_store.h" 9 #include "content/browser/indexed_db/indexed_db_backing_store.h"
10 #include "content/browser/indexed_db/indexed_db_database.h" 10 #include "content/browser/indexed_db/indexed_db_database.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 database_backend_map_.erase(unique_identifier); 50 database_backend_map_.erase(unique_identifier);
51 } 51 }
52 52
53 void IndexedDBFactory::GetDatabaseNames( 53 void IndexedDBFactory::GetDatabaseNames(
54 scoped_refptr<IndexedDBCallbacksWrapper> callbacks, 54 scoped_refptr<IndexedDBCallbacksWrapper> callbacks,
55 const string16& database_identifier, 55 const string16& database_identifier,
56 const base::FilePath& data_directory) { 56 const base::FilePath& data_directory) {
57 IDB_TRACE("IndexedDBFactory::get_database_names"); 57 IDB_TRACE("IndexedDBFactory::get_database_names");
58 scoped_refptr<IndexedDBBackingStore> backing_store = 58 scoped_refptr<IndexedDBBackingStore> backing_store =
59 OpenBackingStore(database_identifier, data_directory); 59 OpenBackingStore(database_identifier, data_directory);
60 if (!backing_store) { 60 if (!backing_store.get()) {
61 callbacks->OnError( 61 callbacks->OnError(
62 IndexedDBDatabaseError(WebKit::WebIDBDatabaseExceptionUnknownError, 62 IndexedDBDatabaseError(WebKit::WebIDBDatabaseExceptionUnknownError,
63 "Internal error opening backing store for " 63 "Internal error opening backing store for "
64 "indexedDB.webkitGetDatabaseNames.")); 64 "indexedDB.webkitGetDatabaseNames."));
65 return; 65 return;
66 } 66 }
67 67
68 callbacks->OnSuccess(backing_store->GetDatabaseNames()); 68 callbacks->OnSuccess(backing_store->GetDatabaseNames());
69 } 69 }
70 70
(...skipping 11 matching lines...) Expand all
82 if (it != database_backend_map_.end()) { 82 if (it != database_backend_map_.end()) {
83 // If there are any connections to the database, directly delete the 83 // If there are any connections to the database, directly delete the
84 // database. 84 // database.
85 it->second->DeleteDatabase(callbacks); 85 it->second->DeleteDatabase(callbacks);
86 return; 86 return;
87 } 87 }
88 88
89 // TODO(jsbell): Everything from now on should be done on another thread. 89 // TODO(jsbell): Everything from now on should be done on another thread.
90 scoped_refptr<IndexedDBBackingStore> backing_store = 90 scoped_refptr<IndexedDBBackingStore> backing_store =
91 OpenBackingStore(database_identifier, data_directory); 91 OpenBackingStore(database_identifier, data_directory);
92 if (!backing_store) { 92 if (!backing_store.get()) {
93 callbacks->OnError(IndexedDBDatabaseError( 93 callbacks->OnError(IndexedDBDatabaseError(
94 WebKit::WebIDBDatabaseExceptionUnknownError, 94 WebKit::WebIDBDatabaseExceptionUnknownError,
95 ASCIIToUTF16("Internal error opening backing store " 95 ASCIIToUTF16("Internal error opening backing store "
96 "for indexed_db.delete_database."))); 96 "for indexed_db.delete_database.")));
97 return; 97 return;
98 } 98 }
99 99
100 scoped_refptr<IndexedDBDatabase> database_backend = IndexedDBDatabase::Create( 100 scoped_refptr<IndexedDBDatabase> database_backend = IndexedDBDatabase::Create(
101 name, backing_store.get(), this, unique_identifier); 101 name, backing_store.get(), this, unique_identifier);
102 if (!database_backend) { 102 if (!database_backend.get()) {
103 callbacks->OnError(IndexedDBDatabaseError( 103 callbacks->OnError(IndexedDBDatabaseError(
104 WebKit::WebIDBDatabaseExceptionUnknownError, 104 WebKit::WebIDBDatabaseExceptionUnknownError,
105 ASCIIToUTF16("Internal error creating database backend for " 105 ASCIIToUTF16("Internal error creating database backend for "
106 "indexed_db.delete_database."))); 106 "indexed_db.delete_database.")));
107 return; 107 return;
108 } 108 }
109 109
110 database_backend_map_[unique_identifier] = database_backend.get(); 110 database_backend_map_[unique_identifier] = database_backend.get();
111 database_backend->DeleteDatabase(callbacks); 111 database_backend->DeleteDatabase(callbacks);
112 database_backend_map_.erase(unique_identifier); 112 database_backend_map_.erase(unique_identifier);
(...skipping 11 matching lines...) Expand all
124 return it2->second.get(); 124 return it2->second.get();
125 125
126 scoped_refptr<IndexedDBBackingStore> backing_store; 126 scoped_refptr<IndexedDBBackingStore> backing_store;
127 if (open_in_memory) { 127 if (open_in_memory) {
128 backing_store = IndexedDBBackingStore::OpenInMemory(file_identifier); 128 backing_store = IndexedDBBackingStore::OpenInMemory(file_identifier);
129 } else { 129 } else {
130 backing_store = IndexedDBBackingStore::Open( 130 backing_store = IndexedDBBackingStore::Open(
131 database_identifier, data_directory, file_identifier); 131 database_identifier, data_directory, file_identifier);
132 } 132 }
133 133
134 if (backing_store) { 134 if (backing_store.get()) {
135 CleanWeakMap(&backing_store_map_); 135 CleanWeakMap(&backing_store_map_);
136 backing_store_map_[file_identifier] = backing_store->GetWeakPtr(); 136 backing_store_map_[file_identifier] = backing_store->GetWeakPtr();
137 // If an in-memory database, bind lifetime to this factory instance. 137 // If an in-memory database, bind lifetime to this factory instance.
138 if (open_in_memory) 138 if (open_in_memory)
139 session_only_backing_stores_.insert(backing_store); 139 session_only_backing_stores_.insert(backing_store);
140 140
141 // All backing stores associated with this factory should be of the same 141 // All backing stores associated with this factory should be of the same
142 // type. 142 // type.
143 DCHECK(session_only_backing_stores_.empty() || open_in_memory); 143 DCHECK(session_only_backing_stores_.empty() || open_in_memory);
144 144
(...skipping 14 matching lines...) Expand all
159 IDB_TRACE("IndexedDBFactory::open"); 159 IDB_TRACE("IndexedDBFactory::open");
160 const string16 unique_identifier = 160 const string16 unique_identifier =
161 ComputeUniqueIdentifier(name, database_identifier); 161 ComputeUniqueIdentifier(name, database_identifier);
162 162
163 scoped_refptr<IndexedDBDatabase> database_backend; 163 scoped_refptr<IndexedDBDatabase> database_backend;
164 IndexedDBDatabaseMap::iterator it = 164 IndexedDBDatabaseMap::iterator it =
165 database_backend_map_.find(unique_identifier); 165 database_backend_map_.find(unique_identifier);
166 if (it == database_backend_map_.end()) { 166 if (it == database_backend_map_.end()) {
167 scoped_refptr<IndexedDBBackingStore> backing_store = 167 scoped_refptr<IndexedDBBackingStore> backing_store =
168 OpenBackingStore(database_identifier, data_directory); 168 OpenBackingStore(database_identifier, data_directory);
169 if (!backing_store) { 169 if (!backing_store.get()) {
170 callbacks->OnError(IndexedDBDatabaseError( 170 callbacks->OnError(IndexedDBDatabaseError(
171 WebKit::WebIDBDatabaseExceptionUnknownError, 171 WebKit::WebIDBDatabaseExceptionUnknownError,
172 ASCIIToUTF16( 172 ASCIIToUTF16(
173 "Internal error opening backing store for indexedDB.open."))); 173 "Internal error opening backing store for indexedDB.open.")));
174 return; 174 return;
175 } 175 }
176 176
177 database_backend = IndexedDBDatabase::Create( 177 database_backend = IndexedDBDatabase::Create(
178 name, backing_store.get(), this, unique_identifier); 178 name, backing_store.get(), this, unique_identifier);
179 if (!database_backend) { 179 if (!database_backend.get()) {
180 callbacks->OnError(IndexedDBDatabaseError( 180 callbacks->OnError(IndexedDBDatabaseError(
181 WebKit::WebIDBDatabaseExceptionUnknownError, 181 WebKit::WebIDBDatabaseExceptionUnknownError,
182 ASCIIToUTF16( 182 ASCIIToUTF16(
183 "Internal error creating database backend for indexedDB.open."))); 183 "Internal error creating database backend for indexedDB.open.")));
184 return; 184 return;
185 } 185 }
186 186
187 database_backend_map_[unique_identifier] = database_backend.get(); 187 database_backend_map_[unique_identifier] = database_backend.get();
188 } else { 188 } else {
189 database_backend = it->second; 189 database_backend = it->second;
190 } 190 }
191 191
192 database_backend->OpenConnection( 192 database_backend->OpenConnection(
193 callbacks, database_callbacks, transaction_id, version); 193 callbacks, database_callbacks, transaction_id, version);
194 } 194 }
195 195
196 } // namespace content 196 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698