| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/extensions/api/storage/storage_api.h" | 5 #include "chrome/browser/extensions/api/storage/storage_api.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "chrome/browser/extensions/api/storage/settings_frontend.h" | 13 #include "chrome/browser/extensions/api/storage/settings_frontend.h" |
| 14 #include "chrome/browser/extensions/extension_service.h" | 14 #include "chrome/browser/extensions/extension_service.h" |
| 15 #include "chrome/browser/extensions/extensions_quota_service.h" | |
| 16 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/common/extensions/api/storage.h" | 16 #include "chrome/common/extensions/api/storage.h" |
| 18 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 18 #include "extensions/browser/quota_service.h" |
| 19 | 19 |
| 20 namespace extensions { | 20 namespace extensions { |
| 21 | 21 |
| 22 using content::BrowserThread; | 22 using content::BrowserThread; |
| 23 | 23 |
| 24 // SettingsFunction | 24 // SettingsFunction |
| 25 | 25 |
| 26 SettingsFunction::SettingsFunction() | 26 SettingsFunction::SettingsFunction() |
| 27 : settings_namespace_(settings_namespace::INVALID) {} | 27 : settings_namespace_(settings_namespace::INVALID) {} |
| 28 | 28 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 return keys; | 128 return keys; |
| 129 } | 129 } |
| 130 | 130 |
| 131 // Creates quota heuristics for settings modification. | 131 // Creates quota heuristics for settings modification. |
| 132 void GetModificationQuotaLimitHeuristics(QuotaLimitHeuristics* heuristics) { | 132 void GetModificationQuotaLimitHeuristics(QuotaLimitHeuristics* heuristics) { |
| 133 QuotaLimitHeuristic::Config longLimitConfig = { | 133 QuotaLimitHeuristic::Config longLimitConfig = { |
| 134 // See storage.json for current value. | 134 // See storage.json for current value. |
| 135 api::storage::sync::MAX_WRITE_OPERATIONS_PER_HOUR, | 135 api::storage::sync::MAX_WRITE_OPERATIONS_PER_HOUR, |
| 136 base::TimeDelta::FromHours(1) | 136 base::TimeDelta::FromHours(1) |
| 137 }; | 137 }; |
| 138 heuristics->push_back( | 138 heuristics->push_back(new QuotaService::TimedLimit( |
| 139 new ExtensionsQuotaService::TimedLimit( | 139 longLimitConfig, |
| 140 longLimitConfig, | 140 new QuotaLimitHeuristic::SingletonBucketMapper(), |
| 141 new QuotaLimitHeuristic::SingletonBucketMapper(), | 141 "MAX_WRITE_OPERATIONS_PER_HOUR")); |
| 142 "MAX_WRITE_OPERATIONS_PER_HOUR")); | |
| 143 | 142 |
| 144 // A max of 10 operations per minute, sustained over 10 minutes. | 143 // A max of 10 operations per minute, sustained over 10 minutes. |
| 145 QuotaLimitHeuristic::Config shortLimitConfig = { | 144 QuotaLimitHeuristic::Config shortLimitConfig = { |
| 146 // See storage.json for current value. | 145 // See storage.json for current value. |
| 147 api::storage::sync::MAX_SUSTAINED_WRITE_OPERATIONS_PER_MINUTE, | 146 api::storage::sync::MAX_SUSTAINED_WRITE_OPERATIONS_PER_MINUTE, |
| 148 base::TimeDelta::FromMinutes(1) | 147 base::TimeDelta::FromMinutes(1) |
| 149 }; | 148 }; |
| 150 heuristics->push_back( | 149 heuristics->push_back(new QuotaService::SustainedLimit( |
| 151 new ExtensionsQuotaService::SustainedLimit( | 150 base::TimeDelta::FromMinutes(10), |
| 152 base::TimeDelta::FromMinutes(10), | 151 shortLimitConfig, |
| 153 shortLimitConfig, | 152 new QuotaLimitHeuristic::SingletonBucketMapper(), |
| 154 new QuotaLimitHeuristic::SingletonBucketMapper(), | 153 "MAX_SUSTAINED_WRITE_OPERATIONS_PER_MINUTE")); |
| 155 "MAX_SUSTAINED_WRITE_OPERATIONS_PER_MINUTE")); | |
| 156 }; | 154 }; |
| 157 | 155 |
| 158 } // namespace | 156 } // namespace |
| 159 | 157 |
| 160 bool StorageStorageAreaGetFunction::RunWithStorage(ValueStore* storage) { | 158 bool StorageStorageAreaGetFunction::RunWithStorage(ValueStore* storage) { |
| 161 base::Value* input = NULL; | 159 base::Value* input = NULL; |
| 162 EXTENSION_FUNCTION_VALIDATE(args_->Get(0, &input)); | 160 EXTENSION_FUNCTION_VALIDATE(args_->Get(0, &input)); |
| 163 | 161 |
| 164 switch (input->GetType()) { | 162 switch (input->GetType()) { |
| 165 case base::Value::TYPE_NULL: | 163 case base::Value::TYPE_NULL: |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 bool StorageStorageAreaClearFunction::RunWithStorage(ValueStore* storage) { | 274 bool StorageStorageAreaClearFunction::RunWithStorage(ValueStore* storage) { |
| 277 return UseWriteResult(storage->Clear()); | 275 return UseWriteResult(storage->Clear()); |
| 278 } | 276 } |
| 279 | 277 |
| 280 void StorageStorageAreaClearFunction::GetQuotaLimitHeuristics( | 278 void StorageStorageAreaClearFunction::GetQuotaLimitHeuristics( |
| 281 QuotaLimitHeuristics* heuristics) const { | 279 QuotaLimitHeuristics* heuristics) const { |
| 282 GetModificationQuotaLimitHeuristics(heuristics); | 280 GetModificationQuotaLimitHeuristics(heuristics); |
| 283 } | 281 } |
| 284 | 282 |
| 285 } // namespace extensions | 283 } // namespace extensions |
| OLD | NEW |