Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(164)

Side by Side Diff: extensions/browser/quota_service.cc

Issue 704453002: Allow extension function call quota to be un-throttled. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: betterify Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698