OLD | NEW |
(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 "requestInfo", |
| 28 NewCallback(this, &QuotaInternalsHandler::OnRequestInfo)); |
| 29 } |
| 30 |
| 31 void QuotaInternalsHandler::ReportAvailableSpace(int64 available_space) { |
| 32 scoped_ptr<base::Value> avail( |
| 33 base::Value::CreateDoubleValue(static_cast<double>(available_space))); |
| 34 SendMessage("AvailableSpaceUpdated", *avail); |
| 35 } |
| 36 |
| 37 void QuotaInternalsHandler::ReportGlobalInfo(const GlobalStorageInfo& data) { |
| 38 scoped_ptr<base::Value> value(data.NewValue()); |
| 39 SendMessage("GlobalInfoUpdated", *value); |
| 40 } |
| 41 |
| 42 void QuotaInternalsHandler::ReportPerHostInfo( |
| 43 const std::vector<PerHostStorageInfo>& hosts) { |
| 44 base::ListValue values; |
| 45 typedef std::vector<PerHostStorageInfo>::const_iterator iterator; |
| 46 for (iterator itr(hosts.begin()); itr != hosts.end(); ++itr) { |
| 47 values.Append(itr->NewValue()); |
| 48 } |
| 49 |
| 50 SendMessage("PerHostInfoUpdated", values); |
| 51 } |
| 52 |
| 53 void QuotaInternalsHandler::ReportPerOriginInfo( |
| 54 const std::vector<PerOriginStorageInfo>& origins) { |
| 55 base::ListValue origins_value; |
| 56 typedef std::vector<PerOriginStorageInfo>::const_iterator iterator; |
| 57 for (iterator itr(origins.begin()); itr != origins.end(); ++itr) { |
| 58 origins_value.Append(itr->NewValue()); |
| 59 } |
| 60 |
| 61 SendMessage("PerOriginInfoUpdated", origins_value); |
| 62 } |
| 63 |
| 64 void QuotaInternalsHandler::ReportStatistics(const Statistics& stats) { |
| 65 base::DictionaryValue dict; |
| 66 typedef Statistics::const_iterator iterator; |
| 67 for (iterator itr(stats.begin()); itr != stats.end(); ++itr) { |
| 68 dict.SetString(itr->first, itr->second); |
| 69 } |
| 70 |
| 71 SendMessage("StatisticsUpdated", dict); |
| 72 } |
| 73 |
| 74 void QuotaInternalsHandler::SendMessage(const std::string& message, |
| 75 const base::Value& value) { |
| 76 scoped_ptr<base::Value> message_data(base::Value::CreateStringValue(message)); |
| 77 web_ui_->CallJavascriptFunction("cr.quota.messageHandler", |
| 78 *message_data, |
| 79 value); |
| 80 } |
| 81 |
| 82 void QuotaInternalsHandler::OnRequestInfo(const base::ListValue*) { |
| 83 if (!proxy_) |
| 84 proxy_ = new QuotaInternalsProxy(this); |
| 85 proxy_->RequestInfo(web_ui_->GetProfile()->GetQuotaManager()); |
| 86 } |
| 87 |
| 88 } // namespace quota_internals |
OLD | NEW |