| OLD | NEW |
| 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_internals_ui.h" | 5 #include "content/browser/indexed_db/indexed_db_internals_ui.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 WebUIDataSource::Add(browser_context, source); | 76 WebUIDataSource::Add(browser_context, source); |
| 77 } | 77 } |
| 78 | 78 |
| 79 IndexedDBInternalsUI::~IndexedDBInternalsUI() {} | 79 IndexedDBInternalsUI::~IndexedDBInternalsUI() {} |
| 80 | 80 |
| 81 void IndexedDBInternalsUI::AddContextFromStoragePartition( | 81 void IndexedDBInternalsUI::AddContextFromStoragePartition( |
| 82 StoragePartition* partition) { | 82 StoragePartition* partition) { |
| 83 scoped_refptr<IndexedDBContext> context = partition->GetIndexedDBContext(); | 83 scoped_refptr<IndexedDBContext> context = partition->GetIndexedDBContext(); |
| 84 context->TaskRunner()->PostTask( | 84 context->TaskRunner()->PostTask( |
| 85 FROM_HERE, | 85 FROM_HERE, |
| 86 base::Bind(&IndexedDBInternalsUI::GetAllOriginsOnIndexedDBThread, | 86 base::BindOnce(&IndexedDBInternalsUI::GetAllOriginsOnIndexedDBThread, |
| 87 base::Unretained(this), | 87 base::Unretained(this), context, partition->GetPath())); |
| 88 context, | |
| 89 partition->GetPath())); | |
| 90 } | 88 } |
| 91 | 89 |
| 92 void IndexedDBInternalsUI::GetAllOrigins(const base::ListValue* args) { | 90 void IndexedDBInternalsUI::GetAllOrigins(const base::ListValue* args) { |
| 93 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 91 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 94 | 92 |
| 95 BrowserContext* browser_context = | 93 BrowserContext* browser_context = |
| 96 web_ui()->GetWebContents()->GetBrowserContext(); | 94 web_ui()->GetWebContents()->GetBrowserContext(); |
| 97 | 95 |
| 98 BrowserContext::StoragePartitionCallback cb = | 96 BrowserContext::StoragePartitionCallback cb = |
| 99 base::Bind(&IndexedDBInternalsUI::AddContextFromStoragePartition, | 97 base::Bind(&IndexedDBInternalsUI::AddContextFromStoragePartition, |
| 100 base::Unretained(this)); | 98 base::Unretained(this)); |
| 101 BrowserContext::ForEachStoragePartition(browser_context, cb); | 99 BrowserContext::ForEachStoragePartition(browser_context, cb); |
| 102 } | 100 } |
| 103 | 101 |
| 104 void IndexedDBInternalsUI::GetAllOriginsOnIndexedDBThread( | 102 void IndexedDBInternalsUI::GetAllOriginsOnIndexedDBThread( |
| 105 scoped_refptr<IndexedDBContext> context, | 103 scoped_refptr<IndexedDBContext> context, |
| 106 const base::FilePath& context_path) { | 104 const base::FilePath& context_path) { |
| 107 DCHECK(context->TaskRunner()->RunsTasksInCurrentSequence()); | 105 DCHECK(context->TaskRunner()->RunsTasksInCurrentSequence()); |
| 108 | 106 |
| 109 IndexedDBContextImpl* context_impl = | 107 IndexedDBContextImpl* context_impl = |
| 110 static_cast<IndexedDBContextImpl*>(context.get()); | 108 static_cast<IndexedDBContextImpl*>(context.get()); |
| 111 | 109 |
| 112 std::unique_ptr<base::ListValue> info_list( | 110 std::unique_ptr<base::ListValue> info_list( |
| 113 context_impl->GetAllOriginsDetails()); | 111 context_impl->GetAllOriginsDetails()); |
| 114 bool is_incognito = context_impl->is_incognito(); | 112 bool is_incognito = context_impl->is_incognito(); |
| 115 | 113 |
| 116 BrowserThread::PostTask( | 114 BrowserThread::PostTask( |
| 117 BrowserThread::UI, | 115 BrowserThread::UI, FROM_HERE, |
| 118 FROM_HERE, | 116 base::BindOnce(&IndexedDBInternalsUI::OnOriginsReady, |
| 119 base::Bind(&IndexedDBInternalsUI::OnOriginsReady, | 117 base::Unretained(this), base::Passed(&info_list), |
| 120 base::Unretained(this), | 118 is_incognito ? base::FilePath() : context_path)); |
| 121 base::Passed(&info_list), | |
| 122 is_incognito ? base::FilePath() : context_path)); | |
| 123 } | 119 } |
| 124 | 120 |
| 125 void IndexedDBInternalsUI::OnOriginsReady( | 121 void IndexedDBInternalsUI::OnOriginsReady( |
| 126 std::unique_ptr<base::ListValue> origins, | 122 std::unique_ptr<base::ListValue> origins, |
| 127 const base::FilePath& path) { | 123 const base::FilePath& path) { |
| 128 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 124 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 129 web_ui()->CallJavascriptFunctionUnsafe("indexeddb.onOriginsReady", *origins, | 125 web_ui()->CallJavascriptFunctionUnsafe("indexeddb.onOriginsReady", *origins, |
| 130 base::Value(path.value())); | 126 base::Value(path.value())); |
| 131 } | 127 } |
| 132 | 128 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 | 180 |
| 185 base::FilePath partition_path; | 181 base::FilePath partition_path; |
| 186 Origin origin; | 182 Origin origin; |
| 187 scoped_refptr<IndexedDBContextImpl> context; | 183 scoped_refptr<IndexedDBContextImpl> context; |
| 188 if (!GetOriginData(args, &partition_path, &origin, &context)) | 184 if (!GetOriginData(args, &partition_path, &origin, &context)) |
| 189 return; | 185 return; |
| 190 | 186 |
| 191 DCHECK(context.get()); | 187 DCHECK(context.get()); |
| 192 context->TaskRunner()->PostTask( | 188 context->TaskRunner()->PostTask( |
| 193 FROM_HERE, | 189 FROM_HERE, |
| 194 base::Bind(&IndexedDBInternalsUI::DownloadOriginDataOnIndexedDBThread, | 190 base::BindOnce(&IndexedDBInternalsUI::DownloadOriginDataOnIndexedDBThread, |
| 195 base::Unretained(this), partition_path, context, origin)); | 191 base::Unretained(this), partition_path, context, origin)); |
| 196 } | 192 } |
| 197 | 193 |
| 198 void IndexedDBInternalsUI::ForceCloseOrigin(const base::ListValue* args) { | 194 void IndexedDBInternalsUI::ForceCloseOrigin(const base::ListValue* args) { |
| 199 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 195 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 200 | 196 |
| 201 base::FilePath partition_path; | 197 base::FilePath partition_path; |
| 202 Origin origin; | 198 Origin origin; |
| 203 scoped_refptr<IndexedDBContextImpl> context; | 199 scoped_refptr<IndexedDBContextImpl> context; |
| 204 if (!GetOriginData(args, &partition_path, &origin, &context)) | 200 if (!GetOriginData(args, &partition_path, &origin, &context)) |
| 205 return; | 201 return; |
| 206 | 202 |
| 207 context->TaskRunner()->PostTask( | 203 context->TaskRunner()->PostTask( |
| 208 FROM_HERE, | 204 FROM_HERE, |
| 209 base::Bind(&IndexedDBInternalsUI::ForceCloseOriginOnIndexedDBThread, | 205 base::BindOnce(&IndexedDBInternalsUI::ForceCloseOriginOnIndexedDBThread, |
| 210 base::Unretained(this), partition_path, context, origin)); | 206 base::Unretained(this), partition_path, context, origin)); |
| 211 } | 207 } |
| 212 | 208 |
| 213 void IndexedDBInternalsUI::DownloadOriginDataOnIndexedDBThread( | 209 void IndexedDBInternalsUI::DownloadOriginDataOnIndexedDBThread( |
| 214 const base::FilePath& partition_path, | 210 const base::FilePath& partition_path, |
| 215 const scoped_refptr<IndexedDBContextImpl> context, | 211 const scoped_refptr<IndexedDBContextImpl> context, |
| 216 const Origin& origin) { | 212 const Origin& origin) { |
| 217 DCHECK(context->TaskRunner()->RunsTasksInCurrentSequence()); | 213 DCHECK(context->TaskRunner()->RunsTasksInCurrentSequence()); |
| 218 // This runs on the IndexedDB task runner to prevent script from reopening | 214 // This runs on the IndexedDB task runner to prevent script from reopening |
| 219 // the origin while we are zipping. | 215 // the origin while we are zipping. |
| 220 | 216 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 236 std::string origin_id = storage::GetIdentifierFromOrigin(origin.GetURL()); | 232 std::string origin_id = storage::GetIdentifierFromOrigin(origin.GetURL()); |
| 237 base::FilePath zip_path = | 233 base::FilePath zip_path = |
| 238 temp_path.AppendASCII(origin_id).AddExtension(FILE_PATH_LITERAL("zip")); | 234 temp_path.AppendASCII(origin_id).AddExtension(FILE_PATH_LITERAL("zip")); |
| 239 | 235 |
| 240 std::vector<base::FilePath> paths = context->GetStoragePaths(origin); | 236 std::vector<base::FilePath> paths = context->GetStoragePaths(origin); |
| 241 zip::ZipWithFilterCallback(context->data_path(), zip_path, | 237 zip::ZipWithFilterCallback(context->data_path(), zip_path, |
| 242 base::Bind(AllowWhitelistedPaths, paths)); | 238 base::Bind(AllowWhitelistedPaths, paths)); |
| 243 | 239 |
| 244 BrowserThread::PostTask( | 240 BrowserThread::PostTask( |
| 245 BrowserThread::UI, FROM_HERE, | 241 BrowserThread::UI, FROM_HERE, |
| 246 base::Bind(&IndexedDBInternalsUI::OnDownloadDataReady, | 242 base::BindOnce(&IndexedDBInternalsUI::OnDownloadDataReady, |
| 247 base::Unretained(this), partition_path, origin, temp_path, | 243 base::Unretained(this), partition_path, origin, temp_path, |
| 248 zip_path, connection_count)); | 244 zip_path, connection_count)); |
| 249 } | 245 } |
| 250 | 246 |
| 251 void IndexedDBInternalsUI::ForceCloseOriginOnIndexedDBThread( | 247 void IndexedDBInternalsUI::ForceCloseOriginOnIndexedDBThread( |
| 252 const base::FilePath& partition_path, | 248 const base::FilePath& partition_path, |
| 253 const scoped_refptr<IndexedDBContextImpl> context, | 249 const scoped_refptr<IndexedDBContextImpl> context, |
| 254 const Origin& origin) { | 250 const Origin& origin) { |
| 255 DCHECK(context->TaskRunner()->RunsTasksInCurrentSequence()); | 251 DCHECK(context->TaskRunner()->RunsTasksInCurrentSequence()); |
| 256 | 252 |
| 257 // Make sure the database hasn't been deleted since the page was loaded. | 253 // Make sure the database hasn't been deleted since the page was loaded. |
| 258 if (!context->HasOrigin(origin)) | 254 if (!context->HasOrigin(origin)) |
| 259 return; | 255 return; |
| 260 | 256 |
| 261 context->ForceClose(origin, IndexedDBContextImpl::FORCE_CLOSE_INTERNALS_PAGE); | 257 context->ForceClose(origin, IndexedDBContextImpl::FORCE_CLOSE_INTERNALS_PAGE); |
| 262 size_t connection_count = context->GetConnectionCount(origin); | 258 size_t connection_count = context->GetConnectionCount(origin); |
| 263 | 259 |
| 264 BrowserThread::PostTask( | 260 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 265 BrowserThread::UI, FROM_HERE, | 261 base::BindOnce(&IndexedDBInternalsUI::OnForcedClose, |
| 266 base::Bind(&IndexedDBInternalsUI::OnForcedClose, base::Unretained(this), | 262 base::Unretained(this), partition_path, |
| 267 partition_path, origin, connection_count)); | 263 origin, connection_count)); |
| 268 } | 264 } |
| 269 | 265 |
| 270 void IndexedDBInternalsUI::OnForcedClose(const base::FilePath& partition_path, | 266 void IndexedDBInternalsUI::OnForcedClose(const base::FilePath& partition_path, |
| 271 const Origin& origin, | 267 const Origin& origin, |
| 272 size_t connection_count) { | 268 size_t connection_count) { |
| 273 web_ui()->CallJavascriptFunctionUnsafe( | 269 web_ui()->CallJavascriptFunctionUnsafe( |
| 274 "indexeddb.onForcedClose", base::Value(partition_path.value()), | 270 "indexeddb.onForcedClose", base::Value(partition_path.value()), |
| 275 base::Value(origin.Serialize()), | 271 base::Value(origin.Serialize()), |
| 276 base::Value(static_cast<double>(connection_count))); | 272 base::Value(static_cast<double>(connection_count))); |
| 277 } | 273 } |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 } | 354 } |
| 359 | 355 |
| 360 item->AddObserver(new FileDeleter(temp_path)); | 356 item->AddObserver(new FileDeleter(temp_path)); |
| 361 web_ui()->CallJavascriptFunctionUnsafe( | 357 web_ui()->CallJavascriptFunctionUnsafe( |
| 362 "indexeddb.onOriginDownloadReady", base::Value(partition_path.value()), | 358 "indexeddb.onOriginDownloadReady", base::Value(partition_path.value()), |
| 363 base::Value(origin.Serialize()), | 359 base::Value(origin.Serialize()), |
| 364 base::Value(static_cast<double>(connection_count))); | 360 base::Value(static_cast<double>(connection_count))); |
| 365 } | 361 } |
| 366 | 362 |
| 367 } // namespace content | 363 } // namespace content |
| OLD | NEW |