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

Side by Side Diff: chrome/browser/profile_resetter/jtl_interpreter.cc

Issue 624173002: replace OVERRIDE and FINAL with override and final in chrome/browser/[j-q]* (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase on master Created 6 years, 2 months 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 "chrome/browser/profile_resetter/jtl_interpreter.h" 5 #include "chrome/browser/profile_resetter/jtl_interpreter.h"
6 6
7 #include <numeric> 7 #include <numeric>
8 8
9 #include "base/memory/scoped_vector.h" 9 #include "base/memory/scoped_vector.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 // Whether a runtime error occurred. 106 // Whether a runtime error occurred.
107 bool error_; 107 bool error_;
108 DISALLOW_COPY_AND_ASSIGN(ExecutionContext); 108 DISALLOW_COPY_AND_ASSIGN(ExecutionContext);
109 }; 109 };
110 110
111 class NavigateOperation : public Operation { 111 class NavigateOperation : public Operation {
112 public: 112 public:
113 explicit NavigateOperation(const std::string& hashed_key) 113 explicit NavigateOperation(const std::string& hashed_key)
114 : hashed_key_(hashed_key) {} 114 : hashed_key_(hashed_key) {}
115 virtual ~NavigateOperation() {} 115 virtual ~NavigateOperation() {}
116 virtual bool Execute(ExecutionContext* context) OVERRIDE { 116 virtual bool Execute(ExecutionContext* context) override {
117 const base::DictionaryValue* dict = NULL; 117 const base::DictionaryValue* dict = NULL;
118 if (!context->current_node()->GetAsDictionary(&dict)) { 118 if (!context->current_node()->GetAsDictionary(&dict)) {
119 // Just ignore this node gracefully as this navigation is a dead end. 119 // Just ignore this node gracefully as this navigation is a dead end.
120 // If this NavigateOperation occurred after a NavigateAny operation, those 120 // If this NavigateOperation occurred after a NavigateAny operation, those
121 // may still be fulfillable, so we allow continuing the execution of the 121 // may still be fulfillable, so we allow continuing the execution of the
122 // sentence on other nodes. 122 // sentence on other nodes.
123 return true; 123 return true;
124 } 124 }
125 for (base::DictionaryValue::Iterator i(*dict); !i.IsAtEnd(); i.Advance()) { 125 for (base::DictionaryValue::Iterator i(*dict); !i.IsAtEnd(); i.Advance()) {
126 if (context->GetHash(i.key()) != hashed_key_) 126 if (context->GetHash(i.key()) != hashed_key_)
127 continue; 127 continue;
128 context->stack()->push_back(&i.value()); 128 context->stack()->push_back(&i.value());
129 bool continue_traversal = context->ContinueExecution(); 129 bool continue_traversal = context->ContinueExecution();
130 context->stack()->pop_back(); 130 context->stack()->pop_back();
131 if (!continue_traversal) 131 if (!continue_traversal)
132 return false; 132 return false;
133 } 133 }
134 return true; 134 return true;
135 } 135 }
136 136
137 private: 137 private:
138 std::string hashed_key_; 138 std::string hashed_key_;
139 DISALLOW_COPY_AND_ASSIGN(NavigateOperation); 139 DISALLOW_COPY_AND_ASSIGN(NavigateOperation);
140 }; 140 };
141 141
142 class NavigateAnyOperation : public Operation { 142 class NavigateAnyOperation : public Operation {
143 public: 143 public:
144 NavigateAnyOperation() {} 144 NavigateAnyOperation() {}
145 virtual ~NavigateAnyOperation() {} 145 virtual ~NavigateAnyOperation() {}
146 virtual bool Execute(ExecutionContext* context) OVERRIDE { 146 virtual bool Execute(ExecutionContext* context) override {
147 const base::DictionaryValue* dict = NULL; 147 const base::DictionaryValue* dict = NULL;
148 const base::ListValue* list = NULL; 148 const base::ListValue* list = NULL;
149 if (context->current_node()->GetAsDictionary(&dict)) { 149 if (context->current_node()->GetAsDictionary(&dict)) {
150 for (base::DictionaryValue::Iterator i(*dict); 150 for (base::DictionaryValue::Iterator i(*dict);
151 !i.IsAtEnd(); i.Advance()) { 151 !i.IsAtEnd(); i.Advance()) {
152 context->stack()->push_back(&i.value()); 152 context->stack()->push_back(&i.value());
153 bool continue_traversal = context->ContinueExecution(); 153 bool continue_traversal = context->ContinueExecution();
154 context->stack()->pop_back(); 154 context->stack()->pop_back();
155 if (!continue_traversal) 155 if (!continue_traversal)
156 return false; 156 return false;
(...skipping 14 matching lines...) Expand all
171 } 171 }
172 172
173 private: 173 private:
174 DISALLOW_COPY_AND_ASSIGN(NavigateAnyOperation); 174 DISALLOW_COPY_AND_ASSIGN(NavigateAnyOperation);
175 }; 175 };
176 176
177 class NavigateBackOperation : public Operation { 177 class NavigateBackOperation : public Operation {
178 public: 178 public:
179 NavigateBackOperation() {} 179 NavigateBackOperation() {}
180 virtual ~NavigateBackOperation() {} 180 virtual ~NavigateBackOperation() {}
181 virtual bool Execute(ExecutionContext* context) OVERRIDE { 181 virtual bool Execute(ExecutionContext* context) override {
182 const base::Value* current_node = context->current_node(); 182 const base::Value* current_node = context->current_node();
183 context->stack()->pop_back(); 183 context->stack()->pop_back();
184 bool continue_traversal = context->ContinueExecution(); 184 bool continue_traversal = context->ContinueExecution();
185 context->stack()->push_back(current_node); 185 context->stack()->push_back(current_node);
186 return continue_traversal; 186 return continue_traversal;
187 } 187 }
188 188
189 private: 189 private:
190 DISALLOW_COPY_AND_ASSIGN(NavigateBackOperation); 190 DISALLOW_COPY_AND_ASSIGN(NavigateBackOperation);
191 }; 191 };
192 192
193 class StoreValue : public Operation { 193 class StoreValue : public Operation {
194 public: 194 public:
195 StoreValue(const std::string& hashed_name, scoped_ptr<base::Value> value) 195 StoreValue(const std::string& hashed_name, scoped_ptr<base::Value> value)
196 : hashed_name_(hashed_name), 196 : hashed_name_(hashed_name),
197 value_(value.Pass()) { 197 value_(value.Pass()) {
198 DCHECK(base::IsStringUTF8(hashed_name)); 198 DCHECK(base::IsStringUTF8(hashed_name));
199 DCHECK(value_); 199 DCHECK(value_);
200 } 200 }
201 virtual ~StoreValue() {} 201 virtual ~StoreValue() {}
202 virtual bool Execute(ExecutionContext* context) OVERRIDE { 202 virtual bool Execute(ExecutionContext* context) override {
203 context->working_memory()->Set(hashed_name_, value_->DeepCopy()); 203 context->working_memory()->Set(hashed_name_, value_->DeepCopy());
204 return context->ContinueExecution(); 204 return context->ContinueExecution();
205 } 205 }
206 206
207 private: 207 private:
208 std::string hashed_name_; 208 std::string hashed_name_;
209 scoped_ptr<base::Value> value_; 209 scoped_ptr<base::Value> value_;
210 DISALLOW_COPY_AND_ASSIGN(StoreValue); 210 DISALLOW_COPY_AND_ASSIGN(StoreValue);
211 }; 211 };
212 212
213 class CompareStoredValue : public Operation { 213 class CompareStoredValue : public Operation {
214 public: 214 public:
215 CompareStoredValue(const std::string& hashed_name, 215 CompareStoredValue(const std::string& hashed_name,
216 scoped_ptr<base::Value> value, 216 scoped_ptr<base::Value> value,
217 scoped_ptr<base::Value> default_value) 217 scoped_ptr<base::Value> default_value)
218 : hashed_name_(hashed_name), 218 : hashed_name_(hashed_name),
219 value_(value.Pass()), 219 value_(value.Pass()),
220 default_value_(default_value.Pass()) { 220 default_value_(default_value.Pass()) {
221 DCHECK(base::IsStringUTF8(hashed_name)); 221 DCHECK(base::IsStringUTF8(hashed_name));
222 DCHECK(value_); 222 DCHECK(value_);
223 DCHECK(default_value_); 223 DCHECK(default_value_);
224 } 224 }
225 virtual ~CompareStoredValue() {} 225 virtual ~CompareStoredValue() {}
226 virtual bool Execute(ExecutionContext* context) OVERRIDE { 226 virtual bool Execute(ExecutionContext* context) override {
227 const base::Value* actual_value = NULL; 227 const base::Value* actual_value = NULL;
228 if (!context->working_memory()->Get(hashed_name_, &actual_value)) 228 if (!context->working_memory()->Get(hashed_name_, &actual_value))
229 actual_value = default_value_.get(); 229 actual_value = default_value_.get();
230 if (!value_->Equals(actual_value)) 230 if (!value_->Equals(actual_value))
231 return true; 231 return true;
232 return context->ContinueExecution(); 232 return context->ContinueExecution();
233 } 233 }
234 234
235 private: 235 private:
236 std::string hashed_name_; 236 std::string hashed_name_;
237 scoped_ptr<base::Value> value_; 237 scoped_ptr<base::Value> value_;
238 scoped_ptr<base::Value> default_value_; 238 scoped_ptr<base::Value> default_value_;
239 DISALLOW_COPY_AND_ASSIGN(CompareStoredValue); 239 DISALLOW_COPY_AND_ASSIGN(CompareStoredValue);
240 }; 240 };
241 241
242 template<bool ExpectedTypeIsBooleanNotHashable> 242 template<bool ExpectedTypeIsBooleanNotHashable>
243 class StoreNodeValue : public Operation { 243 class StoreNodeValue : public Operation {
244 public: 244 public:
245 explicit StoreNodeValue(const std::string& hashed_name) 245 explicit StoreNodeValue(const std::string& hashed_name)
246 : hashed_name_(hashed_name) { 246 : hashed_name_(hashed_name) {
247 DCHECK(base::IsStringUTF8(hashed_name)); 247 DCHECK(base::IsStringUTF8(hashed_name));
248 } 248 }
249 virtual ~StoreNodeValue() {} 249 virtual ~StoreNodeValue() {}
250 virtual bool Execute(ExecutionContext* context) OVERRIDE { 250 virtual bool Execute(ExecutionContext* context) override {
251 scoped_ptr<base::Value> value; 251 scoped_ptr<base::Value> value;
252 if (ExpectedTypeIsBooleanNotHashable) { 252 if (ExpectedTypeIsBooleanNotHashable) {
253 if (!context->current_node()->IsType(base::Value::TYPE_BOOLEAN)) 253 if (!context->current_node()->IsType(base::Value::TYPE_BOOLEAN))
254 return true; 254 return true;
255 value.reset(context->current_node()->DeepCopy()); 255 value.reset(context->current_node()->DeepCopy());
256 } else { 256 } else {
257 std::string hash; 257 std::string hash;
258 if (!context->GetValueHash(*context->current_node(), &hash)) 258 if (!context->GetValueHash(*context->current_node(), &hash))
259 return true; 259 return true;
260 value.reset(new base::StringValue(hash)); 260 value.reset(new base::StringValue(hash));
(...skipping 10 matching lines...) Expand all
271 // Stores the hash of the registerable domain name -- as in, the portion of the 271 // Stores the hash of the registerable domain name -- as in, the portion of the
272 // domain that is registerable, as opposed to controlled by a registrar; without 272 // domain that is registerable, as opposed to controlled by a registrar; without
273 // subdomains -- of the URL represented by the current node into working memory. 273 // subdomains -- of the URL represented by the current node into working memory.
274 class StoreNodeRegisterableDomain : public Operation { 274 class StoreNodeRegisterableDomain : public Operation {
275 public: 275 public:
276 explicit StoreNodeRegisterableDomain(const std::string& hashed_name) 276 explicit StoreNodeRegisterableDomain(const std::string& hashed_name)
277 : hashed_name_(hashed_name) { 277 : hashed_name_(hashed_name) {
278 DCHECK(base::IsStringUTF8(hashed_name)); 278 DCHECK(base::IsStringUTF8(hashed_name));
279 } 279 }
280 virtual ~StoreNodeRegisterableDomain() {} 280 virtual ~StoreNodeRegisterableDomain() {}
281 virtual bool Execute(ExecutionContext* context) OVERRIDE { 281 virtual bool Execute(ExecutionContext* context) override {
282 std::string possibly_invalid_url; 282 std::string possibly_invalid_url;
283 std::string domain; 283 std::string domain;
284 if (!context->current_node()->GetAsString(&possibly_invalid_url) || 284 if (!context->current_node()->GetAsString(&possibly_invalid_url) ||
285 !GetRegisterableDomain(possibly_invalid_url, &domain)) 285 !GetRegisterableDomain(possibly_invalid_url, &domain))
286 return true; 286 return true;
287 context->working_memory()->Set( 287 context->working_memory()->Set(
288 hashed_name_, new base::StringValue(context->GetHash(domain))); 288 hashed_name_, new base::StringValue(context->GetHash(domain)));
289 return context->ContinueExecution(); 289 return context->ContinueExecution();
290 } 290 }
291 291
(...skipping 28 matching lines...) Expand all
320 } 320 }
321 321
322 std::string hashed_name_; 322 std::string hashed_name_;
323 DISALLOW_COPY_AND_ASSIGN(StoreNodeRegisterableDomain); 323 DISALLOW_COPY_AND_ASSIGN(StoreNodeRegisterableDomain);
324 }; 324 };
325 325
326 class CompareNodeBool : public Operation { 326 class CompareNodeBool : public Operation {
327 public: 327 public:
328 explicit CompareNodeBool(bool value) : value_(value) {} 328 explicit CompareNodeBool(bool value) : value_(value) {}
329 virtual ~CompareNodeBool() {} 329 virtual ~CompareNodeBool() {}
330 virtual bool Execute(ExecutionContext* context) OVERRIDE { 330 virtual bool Execute(ExecutionContext* context) override {
331 bool actual_value = false; 331 bool actual_value = false;
332 if (!context->current_node()->GetAsBoolean(&actual_value)) 332 if (!context->current_node()->GetAsBoolean(&actual_value))
333 return true; 333 return true;
334 if (actual_value != value_) 334 if (actual_value != value_)
335 return true; 335 return true;
336 return context->ContinueExecution(); 336 return context->ContinueExecution();
337 } 337 }
338 338
339 private: 339 private:
340 bool value_; 340 bool value_;
341 DISALLOW_COPY_AND_ASSIGN(CompareNodeBool); 341 DISALLOW_COPY_AND_ASSIGN(CompareNodeBool);
342 }; 342 };
343 343
344 class CompareNodeHash : public Operation { 344 class CompareNodeHash : public Operation {
345 public: 345 public:
346 explicit CompareNodeHash(const std::string& hashed_value) 346 explicit CompareNodeHash(const std::string& hashed_value)
347 : hashed_value_(hashed_value) {} 347 : hashed_value_(hashed_value) {}
348 virtual ~CompareNodeHash() {} 348 virtual ~CompareNodeHash() {}
349 virtual bool Execute(ExecutionContext* context) OVERRIDE { 349 virtual bool Execute(ExecutionContext* context) override {
350 std::string actual_hash; 350 std::string actual_hash;
351 if (!context->GetValueHash(*context->current_node(), &actual_hash) || 351 if (!context->GetValueHash(*context->current_node(), &actual_hash) ||
352 actual_hash != hashed_value_) 352 actual_hash != hashed_value_)
353 return true; 353 return true;
354 return context->ContinueExecution(); 354 return context->ContinueExecution();
355 } 355 }
356 356
357 private: 357 private:
358 std::string hashed_value_; 358 std::string hashed_value_;
359 DISALLOW_COPY_AND_ASSIGN(CompareNodeHash); 359 DISALLOW_COPY_AND_ASSIGN(CompareNodeHash);
360 }; 360 };
361 361
362 class CompareNodeHashNot : public Operation { 362 class CompareNodeHashNot : public Operation {
363 public: 363 public:
364 explicit CompareNodeHashNot(const std::string& hashed_value) 364 explicit CompareNodeHashNot(const std::string& hashed_value)
365 : hashed_value_(hashed_value) {} 365 : hashed_value_(hashed_value) {}
366 virtual ~CompareNodeHashNot() {} 366 virtual ~CompareNodeHashNot() {}
367 virtual bool Execute(ExecutionContext* context) OVERRIDE { 367 virtual bool Execute(ExecutionContext* context) override {
368 std::string actual_hash; 368 std::string actual_hash;
369 if (context->GetValueHash(*context->current_node(), &actual_hash) && 369 if (context->GetValueHash(*context->current_node(), &actual_hash) &&
370 actual_hash == hashed_value_) 370 actual_hash == hashed_value_)
371 return true; 371 return true;
372 return context->ContinueExecution(); 372 return context->ContinueExecution();
373 } 373 }
374 374
375 private: 375 private:
376 std::string hashed_value_; 376 std::string hashed_value_;
377 DISALLOW_COPY_AND_ASSIGN(CompareNodeHashNot); 377 DISALLOW_COPY_AND_ASSIGN(CompareNodeHashNot);
378 }; 378 };
379 379
380 template<bool ExpectedTypeIsBooleanNotHashable> 380 template<bool ExpectedTypeIsBooleanNotHashable>
381 class CompareNodeToStored : public Operation { 381 class CompareNodeToStored : public Operation {
382 public: 382 public:
383 explicit CompareNodeToStored(const std::string& hashed_name) 383 explicit CompareNodeToStored(const std::string& hashed_name)
384 : hashed_name_(hashed_name) {} 384 : hashed_name_(hashed_name) {}
385 virtual ~CompareNodeToStored() {} 385 virtual ~CompareNodeToStored() {}
386 virtual bool Execute(ExecutionContext* context) OVERRIDE { 386 virtual bool Execute(ExecutionContext* context) override {
387 const base::Value* stored_value = NULL; 387 const base::Value* stored_value = NULL;
388 if (!context->working_memory()->Get(hashed_name_, &stored_value)) 388 if (!context->working_memory()->Get(hashed_name_, &stored_value))
389 return true; 389 return true;
390 if (ExpectedTypeIsBooleanNotHashable) { 390 if (ExpectedTypeIsBooleanNotHashable) {
391 if (!context->current_node()->IsType(base::Value::TYPE_BOOLEAN) || 391 if (!context->current_node()->IsType(base::Value::TYPE_BOOLEAN) ||
392 !context->current_node()->Equals(stored_value)) 392 !context->current_node()->Equals(stored_value))
393 return true; 393 return true;
394 } else { 394 } else {
395 std::string actual_hash; 395 std::string actual_hash;
396 std::string stored_hash; 396 std::string stored_hash;
(...skipping 14 matching lines...) Expand all
411 public: 411 public:
412 explicit CompareNodeSubstring(const std::string& hashed_pattern, 412 explicit CompareNodeSubstring(const std::string& hashed_pattern,
413 size_t pattern_length, 413 size_t pattern_length,
414 uint32 pattern_sum) 414 uint32 pattern_sum)
415 : hashed_pattern_(hashed_pattern), 415 : hashed_pattern_(hashed_pattern),
416 pattern_length_(pattern_length), 416 pattern_length_(pattern_length),
417 pattern_sum_(pattern_sum) { 417 pattern_sum_(pattern_sum) {
418 DCHECK(pattern_length_); 418 DCHECK(pattern_length_);
419 } 419 }
420 virtual ~CompareNodeSubstring() {} 420 virtual ~CompareNodeSubstring() {}
421 virtual bool Execute(ExecutionContext* context) OVERRIDE { 421 virtual bool Execute(ExecutionContext* context) override {
422 std::string value_as_string; 422 std::string value_as_string;
423 if (!context->current_node()->GetAsString(&value_as_string) || 423 if (!context->current_node()->GetAsString(&value_as_string) ||
424 !pattern_length_ || value_as_string.size() < pattern_length_) 424 !pattern_length_ || value_as_string.size() < pattern_length_)
425 return true; 425 return true;
426 // Go over the string with a sliding window. Meanwhile, maintain the sum in 426 // Go over the string with a sliding window. Meanwhile, maintain the sum in
427 // an incremental fashion, and only calculate the SHA-256 hash when the sum 427 // an incremental fashion, and only calculate the SHA-256 hash when the sum
428 // checks out so as to improve performance. 428 // checks out so as to improve performance.
429 std::string::const_iterator window_begin = value_as_string.begin(); 429 std::string::const_iterator window_begin = value_as_string.begin();
430 std::string::const_iterator window_end = window_begin + pattern_length_ - 1; 430 std::string::const_iterator window_end = window_begin + pattern_length_ - 1;
431 uint32 window_sum = 431 uint32 window_sum =
(...skipping 12 matching lines...) Expand all
444 std::string hashed_pattern_; 444 std::string hashed_pattern_;
445 size_t pattern_length_; 445 size_t pattern_length_;
446 uint32 pattern_sum_; 446 uint32 pattern_sum_;
447 DISALLOW_COPY_AND_ASSIGN(CompareNodeSubstring); 447 DISALLOW_COPY_AND_ASSIGN(CompareNodeSubstring);
448 }; 448 };
449 449
450 class StopExecutingSentenceOperation : public Operation { 450 class StopExecutingSentenceOperation : public Operation {
451 public: 451 public:
452 StopExecutingSentenceOperation() {} 452 StopExecutingSentenceOperation() {}
453 virtual ~StopExecutingSentenceOperation() {} 453 virtual ~StopExecutingSentenceOperation() {}
454 virtual bool Execute(ExecutionContext* context) OVERRIDE { 454 virtual bool Execute(ExecutionContext* context) override {
455 return false; 455 return false;
456 } 456 }
457 457
458 private: 458 private:
459 DISALLOW_COPY_AND_ASSIGN(StopExecutingSentenceOperation); 459 DISALLOW_COPY_AND_ASSIGN(StopExecutingSentenceOperation);
460 }; 460 };
461 461
462 class Parser { 462 class Parser {
463 public: 463 public:
464 explicit Parser(const std::string& program) 464 explicit Parser(const std::string& program)
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 return working_memory_->GetString(hashed_key, output); 739 return working_memory_->GetString(hashed_key, output);
740 } 740 }
741 741
742 int JtlInterpreter::CalculateProgramChecksum() const { 742 int JtlInterpreter::CalculateProgramChecksum() const {
743 uint8 digest[3] = {}; 743 uint8 digest[3] = {};
744 crypto::SHA256HashString(program_, digest, arraysize(digest)); 744 crypto::SHA256HashString(program_, digest, arraysize(digest));
745 return static_cast<uint32>(digest[0]) << 16 | 745 return static_cast<uint32>(digest[0]) << 16 |
746 static_cast<uint32>(digest[1]) << 8 | 746 static_cast<uint32>(digest[1]) << 8 |
747 static_cast<uint32>(digest[2]); 747 static_cast<uint32>(digest[2]);
748 } 748 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698