Chromium Code Reviews| Index: chrome/browser/ui/webui/quota_internals_types.cc |
| diff --git a/chrome/browser/ui/webui/quota_internals_types.cc b/chrome/browser/ui/webui/quota_internals_types.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..4200fce56297cd06df701db726b0d54d220e84de |
| --- /dev/null |
| +++ b/chrome/browser/ui/webui/quota_internals_types.cc |
| @@ -0,0 +1,90 @@ |
| +// 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_types.h" |
| + |
| +#include "base/logging.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/values.h" |
| +#include "net/base/net_util.h" |
| + |
| +namespace { |
| + |
| +std::string StorageTypeToString(quota::StorageType type) { |
| + switch (type) { |
| + case quota::kStorageTypeTemporary: |
| + return "temporary"; |
| + case quota::kStorageTypePersistent: |
| + return "persistent"; |
| + default: |
| + return "unknown"; |
| + } |
| +} |
| + |
| +} // anonymous namespace |
| + |
| +namespace quota_internals { |
| + |
| +GlobalStorageInfo::GlobalStorageInfo(quota::StorageType type) |
| + : type_(type), usage_(-1), unlimited_usage_(-1), quota_(-1) { |
| +} |
| + |
| +Value* GlobalStorageInfo::NewValue() const { |
| + scoped_ptr<DictionaryValue> dict(new DictionaryValue); |
|
Evan Stade
2011/07/07 20:58:17
not much point in using a scoped_ptr here
tzik
2011/07/07 23:00:35
Done.
|
| + dict->SetString("type", StorageTypeToString(type_)); |
| + if (usage_ >= 0) |
| + dict->SetDouble("usage", static_cast<double>(usage_)); |
|
Evan Stade
2011/07/07 20:58:17
maybe we should have a LongInteger Value type (or
tzik
2011/07/07 23:00:35
I want it too. ECMAScript should have richer datat
Evan Stade
2011/07/11 20:53:23
I thought you were using double because int (base
tzik
2011/07/12 02:43:44
Yes, It may be greater than 2^31.
|
| + if (unlimited_usage_ >= 0) |
| + dict->SetDouble("unlimitedUsage", static_cast<double>(unlimited_usage_)); |
| + if (quota_ >= 0) |
| + dict->SetDouble("quota", static_cast<double>(quota_)); |
| + return dict.release(); |
| +} |
| + |
| +PerHostStorageInfo::PerHostStorageInfo(const std::string& host, |
| + quota::StorageType type) |
| + : host_(host), type_(type), usage_(-1), quota_(-1) { |
| +} |
| + |
| +Value* PerHostStorageInfo::NewValue() const { |
| + scoped_ptr<DictionaryValue> dict(new DictionaryValue); |
|
Evan Stade
2011/07/07 20:58:17
ditto
tzik
2011/07/07 23:00:35
Done.
|
| + DCHECK(!host_.empty()); |
| + dict->SetString("host", host_); |
| + dict->SetString("type", StorageTypeToString(type_)); |
| + if (usage_ >= 0) |
| + dict->SetDouble("usage", static_cast<double>(usage_)); |
| + if (quota_ >= 0) |
| + dict->SetDouble("quota", static_cast<double>(quota_)); |
| + return dict.release(); |
| +} |
| + |
| +PerOriginStorageInfo::PerOriginStorageInfo(const GURL& origin, |
| + quota::StorageType type) |
| + : origin_(origin), |
| + type_(type), |
| + host_(net::GetHostOrSpecFromURL(origin)), |
| + in_use_(-1), |
| + used_count_(-1) { |
| +} |
| + |
| +Value* PerOriginStorageInfo::NewValue() const { |
| + scoped_ptr<DictionaryValue> dict(new DictionaryValue); |
|
Evan Stade
2011/07/07 20:58:17
ditto
tzik
2011/07/07 23:00:35
Done.
|
| + DCHECK(!origin_.is_empty()); |
| + DCHECK(!host_.empty()); |
| + dict->SetString("origin", origin_.spec()); |
| + dict->SetString("type", StorageTypeToString(type_)); |
| + dict->SetString("host", host_); |
| + if (in_use_ >= 0) |
| + dict->SetBoolean("inUse", in_use_ ? true : false); |
| + if (used_count_ >= 0) |
| + dict->SetInteger("usedCount", used_count_); |
| + if (!last_access_time_.is_null()) |
| + dict->SetDouble("lastAccessTime", last_access_time_.ToDoubleT() * 1000.0); |
| + if (!last_modified_time_.is_null()) |
|
Evan Stade
2011/07/07 20:58:17
curlies for if statements that have multi-line bod
tzik
2011/07/07 23:00:35
Done.
|
| + dict->SetDouble("lastModifiedTime", |
| + last_modified_time_.ToDoubleT() * 1000.0); |
| + return dict.release(); |
| +} |
| + |
| +} // namespace quota_internals |