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

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

Issue 270183002: Move IsStringUTF8/ASCII to base namespace (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more minor nit Created 6 years, 7 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 | Annotate | Revision Log
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 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(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(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(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;
(...skipping 10 matching lines...) Expand all
268 DISALLOW_COPY_AND_ASSIGN(StoreNodeValue); 268 DISALLOW_COPY_AND_ASSIGN(StoreNodeValue);
269 }; 269 };
270 270
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(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)));
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 break; 481 break;
482 } 482 }
483 case jtl_foundation::NAVIGATE_ANY: 483 case jtl_foundation::NAVIGATE_ANY:
484 operators.push_back(new NavigateAnyOperation); 484 operators.push_back(new NavigateAnyOperation);
485 break; 485 break;
486 case jtl_foundation::NAVIGATE_BACK: 486 case jtl_foundation::NAVIGATE_BACK:
487 operators.push_back(new NavigateBackOperation); 487 operators.push_back(new NavigateBackOperation);
488 break; 488 break;
489 case jtl_foundation::STORE_BOOL: { 489 case jtl_foundation::STORE_BOOL: {
490 std::string hashed_name; 490 std::string hashed_name;
491 if (!ReadHash(&hashed_name) || !IsStringUTF8(hashed_name)) 491 if (!ReadHash(&hashed_name) || !base::IsStringUTF8(hashed_name))
492 return false; 492 return false;
493 bool value = false; 493 bool value = false;
494 if (!ReadBool(&value)) 494 if (!ReadBool(&value))
495 return false; 495 return false;
496 operators.push_back(new StoreValue( 496 operators.push_back(new StoreValue(
497 hashed_name, 497 hashed_name,
498 scoped_ptr<base::Value>(new base::FundamentalValue(value)))); 498 scoped_ptr<base::Value>(new base::FundamentalValue(value))));
499 break; 499 break;
500 } 500 }
501 case jtl_foundation::COMPARE_STORED_BOOL: { 501 case jtl_foundation::COMPARE_STORED_BOOL: {
502 std::string hashed_name; 502 std::string hashed_name;
503 if (!ReadHash(&hashed_name) || !IsStringUTF8(hashed_name)) 503 if (!ReadHash(&hashed_name) || !base::IsStringUTF8(hashed_name))
504 return false; 504 return false;
505 bool value = false; 505 bool value = false;
506 if (!ReadBool(&value)) 506 if (!ReadBool(&value))
507 return false; 507 return false;
508 bool default_value = false; 508 bool default_value = false;
509 if (!ReadBool(&default_value)) 509 if (!ReadBool(&default_value))
510 return false; 510 return false;
511 operators.push_back(new CompareStoredValue( 511 operators.push_back(new CompareStoredValue(
512 hashed_name, 512 hashed_name,
513 scoped_ptr<base::Value>(new base::FundamentalValue(value)), 513 scoped_ptr<base::Value>(new base::FundamentalValue(value)),
514 scoped_ptr<base::Value>( 514 scoped_ptr<base::Value>(
515 new base::FundamentalValue(default_value)))); 515 new base::FundamentalValue(default_value))));
516 break; 516 break;
517 } 517 }
518 case jtl_foundation::STORE_HASH: { 518 case jtl_foundation::STORE_HASH: {
519 std::string hashed_name; 519 std::string hashed_name;
520 if (!ReadHash(&hashed_name) || !IsStringUTF8(hashed_name)) 520 if (!ReadHash(&hashed_name) || !base::IsStringUTF8(hashed_name))
521 return false; 521 return false;
522 std::string hashed_value; 522 std::string hashed_value;
523 if (!ReadHash(&hashed_value)) 523 if (!ReadHash(&hashed_value))
524 return false; 524 return false;
525 operators.push_back(new StoreValue( 525 operators.push_back(new StoreValue(
526 hashed_name, 526 hashed_name,
527 scoped_ptr<base::Value>(new base::StringValue(hashed_value)))); 527 scoped_ptr<base::Value>(new base::StringValue(hashed_value))));
528 break; 528 break;
529 } 529 }
530 case jtl_foundation::COMPARE_STORED_HASH: { 530 case jtl_foundation::COMPARE_STORED_HASH: {
531 std::string hashed_name; 531 std::string hashed_name;
532 if (!ReadHash(&hashed_name) || !IsStringUTF8(hashed_name)) 532 if (!ReadHash(&hashed_name) || !base::IsStringUTF8(hashed_name))
533 return false; 533 return false;
534 std::string hashed_value; 534 std::string hashed_value;
535 if (!ReadHash(&hashed_value)) 535 if (!ReadHash(&hashed_value))
536 return false; 536 return false;
537 std::string hashed_default_value; 537 std::string hashed_default_value;
538 if (!ReadHash(&hashed_default_value)) 538 if (!ReadHash(&hashed_default_value))
539 return false; 539 return false;
540 operators.push_back(new CompareStoredValue( 540 operators.push_back(new CompareStoredValue(
541 hashed_name, 541 hashed_name,
542 scoped_ptr<base::Value>(new base::StringValue(hashed_value)), 542 scoped_ptr<base::Value>(new base::StringValue(hashed_value)),
543 scoped_ptr<base::Value>( 543 scoped_ptr<base::Value>(
544 new base::StringValue(hashed_default_value)))); 544 new base::StringValue(hashed_default_value))));
545 break; 545 break;
546 } 546 }
547 case jtl_foundation::STORE_NODE_BOOL: { 547 case jtl_foundation::STORE_NODE_BOOL: {
548 std::string hashed_name; 548 std::string hashed_name;
549 if (!ReadHash(&hashed_name) || !IsStringUTF8(hashed_name)) 549 if (!ReadHash(&hashed_name) || !base::IsStringUTF8(hashed_name))
550 return false; 550 return false;
551 operators.push_back(new StoreNodeValue<true>(hashed_name)); 551 operators.push_back(new StoreNodeValue<true>(hashed_name));
552 break; 552 break;
553 } 553 }
554 case jtl_foundation::STORE_NODE_HASH: { 554 case jtl_foundation::STORE_NODE_HASH: {
555 std::string hashed_name; 555 std::string hashed_name;
556 if (!ReadHash(&hashed_name) || !IsStringUTF8(hashed_name)) 556 if (!ReadHash(&hashed_name) || !base::IsStringUTF8(hashed_name))
557 return false; 557 return false;
558 operators.push_back(new StoreNodeValue<false>(hashed_name)); 558 operators.push_back(new StoreNodeValue<false>(hashed_name));
559 break; 559 break;
560 } 560 }
561 case jtl_foundation::STORE_NODE_REGISTERABLE_DOMAIN_HASH: { 561 case jtl_foundation::STORE_NODE_REGISTERABLE_DOMAIN_HASH: {
562 std::string hashed_name; 562 std::string hashed_name;
563 if (!ReadHash(&hashed_name) || !IsStringUTF8(hashed_name)) 563 if (!ReadHash(&hashed_name) || !base::IsStringUTF8(hashed_name))
564 return false; 564 return false;
565 operators.push_back(new StoreNodeRegisterableDomain(hashed_name)); 565 operators.push_back(new StoreNodeRegisterableDomain(hashed_name));
566 break; 566 break;
567 } 567 }
568 case jtl_foundation::COMPARE_NODE_BOOL: { 568 case jtl_foundation::COMPARE_NODE_BOOL: {
569 bool value = false; 569 bool value = false;
570 if (!ReadBool(&value)) 570 if (!ReadBool(&value))
571 return false; 571 return false;
572 operators.push_back(new CompareNodeBool(value)); 572 operators.push_back(new CompareNodeBool(value));
573 break; 573 break;
574 } 574 }
575 case jtl_foundation::COMPARE_NODE_HASH: { 575 case jtl_foundation::COMPARE_NODE_HASH: {
576 std::string hashed_value; 576 std::string hashed_value;
577 if (!ReadHash(&hashed_value)) 577 if (!ReadHash(&hashed_value))
578 return false; 578 return false;
579 operators.push_back(new CompareNodeHash(hashed_value)); 579 operators.push_back(new CompareNodeHash(hashed_value));
580 break; 580 break;
581 } 581 }
582 case jtl_foundation::COMPARE_NODE_HASH_NOT: { 582 case jtl_foundation::COMPARE_NODE_HASH_NOT: {
583 std::string hashed_value; 583 std::string hashed_value;
584 if (!ReadHash(&hashed_value)) 584 if (!ReadHash(&hashed_value))
585 return false; 585 return false;
586 operators.push_back(new CompareNodeHashNot(hashed_value)); 586 operators.push_back(new CompareNodeHashNot(hashed_value));
587 break; 587 break;
588 } 588 }
589 case jtl_foundation::COMPARE_NODE_TO_STORED_BOOL: { 589 case jtl_foundation::COMPARE_NODE_TO_STORED_BOOL: {
590 std::string hashed_name; 590 std::string hashed_name;
591 if (!ReadHash(&hashed_name) || !IsStringUTF8(hashed_name)) 591 if (!ReadHash(&hashed_name) || !base::IsStringUTF8(hashed_name))
592 return false; 592 return false;
593 operators.push_back(new CompareNodeToStored<true>(hashed_name)); 593 operators.push_back(new CompareNodeToStored<true>(hashed_name));
594 break; 594 break;
595 } 595 }
596 case jtl_foundation::COMPARE_NODE_TO_STORED_HASH: { 596 case jtl_foundation::COMPARE_NODE_TO_STORED_HASH: {
597 std::string hashed_name; 597 std::string hashed_name;
598 if (!ReadHash(&hashed_name) || !IsStringUTF8(hashed_name)) 598 if (!ReadHash(&hashed_name) || !base::IsStringUTF8(hashed_name))
599 return false; 599 return false;
600 operators.push_back(new CompareNodeToStored<false>(hashed_name)); 600 operators.push_back(new CompareNodeToStored<false>(hashed_name));
601 break; 601 break;
602 } 602 }
603 case jtl_foundation::COMPARE_NODE_SUBSTRING: { 603 case jtl_foundation::COMPARE_NODE_SUBSTRING: {
604 std::string hashed_pattern; 604 std::string hashed_pattern;
605 uint32 pattern_length = 0, pattern_sum = 0; 605 uint32 pattern_length = 0, pattern_sum = 0;
606 if (!ReadHash(&hashed_pattern)) 606 if (!ReadHash(&hashed_pattern))
607 return false; 607 return false;
608 if (!ReadUint32(&pattern_length) || pattern_length == 0) 608 if (!ReadUint32(&pattern_length) || pattern_length == 0)
(...skipping 130 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
« no previous file with comments | « chrome/browser/net/firefox_proxy_settings.cc ('k') | chrome/browser/spellchecker/spellcheck_custom_dictionary.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698