| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "extensions/browser/api/storage/settings_storage_quota_enforcer.h" | 5 #include "extensions/browser/api/storage/settings_storage_quota_enforcer.h" |
| 6 | 6 |
| 7 #include <memory> |
| 8 |
| 7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 8 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
| 9 #include "base/memory/scoped_ptr.h" | |
| 10 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 11 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
| 12 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
| 13 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
| 14 #include "extensions/common/extension_api.h" | 15 #include "extensions/common/extension_api.h" |
| 15 | 16 |
| 16 namespace extensions { | 17 namespace extensions { |
| 17 | 18 |
| 18 namespace { | 19 namespace { |
| 19 | 20 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 } | 66 } |
| 66 CHECK(name); | 67 CHECK(name); |
| 67 return ValueStore::Status(ValueStore::QUOTA_EXCEEDED, | 68 return ValueStore::Status(ValueStore::QUOTA_EXCEEDED, |
| 68 base::StringPrintf("%s quota exceeded", name)); | 69 base::StringPrintf("%s quota exceeded", name)); |
| 69 } | 70 } |
| 70 | 71 |
| 71 } // namespace | 72 } // namespace |
| 72 | 73 |
| 73 SettingsStorageQuotaEnforcer::SettingsStorageQuotaEnforcer( | 74 SettingsStorageQuotaEnforcer::SettingsStorageQuotaEnforcer( |
| 74 const Limits& limits, | 75 const Limits& limits, |
| 75 scoped_ptr<ValueStore> delegate) | 76 std::unique_ptr<ValueStore> delegate) |
| 76 : limits_(limits), | 77 : limits_(limits), |
| 77 delegate_(std::move(delegate)), | 78 delegate_(std::move(delegate)), |
| 78 used_total_(0), | 79 used_total_(0), |
| 79 usage_calculated_(false) {} | 80 usage_calculated_(false) {} |
| 80 | 81 |
| 81 SettingsStorageQuotaEnforcer::~SettingsStorageQuotaEnforcer() {} | 82 SettingsStorageQuotaEnforcer::~SettingsStorageQuotaEnforcer() {} |
| 82 | 83 |
| 83 size_t SettingsStorageQuotaEnforcer::GetBytesInUse(const std::string& key) { | 84 size_t SettingsStorageQuotaEnforcer::GetBytesInUse(const std::string& key) { |
| 84 LazyCalculateUsage(); | 85 LazyCalculateUsage(); |
| 85 std::map<std::string, size_t>::iterator maybe_used = | 86 std::map<std::string, size_t>::iterator maybe_used = |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 return; | 254 return; |
| 254 auto it = used_per_setting_.find(key); | 255 auto it = used_per_setting_.find(key); |
| 255 if (it == used_per_setting_.end()) | 256 if (it == used_per_setting_.end()) |
| 256 return; | 257 return; |
| 257 DCHECK_GE(used_total_, it->second); | 258 DCHECK_GE(used_total_, it->second); |
| 258 used_total_ -= it->second; | 259 used_total_ -= it->second; |
| 259 used_per_setting_.erase(it); | 260 used_per_setting_.erase(it); |
| 260 } | 261 } |
| 261 | 262 |
| 262 } // namespace extensions | 263 } // namespace extensions |
| OLD | NEW |