OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/quota_service.h" | 5 #include "extensions/browser/quota_service.h" |
6 | 6 |
7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "extensions/browser/extension_function.h" | 9 #include "extensions/browser/extension_function.h" |
10 #include "extensions/common/error_utils.h" | 10 #include "extensions/common/error_utils.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 FunctionHeuristicsMap& functions = function_heuristics_[extension_id]; | 50 FunctionHeuristicsMap& functions = function_heuristics_[extension_id]; |
51 | 51 |
52 // Lookup heuristics for function, create if necessary. | 52 // Lookup heuristics for function, create if necessary. |
53 QuotaLimitHeuristics& heuristics = functions[function->name()]; | 53 QuotaLimitHeuristics& heuristics = functions[function->name()]; |
54 if (heuristics.empty()) | 54 if (heuristics.empty()) |
55 function->GetQuotaLimitHeuristics(&heuristics); | 55 function->GetQuotaLimitHeuristics(&heuristics); |
56 | 56 |
57 if (heuristics.empty()) | 57 if (heuristics.empty()) |
58 return std::string(); // No heuristic implies no limit. | 58 return std::string(); // No heuristic implies no limit. |
59 | 59 |
60 ViolationErrorMap::iterator violation_error = | |
61 violation_errors_.find(extension_id); | |
62 if (violation_error != violation_errors_.end()) | |
63 return violation_error->second; // Repeat offender. | |
64 | |
65 QuotaLimitHeuristic* failed_heuristic = NULL; | 60 QuotaLimitHeuristic* failed_heuristic = NULL; |
66 for (QuotaLimitHeuristics::iterator heuristic = heuristics.begin(); | 61 for (QuotaLimitHeuristics::iterator heuristic = heuristics.begin(); |
67 heuristic != heuristics.end(); | 62 heuristic != heuristics.end(); |
68 ++heuristic) { | 63 ++heuristic) { |
69 // Apply heuristic to each item (bucket). | 64 // Apply heuristic to each item (bucket). |
70 if (!(*heuristic)->ApplyToArgs(args, event_time)) { | 65 if (!(*heuristic)->ApplyToArgs(args, event_time)) { |
71 failed_heuristic = *heuristic; | 66 failed_heuristic = *heuristic; |
72 break; | 67 break; |
73 } | 68 } |
74 } | 69 } |
75 | 70 |
76 if (!failed_heuristic) | 71 if (!failed_heuristic) |
77 return std::string(); | 72 return std::string(); |
78 | 73 |
79 std::string error = failed_heuristic->GetError(); | 74 std::string error = failed_heuristic->GetError(); |
80 DCHECK_GT(error.length(), 0u); | 75 DCHECK_GT(error.length(), 0u); |
81 | |
82 PurgeFunctionHeuristicsMap(&functions); | |
83 function_heuristics_.erase(extension_id); | |
84 violation_errors_[extension_id] = error; | |
85 return error; | 76 return error; |
86 } | 77 } |
87 | 78 |
88 void QuotaService::PurgeFunctionHeuristicsMap(FunctionHeuristicsMap* map) { | 79 void QuotaService::PurgeFunctionHeuristicsMap(FunctionHeuristicsMap* map) { |
89 FunctionHeuristicsMap::iterator heuristics = map->begin(); | 80 FunctionHeuristicsMap::iterator heuristics = map->begin(); |
90 while (heuristics != map->end()) { | 81 while (heuristics != map->end()) { |
91 STLDeleteElements(&heuristics->second); | 82 STLDeleteElements(&heuristics->second); |
92 map->erase(heuristics++); | 83 map->erase(heuristics++); |
93 } | 84 } |
94 } | 85 } |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 | 130 |
140 bool QuotaService::TimedLimit::Apply(Bucket* bucket, | 131 bool QuotaService::TimedLimit::Apply(Bucket* bucket, |
141 const base::TimeTicks& event_time) { | 132 const base::TimeTicks& event_time) { |
142 if (event_time > bucket->expiration()) | 133 if (event_time > bucket->expiration()) |
143 bucket->Reset(config(), event_time); | 134 bucket->Reset(config(), event_time); |
144 | 135 |
145 return bucket->DeductToken(); | 136 return bucket->DeductToken(); |
146 } | 137 } |
147 | 138 |
148 } // namespace extensions | 139 } // namespace extensions |
OLD | NEW |