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

Unified Diff: content/browser/indexed_db/indexed_db_internals_ui.cc

Issue 14118002: Implement read-only indexedb-internals (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 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 side-by-side diff with in-line comments
Download patch
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..cd88a022d29e5e74e67edf923b4d23511f00b10c 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,16 @@
namespace content {
IndexedDBInternalsUI::IndexedDBInternalsUI(WebUI* web_ui)
- : WebUIController(web_ui) {
+ : WebUIController(web_ui),
+ fetching_(false) {
+ 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 +45,57 @@ IndexedDBInternalsUI::IndexedDBInternalsUI(WebUI* web_ui)
IndexedDBInternalsUI::~IndexedDBInternalsUI() {
}
+
+void IndexedDBInternalsUI::GetAllOrigins(const base::ListValue* args) {
jsbell 2013/04/11 18:56:20 Add a DCHECK that this is on the UI thread?
+ DCHECK(!fetching_);
+
+ fetching_ = true;
+ 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 sort_by_hostname(const IndexedDBInfo& i, const IndexedDBInfo& j) {
jsbell 2013/04/11 18:56:20 Nit: SortByHostName or e.g. HostNameComparator
+ return i.origin.host() < j.origin.host();
+}
+
+void IndexedDBInternalsUI::GetAllOriginsOnWebkitThread(
+ scoped_refptr<IndexedDBContext> context) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
+
+ scoped_ptr<std::vector<IndexedDBInfo> > origins(
+ new std::vector<IndexedDBInfo>(context->GetAllOriginsInfo()));
+ sort(origins->begin(), origins->end(), sort_by_hostname);
jsbell 2013/04/11 18:56:20 Nit: std::sort
+
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(&IndexedDBInternalsUI::OnOriginsReady, base::Unretained(this),
+ base::Passed(&origins)));
+}
+
+void IndexedDBInternalsUI::OnOriginsReady(
jsbell 2013/04/11 18:56:20 Add a DCHECK that this is on the UI thread?
+ scoped_ptr<std::vector<IndexedDBInfo> > origins) {
+ base::ListValue urls;
+ fetching_ = false;
+ 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);
+}
}

Powered by Google App Engine
This is Rietveld 408576698