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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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>
8
9 #include "base/bind.h"
10 #include "base/threading/platform_thread.h"
11 #include "base/values.h"
12 #include "content/public/browser/browser_context.h"
13 #include "content/public/browser/browser_thread.h"
14 #include "content/public/browser/storage_partition.h"
7 #include "content/public/browser/web_contents.h" 15 #include "content/public/browser/web_contents.h"
8 #include "content/public/browser/web_ui.h" 16 #include "content/public/browser/web_ui.h"
9 #include "content/public/browser/web_ui_data_source.h" 17 #include "content/public/browser/web_ui_data_source.h"
10 #include "content/public/common/url_constants.h" 18 #include "content/public/common/url_constants.h"
11 #include "grit/content_resources.h" 19 #include "grit/content_resources.h"
12 20
13 namespace content { 21 namespace content {
14 22
15 IndexedDBInternalsUI::IndexedDBInternalsUI(WebUI* web_ui) 23 IndexedDBInternalsUI::IndexedDBInternalsUI(WebUI* web_ui)
16 : WebUIController(web_ui) { 24 : WebUIController(web_ui),
25 fetching_(false) {
26 web_ui->RegisterMessageCallback(
27 "getAllOrigins",
28 base::Bind(&IndexedDBInternalsUI::GetAllOrigins,
29 base::Unretained(this)));
30
17 WebUIDataSource* source = 31 WebUIDataSource* source =
18 WebUIDataSource::Create(chrome::kChromeUIIndexedDBInternalsHost); 32 WebUIDataSource::Create(chrome::kChromeUIIndexedDBInternalsHost);
19 33 source->SetUseJsonJSFormatV2();
20 source->SetJsonPath("strings.js"); 34 source->SetJsonPath("strings.js");
21 source->AddResourcePath("indexeddb_internals.js", 35 source->AddResourcePath("indexeddb_internals.js",
22 IDR_INDEXED_DB_INTERNALS_JS); 36 IDR_INDEXED_DB_INTERNALS_JS);
23 source->AddResourcePath("indexeddb_internals.css", 37 source->AddResourcePath("indexeddb_internals.css",
24 IDR_INDEXED_DB_INTERNALS_CSS); 38 IDR_INDEXED_DB_INTERNALS_CSS);
25 source->SetDefaultResource(IDR_INDEXED_DB_INTERNALS_HTML); 39 source->SetDefaultResource(IDR_INDEXED_DB_INTERNALS_HTML);
26 40
27 BrowserContext* browser_context = 41 BrowserContext* browser_context =
28 web_ui->GetWebContents()->GetBrowserContext(); 42 web_ui->GetWebContents()->GetBrowserContext();
29 WebUIDataSource::Add(browser_context, source); 43 WebUIDataSource::Add(browser_context, source);
30 } 44 }
31 45
32 IndexedDBInternalsUI::~IndexedDBInternalsUI() { 46 IndexedDBInternalsUI::~IndexedDBInternalsUI() {
33 } 47 }
48
49 void IndexedDBInternalsUI::GetAllOrigins(const base::ListValue* args) {
jsbell 2013/04/11 18:56:20 Add a DCHECK that this is on the UI thread?
50 DCHECK(!fetching_);
51
52 fetching_ = true;
53 BrowserContext* browser_context =
54 web_ui()->GetWebContents()->GetBrowserContext();
55
56 // TODO(alecflett): do this for each storage partition in the context
57 StoragePartition* partition =
58 BrowserContext::GetDefaultStoragePartition(browser_context);
59 scoped_refptr<IndexedDBContext> context = partition->GetIndexedDBContext();
60
61 BrowserThread::PostTask(
62 BrowserThread::WEBKIT_DEPRECATED, FROM_HERE,
63 base::Bind(
64 &IndexedDBInternalsUI::GetAllOriginsOnWebkitThread,
65 base::Unretained(this),
66 context));
34 } 67 }
68
69 bool sort_by_hostname(const IndexedDBInfo& i, const IndexedDBInfo& j) {
jsbell 2013/04/11 18:56:20 Nit: SortByHostName or e.g. HostNameComparator
70 return i.origin.host() < j.origin.host();
71 }
72
73 void IndexedDBInternalsUI::GetAllOriginsOnWebkitThread(
74 scoped_refptr<IndexedDBContext> context) {
75 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
76
77 scoped_ptr<std::vector<IndexedDBInfo> > origins(
78 new std::vector<IndexedDBInfo>(context->GetAllOriginsInfo()));
79 sort(origins->begin(), origins->end(), sort_by_hostname);
jsbell 2013/04/11 18:56:20 Nit: std::sort
80
81 BrowserThread::PostTask(
82 BrowserThread::UI, FROM_HERE,
83 base::Bind(&IndexedDBInternalsUI::OnOriginsReady, base::Unretained(this),
84 base::Passed(&origins)));
85 }
86
87 void IndexedDBInternalsUI::OnOriginsReady(
jsbell 2013/04/11 18:56:20 Add a DCHECK that this is on the UI thread?
88 scoped_ptr<std::vector<IndexedDBInfo> > origins) {
89 base::ListValue urls;
90 fetching_ = false;
91 for (std::vector<IndexedDBInfo>::const_iterator iter = origins->begin();
92 iter != origins->end(); ++iter) {
93 base::DictionaryValue* info = new DictionaryValue;
94 info->SetString("url", iter->origin.spec());
95 info->SetDouble("size", iter->size);
96 info->SetDouble("last_modified", iter->last_modified.ToJsTime());
97 urls.Append(info);
98 }
99 web_ui()->CallJavascriptFunction("indexeddb.onOriginsReady", urls);
100 }
101 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698