| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 BrowserContext* browser_context = | 146 BrowserContext* browser_context = |
| 147 web_ui()->GetWebContents()->GetBrowserContext(); | 147 web_ui()->GetWebContents()->GetBrowserContext(); |
| 148 | 148 |
| 149 scoped_refptr<IndexedDBContextImpl> result_context; | 149 scoped_refptr<IndexedDBContextImpl> result_context; |
| 150 StoragePartition* result_partition; | 150 StoragePartition* result_partition; |
| 151 scoped_ptr<ContextList> contexts(new ContextList); | 151 scoped_ptr<ContextList> contexts(new ContextList); |
| 152 BrowserContext::StoragePartitionCallback cb = base::Bind( | 152 BrowserContext::StoragePartitionCallback cb = base::Bind( |
| 153 &FindContext, partition_path, &result_partition, &result_context); | 153 &FindContext, partition_path, &result_partition, &result_context); |
| 154 BrowserContext::ForEachStoragePartition(browser_context, cb); | 154 BrowserContext::ForEachStoragePartition(browser_context, cb); |
| 155 DCHECK(result_partition); | 155 DCHECK(result_partition); |
| 156 DCHECK(result_context.get()); | 156 DCHECK(result_context); |
| 157 | 157 |
| 158 result_context->TaskRunner()->PostTask( | 158 result_context->TaskRunner()->PostTask( |
| 159 FROM_HERE, | 159 FROM_HERE, |
| 160 base::Bind(&IndexedDBInternalsUI::DownloadOriginDataOnIndexedDBThread, | 160 base::Bind(&IndexedDBInternalsUI::DownloadOriginDataOnIndexedDBThread, |
| 161 base::Unretained(this), | 161 base::Unretained(this), |
| 162 result_partition->GetPath(), | 162 result_partition->GetPath(), |
| 163 result_context, | 163 result_context, |
| 164 origin_url)); | 164 origin_url)); |
| 165 } | 165 } |
| 166 | 166 |
| 167 void IndexedDBInternalsUI::DownloadOriginDataOnIndexedDBThread( | 167 void IndexedDBInternalsUI::DownloadOriginDataOnIndexedDBThread( |
| 168 const base::FilePath& partition_path, | 168 const base::FilePath& partition_path, |
| 169 const scoped_refptr<IndexedDBContextImpl> context, | 169 const scoped_refptr<IndexedDBContextImpl> context, |
| 170 const GURL& origin_url) { | 170 const GURL& origin_url) { |
| 171 DCHECK(context->TaskRunner()->RunsTasksOnCurrentThread()); | 171 DCHECK(context->TaskRunner()->RunsTasksOnCurrentThread()); |
| 172 | 172 |
| 173 if (!context->IsInOriginSet(origin_url)) | 173 if (!context->IsInOriginSet(origin_url)) |
| 174 return; | 174 return; |
| 175 | 175 |
| 176 context->ForceClose(origin_url); | 176 context->ForceClose(origin_url); |
| 177 | 177 |
| 178 base::ScopedTempDir temp_dir; | 178 base::ScopedTempDir temp_dir; |
| 179 if (!temp_dir.CreateUniqueTempDir()) | 179 if (!temp_dir.CreateUniqueTempDir()) |
| 180 return; | 180 return; |
| 181 | 181 |
| 182 // This will get cleaned up on the File thread after the download | 182 // This will get cleaned up on the File thread after the download |
| 183 // has completed. | 183 // has completed. |
| 184 base::FilePath temp_path = temp_dir.Take(); | 184 base::FilePath temp_path = temp_dir.Take(); |
| 185 | 185 |
| 186 std::string origin_id = | 186 std::string origin_id = webkit_database::GetIdentifierFromOrigin(origin_url); |
| 187 webkit_database::GetIdentifierFromOrigin(origin_url); | |
| 188 base::FilePath zip_path = | 187 base::FilePath zip_path = |
| 189 temp_path.AppendASCII(origin_id).AddExtension(FILE_PATH_LITERAL("zip")); | 188 temp_path.AppendASCII(origin_id).AddExtension(FILE_PATH_LITERAL("zip")); |
| 190 | 189 |
| 191 // This happens on the "webkit" thread (which is really just the IndexedDB | 190 // This happens on the "webkit" thread (which is really just the IndexedDB |
| 192 // thread) as a simple way to avoid another script reopening the origin | 191 // thread) as a simple way to avoid another script reopening the origin |
| 193 // while we are zipping. | 192 // while we are zipping. |
| 194 zip::Zip(context->GetFilePath(origin_url), zip_path, true); | 193 zip::Zip(context->GetFilePath(origin_url), zip_path, true); |
| 195 | 194 |
| 196 BrowserThread::PostTask(BrowserThread::UI, | 195 BrowserThread::PostTask(BrowserThread::UI, |
| 197 FROM_HERE, | 196 FROM_HERE, |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 return; | 281 return; |
| 283 } | 282 } |
| 284 | 283 |
| 285 item->AddObserver(new FileDeleter(temp_path)); | 284 item->AddObserver(new FileDeleter(temp_path)); |
| 286 web_ui()->CallJavascriptFunction("indexeddb.onOriginDownloadReady", | 285 web_ui()->CallJavascriptFunction("indexeddb.onOriginDownloadReady", |
| 287 base::StringValue(partition_path.value()), | 286 base::StringValue(partition_path.value()), |
| 288 base::StringValue(origin_url.spec())); | 287 base::StringValue(origin_url.spec())); |
| 289 } | 288 } |
| 290 | 289 |
| 291 } // namespace content | 290 } // namespace content |
| OLD | NEW |