OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef CHROME_BROWSER_UI_WEBUI_QUOTA_INTERNALS_UI_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBUI_QUOTA_INTERNALS_UI_H_ |
6 #define CHROME_BROWSER_UI_WEBUI_QUOTA_INTERNALS_UI_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_QUOTA_INTERNALS_UI_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <set> | |
9 #include <string> | 10 #include <string> |
11 #include <utility> | |
12 #include <vector> | |
10 | 13 |
11 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | 14 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
12 #include "content/browser/webui/web_ui.h" | 15 #include "content/browser/webui/web_ui.h" |
16 #include "webkit/quota/quota_types.h" | |
17 #include "webkit/quota/quota_manager.h" | |
13 | 18 |
14 class TabContents; | 19 class TabContents; |
15 | 20 |
16 class QuotaInternalsUI : public WebUI { | 21 class QuotaInternalsUI : public WebUI { |
17 public: | 22 public: |
18 explicit QuotaInternalsUI(TabContents* contents); | 23 explicit QuotaInternalsUI(TabContents* contents); |
19 virtual ~QuotaInternalsUI() {} | 24 virtual ~QuotaInternalsUI() {} |
20 | 25 |
21 private: | 26 private: |
22 DISALLOW_COPY_AND_ASSIGN(QuotaInternalsUI); | 27 DISALLOW_COPY_AND_ASSIGN(QuotaInternalsUI); |
23 }; | 28 }; |
24 | 29 |
25 namespace quota_internals { | 30 namespace quota_internals { |
31 class QuotaInternalsProxy; | |
26 | 32 |
27 class QuotaInternalsHTMLSource : public ChromeURLDataManager::DataSource { | 33 class QuotaInternalsHTMLSource : public ChromeURLDataManager::DataSource { |
28 public: | 34 public: |
29 QuotaInternalsHTMLSource(); | 35 QuotaInternalsHTMLSource(); |
30 virtual void StartDataRequest(const std::string& path, | 36 virtual void StartDataRequest(const std::string& path, |
31 bool is_incognito, | 37 bool is_incognito, |
32 int request_id) OVERRIDE; | 38 int request_id) OVERRIDE; |
33 virtual std::string GetMimeType(const std::string&) const; | 39 virtual std::string GetMimeType(const std::string&) const; |
kinuko
2011/05/30 10:18:00
nit: OVERRIDE
tzik
2011/05/31 04:53:00
Done.
| |
34 | 40 |
35 private: | 41 private: |
36 virtual ~QuotaInternalsHTMLSource() {} | 42 virtual ~QuotaInternalsHTMLSource() {} |
37 DISALLOW_COPY_AND_ASSIGN(QuotaInternalsHTMLSource); | 43 DISALLOW_COPY_AND_ASSIGN(QuotaInternalsHTMLSource); |
38 }; | 44 }; |
39 | 45 |
46 class QuotaInternalsMessageHandler : public WebUIMessageHandler { | |
kinuko
2011/05/30 10:18:00
nit: could this be declared in .cc?
tzik
2011/05/31 04:53:00
Done.
| |
47 public: | |
48 struct GlobalData { | |
49 quota::StorageType type; | |
50 int64 usage; | |
51 int64 unlimited_usage; | |
52 int64 quota; | |
53 }; | |
54 | |
55 struct HostData { | |
56 std::string host; | |
57 quota::StorageType type; | |
58 int64 usage; | |
59 int64 quota; | |
60 }; | |
61 | |
62 struct OriginData { | |
63 GURL origin; | |
64 quota::StorageType type; | |
65 std::string host; | |
66 int in_use; | |
67 int used_count; | |
68 base::Time last_access_time; | |
69 }; | |
70 | |
71 QuotaInternalsMessageHandler(); | |
72 virtual ~QuotaInternalsMessageHandler(); | |
73 | |
74 virtual WebUIMessageHandler* Attach(WebUI* web_ui) OVERRIDE; | |
75 virtual void RegisterMessages() OVERRIDE; | |
76 | |
77 void ReportAvailableSpace(int64 available_space); | |
78 void ReportGlobalData(const GlobalData& global_data); | |
79 void ReportHostData(const std::vector<HostData>& hosts); | |
80 void ReportOriginData(const std::vector<OriginData>& origins); | |
81 | |
82 private: | |
83 void OnRequestData(const ListValue* list_unused); | |
84 void SendMessage(const std::string& message, const Value& value); | |
85 | |
86 DictionaryValue* GlobalDataToValue(const GlobalData& global_data); | |
87 ListValue* HostDataToValue(const HostData& host); | |
88 ListValue* OriginDataToValue(const OriginData& origin); | |
89 | |
90 scoped_refptr<QuotaInternalsProxy> proxy_; | |
91 | |
92 DISALLOW_COPY_AND_ASSIGN(QuotaInternalsMessageHandler); | |
93 }; | |
94 | |
95 typedef QuotaInternalsProxy QuotaInternalsProxyDeleter; | |
96 | |
97 class QuotaInternalsProxy | |
98 : public base::RefCountedThreadSafe<QuotaInternalsProxy, | |
99 QuotaInternalsProxyDeleter> { | |
kinuko
2011/05/30 10:18:00
As we're in chrome/ I think you can simply use Bro
tzik
2011/05/31 04:53:00
Done.
| |
100 public: | |
101 typedef QuotaInternalsMessageHandler::GlobalData GlobalData; | |
102 typedef QuotaInternalsMessageHandler::HostData HostData; | |
103 typedef QuotaInternalsMessageHandler::OriginData OriginData; | |
104 | |
105 explicit QuotaInternalsProxy(QuotaInternalsMessageHandler* handler); | |
106 | |
107 // Called on IO Thread | |
kinuko
2011/05/30 10:18:00
style-nit: please end the comment with '.'
tzik
2011/05/31 04:53:00
Done.
| |
108 void ReportAvailableSpace(int64 available_space); | |
109 void ReportGlobalData(const GlobalData& global_data); | |
110 void ReportHostData(const std::vector<HostData>& hosts); | |
111 void ReportOriginData(const std::vector<OriginData>& origins); | |
112 | |
113 // Called on UI Thread | |
114 void RequestData(quota::QuotaManager* quota_manager); | |
115 | |
116 static void Destruct(const QuotaInternalsProxy* proxy); | |
117 | |
118 private: | |
119 typedef quota::QuotaManager::QuotaTableEntry QuotaTableEntry; | |
120 typedef quota::QuotaManager::LastAccessTimeTableEntry | |
121 LastAccessTimeTableEntry; | |
122 typedef quota::QuotaManager::QuotaTableEntries QuotaTableEntries; | |
123 typedef quota::QuotaManager::LastAccessTimeTableEntries | |
124 LastAccessTimeTableEntries; | |
125 | |
126 // Called on UI Thread | |
127 void RunReportAvailableSpace(int64 available_space); | |
128 void RunReportGlobalData(const GlobalData& global_data); | |
129 void RunReportHostData(const std::vector<HostData>& hosts); | |
130 void RunReportOriginData(const std::vector<OriginData>& origins); | |
131 | |
132 // Called on IO Thread | |
133 void RunRequestData(scoped_refptr<quota::QuotaManager> quota_manager); | |
134 | |
135 // Called on IO Thread by QuotaManager as callback | |
136 void DidGetAvailableSpace(quota::QuotaStatusCode status, int64 space); | |
137 void DidGetGlobalQuota(quota::QuotaStatusCode status, | |
138 quota::StorageType type, | |
139 int64 quota); | |
140 void DidGetGlobalUsage(quota::StorageType type, | |
141 int64 usage, | |
142 int64 unlimited_usage); | |
143 void DidDumpQuotaTable(const QuotaTableEntries& entries); | |
144 void DidDumpLastAccessTimeTable(const LastAccessTimeTableEntries& entries); | |
145 void DidGetHostUsage(const std::string& host, | |
146 quota::StorageType type, | |
147 int64 usage); | |
148 | |
149 // Helper. Called on IO Thread | |
150 void RequestPerOriginData(quota::StorageType type); | |
151 void VisitHost(const std::string& host, quota::StorageType type); | |
152 void GetHostUsage(const std::string& host, quota::StorageType type); | |
153 | |
154 // base::ScopedCallbackFactory<QuotaInternalsProxy> callback_factory_; | |
kinuko
2011/05/30 10:18:00
you forgot to delete this line?
tzik
2011/05/31 04:53:00
Done.
| |
155 scoped_refptr<base::MessageLoopProxy> io_thread_, ui_thread_; | |
156 | |
157 // Used on UI Thread | |
158 QuotaInternalsMessageHandler* handler_; | |
159 | |
160 // Used on IO Thread | |
161 base::ScopedCallbackFactory<QuotaInternalsProxy> callback_factory_; | |
162 base::WeakPtr<quota::QuotaManager> quota_manager_; | |
163 std::set<std::pair<std::string, quota::StorageType> > | |
164 hosts_visited_, hosts_pending_; | |
165 std::vector<HostData> report_pending_; | |
166 | |
167 friend class QuotaInternalsMessageHandler; | |
168 friend class DeleteTask<const QuotaInternalsProxy>; | |
169 | |
170 virtual ~QuotaInternalsProxy() {} | |
171 }; | |
40 } // namespace quota_internals | 172 } // namespace quota_internals |
41 | 173 |
42 #endif // CHROME_BROWSER_UI_WEBUI_QUOTA_INTERNALS_UI_H_ | 174 #endif // CHROME_BROWSER_UI_WEBUI_QUOTA_INTERNALS_UI_H_ |
43 | |
OLD | NEW |