Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / chrome / browser / ui / webui / quota_internals / quota_internals_handler.cc
blob23c164a587c3d9c3f51f2db772ae303528af213e
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.
5 #include "chrome/browser/ui/webui/quota_internals/quota_internals_handler.h"
7 #include <string>
9 #include "base/bind.h"
10 #include "base/bind_helpers.h"
11 #include "base/values.h"
12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/ui/webui/quota_internals/quota_internals_proxy.h"
14 #include "chrome/browser/ui/webui/quota_internals/quota_internals_types.h"
15 #include "content/public/browser/storage_partition.h"
16 #include "content/public/browser/web_ui.h"
17 #include "net/base/net_util.h"
19 using content::BrowserContext;
21 namespace quota_internals {
23 QuotaInternalsHandler::QuotaInternalsHandler() {}
25 QuotaInternalsHandler::~QuotaInternalsHandler() {
26 if (proxy_.get())
27 proxy_->handler_ = NULL;
30 void QuotaInternalsHandler::RegisterMessages() {
31 web_ui()->RegisterMessageCallback("requestInfo",
32 base::Bind(&QuotaInternalsHandler::OnRequestInfo,
33 base::Unretained(this)));
36 void QuotaInternalsHandler::ReportAvailableSpace(int64 available_space) {
37 SendMessage("AvailableSpaceUpdated",
38 base::FundamentalValue(static_cast<double>(available_space)));
41 void QuotaInternalsHandler::ReportGlobalInfo(const GlobalStorageInfo& data) {
42 scoped_ptr<base::Value> value(data.NewValue());
43 SendMessage("GlobalInfoUpdated", *value);
46 void QuotaInternalsHandler::ReportPerHostInfo(
47 const std::vector<PerHostStorageInfo>& hosts) {
48 base::ListValue values;
49 typedef std::vector<PerHostStorageInfo>::const_iterator iterator;
50 for (iterator itr(hosts.begin()); itr != hosts.end(); ++itr) {
51 values.Append(itr->NewValue());
54 SendMessage("PerHostInfoUpdated", values);
57 void QuotaInternalsHandler::ReportPerOriginInfo(
58 const std::vector<PerOriginStorageInfo>& origins) {
59 base::ListValue origins_value;
60 typedef std::vector<PerOriginStorageInfo>::const_iterator iterator;
61 for (iterator itr(origins.begin()); itr != origins.end(); ++itr) {
62 origins_value.Append(itr->NewValue());
65 SendMessage("PerOriginInfoUpdated", origins_value);
68 void QuotaInternalsHandler::ReportStatistics(const Statistics& stats) {
69 base::DictionaryValue dict;
70 typedef Statistics::const_iterator iterator;
71 for (iterator itr(stats.begin()); itr != stats.end(); ++itr) {
72 dict.SetString(itr->first, itr->second);
75 SendMessage("StatisticsUpdated", dict);
78 void QuotaInternalsHandler::SendMessage(const std::string& message,
79 const base::Value& value) {
80 web_ui()->CallJavascriptFunction(
81 "cr.quota.messageHandler", base::StringValue(message), value);
84 void QuotaInternalsHandler::OnRequestInfo(const base::ListValue*) {
85 if (!proxy_.get())
86 proxy_ = new QuotaInternalsProxy(this);
87 proxy_->RequestInfo(
88 BrowserContext::GetDefaultStoragePartition(
89 Profile::FromWebUI(web_ui()))->GetQuotaManager());
92 } // namespace quota_internals