| Index: chrome/browser/ui/webui/quota_internals_handler.cc
|
| diff --git a/chrome/browser/ui/webui/quota_internals_handler.cc b/chrome/browser/ui/webui/quota_internals_handler.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..ff894b4d286307542fcbce48ae47f8a5bae8959d
|
| --- /dev/null
|
| +++ b/chrome/browser/ui/webui/quota_internals_handler.cc
|
| @@ -0,0 +1,87 @@
|
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "chrome/browser/ui/webui/quota_internals_handler.h"
|
| +
|
| +#include <string>
|
| +
|
| +#include "base/values.h"
|
| +#include "chrome/browser/profiles/profile.h"
|
| +#include "chrome/browser/ui/webui/quota_internals_proxy.h"
|
| +#include "chrome/browser/ui/webui/quota_internals_types.h"
|
| +#include "net/base/net_util.h"
|
| +
|
| +namespace quota_internals {
|
| +
|
| +QuotaInternalsHandler::QuotaInternalsHandler() {}
|
| +
|
| +QuotaInternalsHandler::~QuotaInternalsHandler() {
|
| + if (proxy_)
|
| + proxy_->handler_ = NULL;
|
| +}
|
| +
|
| +void QuotaInternalsHandler::RegisterMessages() {
|
| + DCHECK(web_ui_);
|
| + web_ui_->RegisterMessageCallback(
|
| + "requestData",
|
| + NewCallback(this, &QuotaInternalsHandler::OnRequestData));
|
| +}
|
| +
|
| +void QuotaInternalsHandler::ReportAvailableSpace(int64 available_space) {
|
| + scoped_ptr<Value> avail(
|
| + Value::CreateDoubleValue(static_cast<double>(available_space)));
|
| + SendMessage("AvailableSpaceUpdated", *avail.get());
|
| +}
|
| +
|
| +void QuotaInternalsHandler::ReportGlobalData(const GlobalData& data) {
|
| + scoped_ptr<Value> value(data.NewValue());
|
| + SendMessage("GlobalDataUpdated", *value);
|
| +}
|
| +
|
| +void QuotaInternalsHandler::ReportHostData(const std::vector<HostData>& hosts) {
|
| + ListValue values;
|
| + typedef std::vector<HostData>::const_iterator iterator;
|
| + for (iterator itr(hosts.begin()); itr != hosts.end(); ++itr) {
|
| + values.Append(itr->NewValue());
|
| + }
|
| +
|
| + SendMessage("HostDataUpdated", values);
|
| +}
|
| +
|
| +void QuotaInternalsHandler::ReportOriginData(
|
| + const std::vector<OriginData>& origins) {
|
| + ListValue origins_value;
|
| + typedef std::vector<OriginData>::const_iterator iterator;
|
| + for (iterator itr(origins.begin()); itr != origins.end(); ++itr) {
|
| + origins_value.Append(itr->NewValue());
|
| + }
|
| +
|
| + SendMessage("OriginDataUpdated", origins_value);
|
| +}
|
| +
|
| +void QuotaInternalsHandler::ReportStatistics(const Statistics& stats) {
|
| + DictionaryValue dict;
|
| + typedef Statistics::const_iterator iterator;
|
| + for (iterator itr(stats.begin()); itr != stats.end(); ++itr) {
|
| + dict.SetString(itr->first, itr->second);
|
| + }
|
| +
|
| + SendMessage("StatisticsUpdated", dict);
|
| +}
|
| +
|
| +void QuotaInternalsHandler::SendMessage(const std::string& message,
|
| + const Value& value) {
|
| + scoped_ptr<Value> message_data(Value::CreateStringValue(message));
|
| + web_ui_->CallJavascriptFunction("cr.quota.messageHandler",
|
| + *message_data,
|
| + value);
|
| +}
|
| +
|
| +void QuotaInternalsHandler::OnRequestData(const ListValue*) {
|
| + if (!proxy_)
|
| + proxy_ = new QuotaInternalsProxy(this);
|
| + proxy_->RequestData(web_ui_->GetProfile()->GetQuotaManager());
|
| +}
|
| +
|
| +} // namespace quota_internals
|
|
|