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

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: Patch for landing, nits addressed 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 web_ui->RegisterMessageCallback(
26 "getAllOrigins",
27 base::Bind(&IndexedDBInternalsUI::GetAllOrigins,
28 base::Unretained(this)));
29
17 WebUIDataSource* source = 30 WebUIDataSource* source =
18 WebUIDataSource::Create(chrome::kChromeUIIndexedDBInternalsHost); 31 WebUIDataSource::Create(chrome::kChromeUIIndexedDBInternalsHost);
19 32 source->SetUseJsonJSFormatV2();
20 source->SetJsonPath("strings.js"); 33 source->SetJsonPath("strings.js");
21 source->AddResourcePath("indexeddb_internals.js", 34 source->AddResourcePath("indexeddb_internals.js",
22 IDR_INDEXED_DB_INTERNALS_JS); 35 IDR_INDEXED_DB_INTERNALS_JS);
23 source->AddResourcePath("indexeddb_internals.css", 36 source->AddResourcePath("indexeddb_internals.css",
24 IDR_INDEXED_DB_INTERNALS_CSS); 37 IDR_INDEXED_DB_INTERNALS_CSS);
25 source->SetDefaultResource(IDR_INDEXED_DB_INTERNALS_HTML); 38 source->SetDefaultResource(IDR_INDEXED_DB_INTERNALS_HTML);
26 39
27 BrowserContext* browser_context = 40 BrowserContext* browser_context =
28 web_ui->GetWebContents()->GetBrowserContext(); 41 web_ui->GetWebContents()->GetBrowserContext();
29 WebUIDataSource::Add(browser_context, source); 42 WebUIDataSource::Add(browser_context, source);
30 } 43 }
31 44
32 IndexedDBInternalsUI::~IndexedDBInternalsUI() { 45 IndexedDBInternalsUI::~IndexedDBInternalsUI() {
33 } 46 }
47
48 void IndexedDBInternalsUI::GetAllOrigins(const base::ListValue* args) {
49 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
50
51 BrowserContext* browser_context =
52 web_ui()->GetWebContents()->GetBrowserContext();
53
54 // TODO(alecflett): do this for each storage partition in the context
55 StoragePartition* partition =
56 BrowserContext::GetDefaultStoragePartition(browser_context);
57 scoped_refptr<IndexedDBContext> context = partition->GetIndexedDBContext();
58
59 BrowserThread::PostTask(
60 BrowserThread::WEBKIT_DEPRECATED, FROM_HERE,
61 base::Bind(
62 &IndexedDBInternalsUI::GetAllOriginsOnWebkitThread,
63 base::Unretained(this),
64 context));
34 } 65 }
66
67 bool HostNameComparator(const IndexedDBInfo& i, const IndexedDBInfo& j) {
68 return i.origin.host() < j.origin.host();
69 }
70
71 void IndexedDBInternalsUI::GetAllOriginsOnWebkitThread(
72 scoped_refptr<IndexedDBContext> context) {
awong 2013/04/17 21:20:02 const scoped_refptr<IndexedDBContext>& is preferre
73 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
74
75 scoped_ptr<std::vector<IndexedDBInfo> > origins(
76 new std::vector<IndexedDBInfo>(context->GetAllOriginsInfo()));
77 std::sort(origins->begin(), origins->end(), HostNameComparator);
78
79 BrowserThread::PostTask(
80 BrowserThread::UI, FROM_HERE,
81 base::Bind(&IndexedDBInternalsUI::OnOriginsReady, base::Unretained(this),
82 base::Passed(&origins)));
83 }
84
85 void IndexedDBInternalsUI::OnOriginsReady(
86 scoped_ptr<std::vector<IndexedDBInfo> > origins) {
87 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
88 base::ListValue urls;
89 for (std::vector<IndexedDBInfo>::const_iterator iter = origins->begin();
90 iter != origins->end(); ++iter) {
91 base::DictionaryValue* info = new DictionaryValue;
92 info->SetString("url", iter->origin.spec());
93 info->SetDouble("size", iter->size);
94 info->SetDouble("last_modified", iter->last_modified.ToJsTime());
95 urls.Append(info);
96 }
97 web_ui()->CallJavascriptFunction("indexeddb.onOriginsReady", urls);
98 }
99 }
awong 2013/04/17 21:20:02 add a newline and comment } // namespace conten
OLDNEW
« no previous file with comments | « content/browser/indexed_db/indexed_db_internals_ui.h ('k') | content/browser/resources/indexed_db/indexeddb_internals.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698