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/extensions_quota_service.h" | 5 #include "chrome/browser/extensions/extensions_quota_service.h" |
6 | 6 |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "chrome/browser/extensions/extension_function.h" | 9 #include "chrome/browser/extensions/extension_function.h" |
10 #include "extensions/common/error_utils.h" | 10 #include "extensions/common/error_utils.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 } | 35 } |
36 | 36 |
37 std::string ExtensionsQuotaService::Assess( | 37 std::string ExtensionsQuotaService::Assess( |
38 const std::string& extension_id, | 38 const std::string& extension_id, |
39 ExtensionFunction* function, | 39 ExtensionFunction* function, |
40 const ListValue* args, | 40 const ListValue* args, |
41 const base::TimeTicks& event_time) { | 41 const base::TimeTicks& event_time) { |
42 DCHECK(CalledOnValidThread()); | 42 DCHECK(CalledOnValidThread()); |
43 | 43 |
44 if (function->ShouldSkipQuotaLimiting()) | 44 if (function->ShouldSkipQuotaLimiting()) |
45 return ""; | 45 return std::string(); |
46 | 46 |
47 // Lookup function list for extension. | 47 // Lookup function list for extension. |
48 FunctionHeuristicsMap& functions = function_heuristics_[extension_id]; | 48 FunctionHeuristicsMap& functions = function_heuristics_[extension_id]; |
49 | 49 |
50 // Lookup heuristics for function, create if necessary. | 50 // Lookup heuristics for function, create if necessary. |
51 QuotaLimitHeuristics& heuristics = functions[function->name()]; | 51 QuotaLimitHeuristics& heuristics = functions[function->name()]; |
52 if (heuristics.empty()) | 52 if (heuristics.empty()) |
53 function->GetQuotaLimitHeuristics(&heuristics); | 53 function->GetQuotaLimitHeuristics(&heuristics); |
54 | 54 |
55 if (heuristics.empty()) | 55 if (heuristics.empty()) |
56 return ""; // No heuristic implies no limit. | 56 return std::string(); // No heuristic implies no limit. |
57 | 57 |
58 ViolationErrorMap::iterator violation_error = | 58 ViolationErrorMap::iterator violation_error = |
59 violation_errors_.find(extension_id); | 59 violation_errors_.find(extension_id); |
60 if (violation_error != violation_errors_.end()) | 60 if (violation_error != violation_errors_.end()) |
61 return violation_error->second; // Repeat offender. | 61 return violation_error->second; // Repeat offender. |
62 | 62 |
63 QuotaLimitHeuristic* failed_heuristic = NULL; | 63 QuotaLimitHeuristic* failed_heuristic = NULL; |
64 for (QuotaLimitHeuristics::iterator heuristic = heuristics.begin(); | 64 for (QuotaLimitHeuristics::iterator heuristic = heuristics.begin(); |
65 heuristic != heuristics.end(); ++heuristic) { | 65 heuristic != heuristics.end(); ++heuristic) { |
66 // Apply heuristic to each item (bucket). | 66 // Apply heuristic to each item (bucket). |
67 if (!(*heuristic)->ApplyToArgs(args, event_time)) { | 67 if (!(*heuristic)->ApplyToArgs(args, event_time)) { |
68 failed_heuristic = *heuristic; | 68 failed_heuristic = *heuristic; |
69 break; | 69 break; |
70 } | 70 } |
71 } | 71 } |
72 | 72 |
73 if (!failed_heuristic) | 73 if (!failed_heuristic) |
74 return ""; | 74 return std::string(); |
75 | 75 |
76 std::string error = failed_heuristic->GetError(); | 76 std::string error = failed_heuristic->GetError(); |
77 DCHECK_GT(error.length(), 0u); | 77 DCHECK_GT(error.length(), 0u); |
78 | 78 |
79 PurgeFunctionHeuristicsMap(&functions); | 79 PurgeFunctionHeuristicsMap(&functions); |
80 function_heuristics_.erase(extension_id); | 80 function_heuristics_.erase(extension_id); |
81 violation_errors_[extension_id] = error; | 81 violation_errors_[extension_id] = error; |
82 return error; | 82 return error; |
83 } | 83 } |
84 | 84 |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 return false; | 182 return false; |
183 } | 183 } |
184 } | 184 } |
185 | 185 |
186 // We can go negative since we check has_tokens when we get to *next* bucket, | 186 // We can go negative since we check has_tokens when we get to *next* bucket, |
187 // and for the small interval all that matters is whether we used up all the | 187 // and for the small interval all that matters is whether we used up all the |
188 // tokens (which is true if num_tokens_ <= 0). | 188 // tokens (which is true if num_tokens_ <= 0). |
189 bucket->DeductToken(); | 189 bucket->DeductToken(); |
190 return true; | 190 return true; |
191 } | 191 } |
OLD | NEW |