OLD | NEW |
---|---|
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/threading/platform_thread.h" | 10 #include "base/threading/platform_thread.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 #include "base/memory/scoped_vector.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 { |
(...skipping 16 matching lines...) Expand all Loading... | |
38 source->SetDefaultResource(IDR_INDEXED_DB_INTERNALS_HTML); | 39 source->SetDefaultResource(IDR_INDEXED_DB_INTERNALS_HTML); |
39 | 40 |
40 BrowserContext* browser_context = | 41 BrowserContext* browser_context = |
41 web_ui->GetWebContents()->GetBrowserContext(); | 42 web_ui->GetWebContents()->GetBrowserContext(); |
42 WebUIDataSource::Add(browser_context, source); | 43 WebUIDataSource::Add(browser_context, source); |
43 } | 44 } |
44 | 45 |
45 IndexedDBInternalsUI::~IndexedDBInternalsUI() { | 46 IndexedDBInternalsUI::~IndexedDBInternalsUI() { |
46 } | 47 } |
47 | 48 |
49 void IndexedDBInternalsUI::AddContextFromStoragePartition( | |
50 ContextList* contexts, | |
51 std::vector<base::FilePath>* paths, | |
52 StoragePartition* partition) { | |
53 scoped_refptr<IndexedDBContext> context = partition->GetIndexedDBContext(); | |
54 contexts->push_back(context); | |
55 paths->push_back(partition->GetPath()); | |
56 } | |
57 | |
48 void IndexedDBInternalsUI::GetAllOrigins(const base::ListValue* args) { | 58 void IndexedDBInternalsUI::GetAllOrigins(const base::ListValue* args) { |
49 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 59 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
50 | 60 |
51 BrowserContext* browser_context = | 61 BrowserContext* browser_context = |
52 web_ui()->GetWebContents()->GetBrowserContext(); | 62 web_ui()->GetWebContents()->GetBrowserContext(); |
53 | 63 |
54 // TODO(alecflett): do this for each storage partition in the context | 64 scoped_ptr<std::vector<base::FilePath> > |
55 StoragePartition* partition = | 65 paths(new std::vector<base::FilePath>); |
56 BrowserContext::GetDefaultStoragePartition(browser_context); | 66 scoped_ptr<ContextList> contexts(new ContextList); |
57 scoped_refptr<IndexedDBContext> context = partition->GetIndexedDBContext(); | 67 BrowserContext::StoragePartitionCallback cb = |
68 base::Bind(&AddContextFromStoragePartition, contexts.get(), paths.get()); | |
69 BrowserContext::ForEachStoragePartition(browser_context, cb); | |
58 | 70 |
59 BrowserThread::PostTask( | 71 BrowserThread::PostTask( |
60 BrowserThread::WEBKIT_DEPRECATED, FROM_HERE, | 72 BrowserThread::WEBKIT_DEPRECATED, FROM_HERE, |
61 base::Bind( | 73 base::Bind( |
62 &IndexedDBInternalsUI::GetAllOriginsOnWebkitThread, | 74 &IndexedDBInternalsUI::GetAllOriginsOnWebkitThread, |
63 base::Unretained(this), | 75 base::Unretained(this), |
64 context)); | 76 base::Passed(&contexts), |
77 base::Passed(&paths))); | |
65 } | 78 } |
66 | 79 |
67 bool HostNameComparator(const IndexedDBInfo& i, const IndexedDBInfo& j) { | 80 bool HostNameComparator(const IndexedDBInfo& i, const IndexedDBInfo& j) { |
68 return i.origin.host() < j.origin.host(); | 81 return i.origin.host() < j.origin.host(); |
69 } | 82 } |
70 | 83 |
71 void IndexedDBInternalsUI::GetAllOriginsOnWebkitThread( | 84 void IndexedDBInternalsUI::GetAllOriginsOnWebkitThread( |
72 scoped_refptr<IndexedDBContext> context) { | 85 scoped_ptr<ContextList> contexts, |
86 scoped_ptr<std::vector<base::FilePath> > context_paths) { | |
73 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); | 87 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); |
88 DCHECK_EQ(contexts->size(), context_paths->size()); | |
jsbell
2013/04/12 21:25:59
As discussed offline, an alternative would be to m
| |
74 | 89 |
75 scoped_ptr<std::vector<IndexedDBInfo> > origins( | 90 std::vector<base::FilePath>::const_iterator path_iter = |
76 new std::vector<IndexedDBInfo>(context->GetAllOriginsInfo())); | 91 context_paths->begin(); |
77 std::sort(origins->begin(), origins->end(), HostNameComparator); | 92 for (ContextList::const_iterator iter = contexts->begin(); |
jsbell
2013/04/12 21:25:59
... although it would make this dual-iteration sli
| |
93 iter != contexts->end(); ++iter) { | |
michaeln
2013/04/12 23:00:31
nit: would dbl-iter be more clear with ++iter, ++p
| |
94 IndexedDBContext* context = *iter; | |
95 const base::FilePath& context_path = *path_iter; | |
78 | 96 |
79 BrowserThread::PostTask( | 97 scoped_ptr<std::vector<IndexedDBInfo> > info_list( |
80 BrowserThread::UI, FROM_HERE, | 98 new std::vector<IndexedDBInfo>(context->GetAllOriginsInfo())); |
81 base::Bind(&IndexedDBInternalsUI::OnOriginsReady, base::Unretained(this), | 99 std::sort(info_list->begin(), info_list->end(), HostNameComparator); |
82 base::Passed(&origins))); | 100 BrowserThread::PostTask( |
101 BrowserThread::UI, FROM_HERE, | |
102 base::Bind(&IndexedDBInternalsUI::OnOriginsReady, | |
103 base::Unretained(this), | |
104 base::Passed(&info_list), | |
105 context_path)); | |
106 ++path_iter; | |
107 } | |
83 } | 108 } |
84 | 109 |
85 void IndexedDBInternalsUI::OnOriginsReady( | 110 void IndexedDBInternalsUI::OnOriginsReady( |
86 scoped_ptr<std::vector<IndexedDBInfo> > origins) { | 111 scoped_ptr<std::vector<IndexedDBInfo> > origins, |
112 const base::FilePath& path) { | |
87 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 113 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
88 base::ListValue urls; | 114 base::ListValue urls; |
89 for (std::vector<IndexedDBInfo>::const_iterator iter = origins->begin(); | 115 for (std::vector<IndexedDBInfo>::const_iterator iter = origins->begin(); |
90 iter != origins->end(); ++iter) { | 116 iter != origins->end(); ++iter) { |
91 base::DictionaryValue* info = new DictionaryValue; | 117 base::DictionaryValue* info = new DictionaryValue; |
92 info->SetString("url", iter->origin.spec()); | 118 info->SetString("url", iter->origin.spec()); |
93 info->SetDouble("size", iter->size); | 119 info->SetDouble("size", iter->size); |
94 info->SetDouble("last_modified", iter->last_modified.ToJsTime()); | 120 info->SetDouble("last_modified", iter->last_modified.ToJsTime()); |
121 info->SetString("path", iter->path.value()); | |
95 urls.Append(info); | 122 urls.Append(info); |
96 } | 123 } |
97 web_ui()->CallJavascriptFunction("indexeddb.onOriginsReady", urls); | 124 web_ui()->CallJavascriptFunction("indexeddb.onOriginsReady", |
125 urls, | |
126 base::StringValue(path.value())); | |
98 } | 127 } |
99 } | 128 } |
OLD | NEW |