Chromium Code Reviews| Index: content/browser/indexed_db/indexed_db_internals_ui.cc |
| diff --git a/content/browser/indexed_db/indexed_db_internals_ui.cc b/content/browser/indexed_db/indexed_db_internals_ui.cc |
| index eefbc7f7830e1d4a59024395f36c7a256071b555..6d0871c36ff86839c44a6b390bf3335cea7a0989 100644 |
| --- a/content/browser/indexed_db/indexed_db_internals_ui.cc |
| +++ b/content/browser/indexed_db/indexed_db_internals_ui.cc |
| @@ -4,6 +4,14 @@ |
| #include "content/browser/indexed_db/indexed_db_internals_ui.h" |
| +#include <algorithm> |
| + |
| +#include "base/bind.h" |
| +#include "base/threading/platform_thread.h" |
| +#include "base/values.h" |
| +#include "content/public/browser/browser_context.h" |
| +#include "content/public/browser/browser_thread.h" |
| +#include "content/public/browser/storage_partition.h" |
| #include "content/public/browser/web_contents.h" |
| #include "content/public/browser/web_ui.h" |
| #include "content/public/browser/web_ui_data_source.h" |
| @@ -13,10 +21,15 @@ |
| namespace content { |
| IndexedDBInternalsUI::IndexedDBInternalsUI(WebUI* web_ui) |
| - : WebUIController(web_ui) { |
| + : WebUIController(web_ui) { |
| + web_ui->RegisterMessageCallback( |
| + "getAllOrigins", |
| + base::Bind(&IndexedDBInternalsUI::GetAllOrigins, |
| + base::Unretained(this))); |
| + |
| WebUIDataSource* source = |
| WebUIDataSource::Create(chrome::kChromeUIIndexedDBInternalsHost); |
| - |
| + source->SetUseJsonJSFormatV2(); |
| source->SetJsonPath("strings.js"); |
| source->AddResourcePath("indexeddb_internals.js", |
| IDR_INDEXED_DB_INTERNALS_JS); |
| @@ -31,4 +44,56 @@ IndexedDBInternalsUI::IndexedDBInternalsUI(WebUI* web_ui) |
| IndexedDBInternalsUI::~IndexedDBInternalsUI() { |
| } |
| + |
| +void IndexedDBInternalsUI::GetAllOrigins(const base::ListValue* args) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + |
| + BrowserContext* browser_context = |
| + web_ui()->GetWebContents()->GetBrowserContext(); |
| + |
| + // TODO(alecflett): do this for each storage partition in the context |
| + StoragePartition* partition = |
| + BrowserContext::GetDefaultStoragePartition(browser_context); |
| + scoped_refptr<IndexedDBContext> context = partition->GetIndexedDBContext(); |
| + |
| + BrowserThread::PostTask( |
| + BrowserThread::WEBKIT_DEPRECATED, FROM_HERE, |
| + base::Bind( |
| + &IndexedDBInternalsUI::GetAllOriginsOnWebkitThread, |
| + base::Unretained(this), |
| + context)); |
| +} |
| + |
| +bool HostNameComparator(const IndexedDBInfo& i, const IndexedDBInfo& j) { |
| + return i.origin.host() < j.origin.host(); |
| +} |
| + |
| +void IndexedDBInternalsUI::GetAllOriginsOnWebkitThread( |
| + scoped_refptr<IndexedDBContext> context) { |
|
awong
2013/04/17 21:20:02
const scoped_refptr<IndexedDBContext>& is preferre
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); |
| + |
| + scoped_ptr<std::vector<IndexedDBInfo> > origins( |
| + new std::vector<IndexedDBInfo>(context->GetAllOriginsInfo())); |
| + std::sort(origins->begin(), origins->end(), HostNameComparator); |
| + |
| + BrowserThread::PostTask( |
| + BrowserThread::UI, FROM_HERE, |
| + base::Bind(&IndexedDBInternalsUI::OnOriginsReady, base::Unretained(this), |
| + base::Passed(&origins))); |
| +} |
| + |
| +void IndexedDBInternalsUI::OnOriginsReady( |
| + scoped_ptr<std::vector<IndexedDBInfo> > origins) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + base::ListValue urls; |
| + for (std::vector<IndexedDBInfo>::const_iterator iter = origins->begin(); |
| + iter != origins->end(); ++iter) { |
| + base::DictionaryValue* info = new DictionaryValue; |
| + info->SetString("url", iter->origin.spec()); |
| + info->SetDouble("size", iter->size); |
| + info->SetDouble("last_modified", iter->last_modified.ToJsTime()); |
| + urls.Append(info); |
| + } |
| + web_ui()->CallJavascriptFunction("indexeddb.onOriginsReady", urls); |
| +} |
| } |
|
awong
2013/04/17 21:20:02
add a newline and comment
} // namespace conten
|