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_types.h"
7 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "base/values.h"
10 #include "net/base/net_util.h"
14 std::string StorageTypeToString(storage::StorageType type) {
16 case storage::kStorageTypeTemporary:
18 case storage::kStorageTypePersistent:
20 case storage::kStorageTypeSyncable:
22 case storage::kStorageTypeQuotaNotManaged:
23 return "quota not managed";
24 case storage::kStorageTypeUnknown:
30 } // anonymous namespace
32 namespace quota_internals {
34 GlobalStorageInfo::GlobalStorageInfo(storage::StorageType type)
35 : type_(type), usage_(-1), unlimited_usage_(-1), quota_(-1) {
38 GlobalStorageInfo::~GlobalStorageInfo() {}
40 base::Value* GlobalStorageInfo::NewValue() const {
41 // TODO(tzik): Add CreateLongIntegerValue to base/values.h and remove
42 // all static_cast<double> in this file.
43 base::DictionaryValue* dict = new base::DictionaryValue;
44 dict->SetString("type", StorageTypeToString(type_));
46 dict->SetDouble("usage", static_cast<double>(usage_));
47 if (unlimited_usage_ >= 0)
48 dict->SetDouble("unlimitedUsage", static_cast<double>(unlimited_usage_));
50 dict->SetDouble("quota", static_cast<double>(quota_));
54 PerHostStorageInfo::PerHostStorageInfo(const std::string& host,
55 storage::StorageType type)
56 : host_(host), type_(type), usage_(-1), quota_(-1) {
59 PerHostStorageInfo::~PerHostStorageInfo() {}
61 base::Value* PerHostStorageInfo::NewValue() const {
62 base::DictionaryValue* dict = new base::DictionaryValue;
63 DCHECK(!host_.empty());
64 dict->SetString("host", host_);
65 dict->SetString("type", StorageTypeToString(type_));
67 dict->SetDouble("usage", static_cast<double>(usage_));
69 dict->SetDouble("quota", static_cast<double>(quota_));
73 PerOriginStorageInfo::PerOriginStorageInfo(const GURL& origin,
74 storage::StorageType type)
77 host_(net::GetHostOrSpecFromURL(origin)),
82 PerOriginStorageInfo::~PerOriginStorageInfo() {}
84 base::Value* PerOriginStorageInfo::NewValue() const {
85 base::DictionaryValue* dict = new base::DictionaryValue;
86 DCHECK(!origin_.is_empty());
87 DCHECK(!host_.empty());
88 dict->SetString("origin", origin_.spec());
89 dict->SetString("type", StorageTypeToString(type_));
90 dict->SetString("host", host_);
92 dict->SetBoolean("inUse", (in_use_ > 0));
94 dict->SetInteger("usedCount", used_count_);
95 if (!last_access_time_.is_null())
96 dict->SetDouble("lastAccessTime", last_access_time_.ToDoubleT() * 1000.0);
97 if (!last_modified_time_.is_null()) {
98 dict->SetDouble("lastModifiedTime",
99 last_modified_time_.ToDoubleT() * 1000.0);
104 } // namespace quota_internals