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

Side by Side Diff: chrome/browser/ui/webui/quota_internals_handler.cc

Issue 7084024: Add chrome://quota-internals/ (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: '' Created 9 years, 5 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/webui/quota_internals_handler.h"
6
7 #include <string>
8
9 #include "base/values.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/ui/webui/quota_internals_proxy.h"
12 #include "chrome/browser/ui/webui/quota_internals_types.h"
13 #include "net/base/net_util.h"
14
15 namespace quota_internals {
16
17 QuotaInternalsHandler::QuotaInternalsHandler() {}
18
19 QuotaInternalsHandler::~QuotaInternalsHandler() {
20 if (proxy_)
21 proxy_->handler_ = NULL;
22 }
23
24 void QuotaInternalsHandler::RegisterMessages() {
25 DCHECK(web_ui_);
26 web_ui_->RegisterMessageCallback(
27 "requestData",
28 NewCallback(this, &QuotaInternalsHandler::OnRequestData));
29 }
30
31 void QuotaInternalsHandler::ReportAvailableSpace(int64 available_space) {
32 scoped_ptr<Value> avail(
33 Value::CreateDoubleValue(static_cast<double>(available_space)));
34 SendMessage("AvailableSpaceUpdated", *avail.get());
35 }
36
37 void QuotaInternalsHandler::ReportGlobalData(const GlobalData& data) {
38 scoped_ptr<Value> value(data.NewValue());
39 SendMessage("GlobalDataUpdated", *value);
40 }
41
42 void QuotaInternalsHandler::ReportHostData(const std::vector<HostData>& hosts) {
43 ListValue values;
44 typedef std::vector<HostData>::const_iterator iterator;
45 for (iterator itr(hosts.begin()); itr != hosts.end(); ++itr) {
46 values.Append(itr->NewValue());
47 }
48
49 SendMessage("HostDataUpdated", values);
50 }
51
52 void QuotaInternalsHandler::ReportOriginData(
53 const std::vector<OriginData>& origins) {
54 ListValue origins_value;
55 typedef std::vector<OriginData>::const_iterator iterator;
56 for (iterator itr(origins.begin()); itr != origins.end(); ++itr) {
57 origins_value.Append(itr->NewValue());
58 }
59
60 SendMessage("OriginDataUpdated", origins_value);
61 }
62
63 void QuotaInternalsHandler::ReportStatistics(const Statistics& stats) {
64 DictionaryValue dict;
65 typedef Statistics::const_iterator iterator;
66 for (iterator itr(stats.begin()); itr != stats.end(); ++itr) {
67 dict.SetString(itr->first, itr->second);
68 }
69
70 SendMessage("StatisticsUpdated", dict);
71 }
72
73 void QuotaInternalsHandler::SendMessage(const std::string& message,
74 const Value& value) {
75 scoped_ptr<Value> message_data(Value::CreateStringValue(message));
76 web_ui_->CallJavascriptFunction("cr.quota.messageHandler",
77 *message_data,
78 value);
79 }
80
81 void QuotaInternalsHandler::OnRequestData(const ListValue*) {
82 if (!proxy_)
83 proxy_ = new QuotaInternalsProxy(this);
84 proxy_->RequestData(web_ui_->GetProfile()->GetQuotaManager());
85 }
86
87 } // namespace quota_internals
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698