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

Side by Side Diff: content/browser/indexed_db/indexed_db_internals_ui.cc

Issue 14156003: Support multiple storage partitions in chrome://indexeddb-internals/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix cocoa unit test 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> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/memory/scoped_vector.h"
10 #include "base/threading/platform_thread.h" 11 #include "base/threading/platform_thread.h"
11 #include "base/values.h" 12 #include "base/values.h"
12 #include "content/public/browser/browser_context.h" 13 #include "content/public/browser/browser_context.h"
13 #include "content/public/browser/browser_thread.h" 14 #include "content/public/browser/browser_thread.h"
14 #include "content/public/browser/storage_partition.h" 15 #include "content/public/browser/storage_partition.h"
15 #include "content/public/browser/web_contents.h" 16 #include "content/public/browser/web_contents.h"
16 #include "content/public/browser/web_ui.h" 17 #include "content/public/browser/web_ui.h"
17 #include "content/public/browser/web_ui_data_source.h" 18 #include "content/public/browser/web_ui_data_source.h"
18 #include "content/public/common/url_constants.h" 19 #include "content/public/common/url_constants.h"
19 #include "grit/content_resources.h" 20 #include "grit/content_resources.h"
20 21
21 namespace content { 22 namespace content {
22 23
23 IndexedDBInternalsUI::IndexedDBInternalsUI(WebUI* web_ui) 24 IndexedDBInternalsUI::IndexedDBInternalsUI(WebUI* web_ui)
24 : WebUIController(web_ui) { 25 : WebUIController(web_ui) {
25 web_ui->RegisterMessageCallback( 26 web_ui->RegisterMessageCallback(
26 "getAllOrigins", 27 "getAllOrigins",
27 base::Bind(&IndexedDBInternalsUI::GetAllOrigins, 28 base::Bind(&IndexedDBInternalsUI::GetAllOrigins, base::Unretained(this)));
28 base::Unretained(this)));
29 29
30 WebUIDataSource* source = 30 WebUIDataSource* source =
31 WebUIDataSource::Create(kChromeUIIndexedDBInternalsHost); 31 WebUIDataSource::Create(kChromeUIIndexedDBInternalsHost);
32 source->SetUseJsonJSFormatV2(); 32 source->SetUseJsonJSFormatV2();
33 source->SetJsonPath("strings.js"); 33 source->SetJsonPath("strings.js");
34 source->AddResourcePath("indexeddb_internals.js", 34 source->AddResourcePath("indexeddb_internals.js",
35 IDR_INDEXED_DB_INTERNALS_JS); 35 IDR_INDEXED_DB_INTERNALS_JS);
36 source->AddResourcePath("indexeddb_internals.css", 36 source->AddResourcePath("indexeddb_internals.css",
37 IDR_INDEXED_DB_INTERNALS_CSS); 37 IDR_INDEXED_DB_INTERNALS_CSS);
38 source->SetDefaultResource(IDR_INDEXED_DB_INTERNALS_HTML); 38 source->SetDefaultResource(IDR_INDEXED_DB_INTERNALS_HTML);
39 39
40 BrowserContext* browser_context = 40 BrowserContext* browser_context =
41 web_ui->GetWebContents()->GetBrowserContext(); 41 web_ui->GetWebContents()->GetBrowserContext();
42 WebUIDataSource::Add(browser_context, source); 42 WebUIDataSource::Add(browser_context, source);
43 } 43 }
44 44
45 IndexedDBInternalsUI::~IndexedDBInternalsUI() { 45 IndexedDBInternalsUI::~IndexedDBInternalsUI() {}
46
47 void IndexedDBInternalsUI::AddContextFromStoragePartition(
48 ContextList* contexts,
49 std::vector<base::FilePath>* paths,
50 StoragePartition* partition) {
51 scoped_refptr<IndexedDBContext> context = partition->GetIndexedDBContext();
52 contexts->push_back(context);
53 paths->push_back(partition->GetPath());
46 } 54 }
47 55
48 void IndexedDBInternalsUI::GetAllOrigins(const base::ListValue* args) { 56 void IndexedDBInternalsUI::GetAllOrigins(const base::ListValue* args) {
49 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 57 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
50 58
51 BrowserContext* browser_context = 59 BrowserContext* browser_context =
52 web_ui()->GetWebContents()->GetBrowserContext(); 60 web_ui()->GetWebContents()->GetBrowserContext();
53 61
54 // TODO(alecflett): do this for each storage partition in the context 62 scoped_ptr<std::vector<base::FilePath> > paths(
55 StoragePartition* partition = 63 new std::vector<base::FilePath>);
56 BrowserContext::GetDefaultStoragePartition(browser_context); 64 scoped_ptr<ContextList> contexts(new ContextList);
57 scoped_refptr<IndexedDBContext> context = partition->GetIndexedDBContext(); 65 BrowserContext::StoragePartitionCallback cb =
66 base::Bind(&AddContextFromStoragePartition, contexts.get(), paths.get());
67 BrowserContext::ForEachStoragePartition(browser_context, cb);
58 68
59 BrowserThread::PostTask( 69 BrowserThread::PostTask(
60 BrowserThread::WEBKIT_DEPRECATED, FROM_HERE, 70 BrowserThread::WEBKIT_DEPRECATED,
61 base::Bind( 71 FROM_HERE,
62 &IndexedDBInternalsUI::GetAllOriginsOnWebkitThread, 72 base::Bind(&IndexedDBInternalsUI::GetAllOriginsOnWebkitThread,
63 base::Unretained(this), 73 base::Unretained(this),
64 context)); 74 base::Passed(&contexts),
75 base::Passed(&paths)));
65 } 76 }
66 77
67 bool HostNameComparator(const IndexedDBInfo& i, const IndexedDBInfo& j) { 78 bool HostNameComparator(const IndexedDBInfo& i, const IndexedDBInfo& j) {
68 return i.origin.host() < j.origin.host(); 79 return i.origin_.host() < j.origin_.host();
69 } 80 }
70 81
71 void IndexedDBInternalsUI::GetAllOriginsOnWebkitThread( 82 void IndexedDBInternalsUI::GetAllOriginsOnWebkitThread(
72 scoped_refptr<IndexedDBContext> context) { 83 scoped_ptr<ContextList> contexts,
84 scoped_ptr<std::vector<base::FilePath> > context_paths) {
73 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 85 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
86 DCHECK_EQ(contexts->size(), context_paths->size());
74 87
75 scoped_ptr<std::vector<IndexedDBInfo> > origins( 88 std::vector<base::FilePath>::const_iterator path_iter =
76 new std::vector<IndexedDBInfo>(context->GetAllOriginsInfo())); 89 context_paths->begin();
77 std::sort(origins->begin(), origins->end(), HostNameComparator); 90 for (ContextList::const_iterator iter = contexts->begin();
91 iter != contexts->end();
92 ++iter, ++path_iter) {
93 IndexedDBContext* context = *iter;
94 const base::FilePath& context_path = *path_iter;
78 95
79 BrowserThread::PostTask( 96 scoped_ptr<std::vector<IndexedDBInfo> > info_list(
80 BrowserThread::UI, FROM_HERE, 97 new std::vector<IndexedDBInfo>(context->GetAllOriginsInfo()));
81 base::Bind(&IndexedDBInternalsUI::OnOriginsReady, base::Unretained(this), 98 std::sort(info_list->begin(), info_list->end(), HostNameComparator);
82 base::Passed(&origins))); 99 BrowserThread::PostTask(BrowserThread::UI,
100 FROM_HERE,
101 base::Bind(&IndexedDBInternalsUI::OnOriginsReady,
102 base::Unretained(this),
103 base::Passed(&info_list),
104 context_path));
105 }
83 } 106 }
84 107
85 void IndexedDBInternalsUI::OnOriginsReady( 108 void IndexedDBInternalsUI::OnOriginsReady(
86 scoped_ptr<std::vector<IndexedDBInfo> > origins) { 109 scoped_ptr<std::vector<IndexedDBInfo> > origins,
110 const base::FilePath& path) {
87 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 111 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
88 base::ListValue urls; 112 base::ListValue urls;
89 for (std::vector<IndexedDBInfo>::const_iterator iter = origins->begin(); 113 for (std::vector<IndexedDBInfo>::const_iterator iter = origins->begin();
90 iter != origins->end(); ++iter) { 114 iter != origins->end();
115 ++iter) {
91 base::DictionaryValue* info = new DictionaryValue; 116 base::DictionaryValue* info = new DictionaryValue;
92 info->SetString("url", iter->origin.spec()); 117 info->SetString("url", iter->origin_.spec());
93 info->SetDouble("size", iter->size); 118 info->SetDouble("size", iter->size_);
94 info->SetDouble("last_modified", iter->last_modified.ToJsTime()); 119 info->SetDouble("last_modified", iter->last_modified_.ToJsTime());
120 info->SetString("path", iter->path_.value());
95 urls.Append(info); 121 urls.Append(info);
96 } 122 }
97 web_ui()->CallJavascriptFunction("indexeddb.onOriginsReady", urls); 123 web_ui()->CallJavascriptFunction(
124 "indexeddb.onOriginsReady", urls, base::StringValue(path.value()));
98 } 125 }
99 126
100 } // namespace content 127 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/indexed_db/indexed_db_internals_ui.h ('k') | content/browser/resources/indexed_db/indexeddb_internals.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698