| 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 source->SetDefaultResource(IDR_INDEXED_DB_INTERNALS_HTML); | 52 source->SetDefaultResource(IDR_INDEXED_DB_INTERNALS_HTML); |
| 53 | 53 |
| 54 BrowserContext* browser_context = | 54 BrowserContext* browser_context = |
| 55 web_ui->GetWebContents()->GetBrowserContext(); | 55 web_ui->GetWebContents()->GetBrowserContext(); |
| 56 WebUIDataSource::Add(browser_context, source); | 56 WebUIDataSource::Add(browser_context, source); |
| 57 } | 57 } |
| 58 | 58 |
| 59 IndexedDBInternalsUI::~IndexedDBInternalsUI() {} | 59 IndexedDBInternalsUI::~IndexedDBInternalsUI() {} |
| 60 | 60 |
| 61 void IndexedDBInternalsUI::AddContextFromStoragePartition( | 61 void IndexedDBInternalsUI::AddContextFromStoragePartition( |
| 62 ContextList* contexts, | |
| 63 std::vector<base::FilePath>* paths, | |
| 64 StoragePartition* partition) { | 62 StoragePartition* partition) { |
| 65 scoped_refptr<IndexedDBContext> context = partition->GetIndexedDBContext(); | 63 scoped_refptr<IndexedDBContext> context = partition->GetIndexedDBContext(); |
| 66 contexts->push_back(context); | 64 context->TaskRunner()->PostTask( |
| 67 paths->push_back(partition->GetPath()); | 65 FROM_HERE, |
| 66 base::Bind(&IndexedDBInternalsUI::GetAllOriginsOnIndexedDBThread, |
| 67 base::Unretained(this), |
| 68 context, |
| 69 partition->GetPath())); |
| 68 } | 70 } |
| 69 | 71 |
| 70 void IndexedDBInternalsUI::GetAllOrigins(const base::ListValue* args) { | 72 void IndexedDBInternalsUI::GetAllOrigins(const base::ListValue* args) { |
| 71 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 73 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 72 | 74 |
| 73 BrowserContext* browser_context = | 75 BrowserContext* browser_context = |
| 74 web_ui()->GetWebContents()->GetBrowserContext(); | 76 web_ui()->GetWebContents()->GetBrowserContext(); |
| 75 | 77 |
| 76 scoped_ptr<std::vector<base::FilePath> > paths( | |
| 77 new std::vector<base::FilePath>); | |
| 78 scoped_ptr<ContextList> contexts(new ContextList); | |
| 79 BrowserContext::StoragePartitionCallback cb = | 78 BrowserContext::StoragePartitionCallback cb = |
| 80 base::Bind(&AddContextFromStoragePartition, contexts.get(), paths.get()); | 79 base::Bind(&IndexedDBInternalsUI::AddContextFromStoragePartition, |
| 80 base::Unretained(this)); |
| 81 BrowserContext::ForEachStoragePartition(browser_context, cb); | 81 BrowserContext::ForEachStoragePartition(browser_context, cb); |
| 82 | |
| 83 BrowserThread::PostTask( | |
| 84 BrowserThread::WEBKIT_DEPRECATED, | |
| 85 FROM_HERE, | |
| 86 base::Bind(&IndexedDBInternalsUI::GetAllOriginsOnWebkitThread, | |
| 87 base::Unretained(this), | |
| 88 base::Passed(&contexts), | |
| 89 base::Passed(&paths))); | |
| 90 } | 82 } |
| 91 | 83 |
| 92 bool HostNameComparator(const IndexedDBInfo& i, const IndexedDBInfo& j) { | 84 static bool HostNameComparator(const IndexedDBInfo& i, const IndexedDBInfo& j) { |
| 93 return i.origin_.host() < j.origin_.host(); | 85 return i.origin_.host() < j.origin_.host(); |
| 94 } | 86 } |
| 95 | 87 |
| 96 void IndexedDBInternalsUI::GetAllOriginsOnWebkitThread( | 88 void IndexedDBInternalsUI::GetAllOriginsOnIndexedDBThread( |
| 97 const scoped_ptr<ContextList> contexts, | 89 scoped_refptr<IndexedDBContext> context, |
| 98 const scoped_ptr<std::vector<base::FilePath> > context_paths) { | 90 const base::FilePath& context_path) { |
| 99 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); | 91 DCHECK(context->OnIndexedDBThread()); |
| 100 DCHECK_EQ(contexts->size(), context_paths->size()); | |
| 101 | 92 |
| 102 std::vector<base::FilePath>::const_iterator path_iter = | 93 scoped_ptr<std::vector<IndexedDBInfo> > info_list( |
| 103 context_paths->begin(); | 94 new std::vector<IndexedDBInfo>(context->GetAllOriginsInfo())); |
| 104 for (ContextList::const_iterator iter = contexts->begin(); | 95 std::sort(info_list->begin(), info_list->end(), HostNameComparator); |
| 105 iter != contexts->end(); | 96 BrowserThread::PostTask(BrowserThread::UI, |
| 106 ++iter, ++path_iter) { | 97 FROM_HERE, |
| 107 IndexedDBContext* context = iter->get(); | 98 base::Bind(&IndexedDBInternalsUI::OnOriginsReady, |
| 108 const base::FilePath& context_path = *path_iter; | 99 base::Unretained(this), |
| 109 | 100 base::Passed(&info_list), |
| 110 scoped_ptr<std::vector<IndexedDBInfo> > info_list( | 101 context_path)); |
| 111 new std::vector<IndexedDBInfo>(context->GetAllOriginsInfo())); | |
| 112 std::sort(info_list->begin(), info_list->end(), HostNameComparator); | |
| 113 BrowserThread::PostTask(BrowserThread::UI, | |
| 114 FROM_HERE, | |
| 115 base::Bind(&IndexedDBInternalsUI::OnOriginsReady, | |
| 116 base::Unretained(this), | |
| 117 base::Passed(&info_list), | |
| 118 context_path)); | |
| 119 } | |
| 120 } | 102 } |
| 121 | 103 |
| 122 void IndexedDBInternalsUI::OnOriginsReady( | 104 void IndexedDBInternalsUI::OnOriginsReady( |
| 123 scoped_ptr<std::vector<IndexedDBInfo> > origins, | 105 scoped_ptr<std::vector<IndexedDBInfo> > origins, |
| 124 const base::FilePath& path) { | 106 const base::FilePath& path) { |
| 125 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 107 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 126 base::ListValue urls; | 108 base::ListValue urls; |
| 127 for (std::vector<IndexedDBInfo>::const_iterator iter = origins->begin(); | 109 for (std::vector<IndexedDBInfo>::const_iterator iter = origins->begin(); |
| 128 iter != origins->end(); | 110 iter != origins->end(); |
| 129 ++iter) { | 111 ++iter) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 | 151 |
| 170 scoped_refptr<IndexedDBContextImpl> result_context; | 152 scoped_refptr<IndexedDBContextImpl> result_context; |
| 171 StoragePartition* result_partition; | 153 StoragePartition* result_partition; |
| 172 scoped_ptr<ContextList> contexts(new ContextList); | 154 scoped_ptr<ContextList> contexts(new ContextList); |
| 173 BrowserContext::StoragePartitionCallback cb = base::Bind( | 155 BrowserContext::StoragePartitionCallback cb = base::Bind( |
| 174 &FindContext, partition_path, &result_partition, &result_context); | 156 &FindContext, partition_path, &result_partition, &result_context); |
| 175 BrowserContext::ForEachStoragePartition(browser_context, cb); | 157 BrowserContext::ForEachStoragePartition(browser_context, cb); |
| 176 DCHECK(result_partition); | 158 DCHECK(result_partition); |
| 177 DCHECK(result_context.get()); | 159 DCHECK(result_context.get()); |
| 178 | 160 |
| 179 BrowserThread::PostTask( | 161 result_context->TaskRunner()->PostTask( |
| 180 BrowserThread::WEBKIT_DEPRECATED, | |
| 181 FROM_HERE, | 162 FROM_HERE, |
| 182 base::Bind(&IndexedDBInternalsUI::DownloadOriginDataOnWebkitThread, | 163 base::Bind(&IndexedDBInternalsUI::DownloadOriginDataOnIndexedDBThread, |
| 183 base::Unretained(this), | 164 base::Unretained(this), |
| 184 result_partition->GetPath(), | 165 result_partition->GetPath(), |
| 185 result_context, | 166 result_context, |
| 186 origin_url)); | 167 origin_url)); |
| 187 } | 168 } |
| 188 | 169 |
| 189 void IndexedDBInternalsUI::DownloadOriginDataOnWebkitThread( | 170 void IndexedDBInternalsUI::DownloadOriginDataOnIndexedDBThread( |
| 190 const base::FilePath& partition_path, | 171 const base::FilePath& partition_path, |
| 191 const scoped_refptr<IndexedDBContextImpl> context, | 172 const scoped_refptr<IndexedDBContextImpl> context, |
| 192 const GURL& origin_url) { | 173 const GURL& origin_url) { |
| 193 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); | 174 DCHECK(context->OnIndexedDBThread()); |
| 194 | 175 |
| 195 if (!context->IsInOriginSet(origin_url)) | 176 if (!context->IsInOriginSet(origin_url)) |
| 196 return; | 177 return; |
| 197 | 178 |
| 198 context->ForceClose(origin_url); | 179 context->ForceClose(origin_url); |
| 199 | 180 |
| 200 base::ScopedTempDir temp_dir; | 181 base::ScopedTempDir temp_dir; |
| 201 if (!temp_dir.CreateUniqueTempDir()) | 182 if (!temp_dir.CreateUniqueTempDir()) |
| 202 return; | 183 return; |
| 203 | 184 |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 return; | 285 return; |
| 305 } | 286 } |
| 306 | 287 |
| 307 item->AddObserver(new FileDeleter(temp_path)); | 288 item->AddObserver(new FileDeleter(temp_path)); |
| 308 web_ui()->CallJavascriptFunction("indexeddb.onOriginDownloadReady", | 289 web_ui()->CallJavascriptFunction("indexeddb.onOriginDownloadReady", |
| 309 base::StringValue(partition_path.value()), | 290 base::StringValue(partition_path.value()), |
| 310 base::StringValue(origin_url.spec())); | 291 base::StringValue(origin_url.spec())); |
| 311 } | 292 } |
| 312 | 293 |
| 313 } // namespace content | 294 } // namespace content |
| OLD | NEW |