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

Side by Side Diff: third_party/WebKit/Source/platform/network/ResourceResponse.cpp

Issue 2638623004: Stop using DEFINE_STATIC_LOCAL in ResourceResponse.cpp. (Closed)
Patch Set: use const char[] Created 3 years, 11 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 /* 1 /*
2 * Copyright (C) 2006, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2009 Google Inc. All rights reserved. 3 * Copyright (C) 2009 Google Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 27 matching lines...) Expand all
38 template <typename Interface> 38 template <typename Interface>
39 Vector<Interface> isolatedCopy(const Vector<Interface>& src) { 39 Vector<Interface> isolatedCopy(const Vector<Interface>& src) {
40 Vector<Interface> result; 40 Vector<Interface> result;
41 result.reserveCapacity(src.size()); 41 result.reserveCapacity(src.size());
42 for (const auto& timestamp : src) { 42 for (const auto& timestamp : src) {
43 result.push_back(timestamp.isolatedCopy()); 43 result.push_back(timestamp.isolatedCopy());
44 } 44 }
45 return result; 45 return result;
46 } 46 }
47 47
48 static const char cacheControlHeader[] = "cache-control";
49 static const char pragmaHeader[] = "pragma";
50
48 } // namespace 51 } // namespace
49 52
50 ResourceResponse::SignedCertificateTimestamp::SignedCertificateTimestamp( 53 ResourceResponse::SignedCertificateTimestamp::SignedCertificateTimestamp(
51 const blink::WebURLResponse::SignedCertificateTimestamp& sct) 54 const blink::WebURLResponse::SignedCertificateTimestamp& sct)
52 : m_status(sct.status), 55 : m_status(sct.status),
53 m_origin(sct.origin), 56 m_origin(sct.origin),
54 m_logDescription(sct.logDescription), 57 m_logDescription(sct.logDescription),
55 m_logId(sct.logId), 58 m_logId(sct.logId),
56 m_timestamp(sct.timestamp), 59 m_timestamp(sct.timestamp),
57 m_hashAlgorithm(sct.hashAlgorithm), 60 m_hashAlgorithm(sct.hashAlgorithm),
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 353
351 void ResourceResponse::setHTTPStatusText(const AtomicString& statusText) { 354 void ResourceResponse::setHTTPStatusText(const AtomicString& statusText) {
352 m_httpStatusText = statusText; 355 m_httpStatusText = statusText;
353 } 356 }
354 357
355 const AtomicString& ResourceResponse::httpHeaderField( 358 const AtomicString& ResourceResponse::httpHeaderField(
356 const AtomicString& name) const { 359 const AtomicString& name) const {
357 return m_httpHeaderFields.get(name); 360 return m_httpHeaderFields.get(name);
358 } 361 }
359 362
360 static const AtomicString& cacheControlHeaderString() {
361 DEFINE_STATIC_LOCAL(const AtomicString, cacheControlHeader,
362 ("cache-control"));
363 return cacheControlHeader;
364 }
365
366 static const AtomicString& pragmaHeaderString() {
367 DEFINE_STATIC_LOCAL(const AtomicString, pragmaHeader, ("pragma"));
368 return pragmaHeader;
369 }
370
371 void ResourceResponse::updateHeaderParsedState(const AtomicString& name) { 363 void ResourceResponse::updateHeaderParsedState(const AtomicString& name) {
372 DEFINE_STATIC_LOCAL(const AtomicString, ageHeader, ("age")); 364 static const char ageHeader[] = "age";
373 DEFINE_STATIC_LOCAL(const AtomicString, dateHeader, ("date")); 365 static const char dateHeader[] = "date";
374 DEFINE_STATIC_LOCAL(const AtomicString, expiresHeader, ("expires")); 366 static const char expiresHeader[] = "expires";
375 DEFINE_STATIC_LOCAL(const AtomicString, lastModifiedHeader, 367 static const char lastModifiedHeader[] = "last-modified";
376 ("last-modified"));
377 368
378 if (equalIgnoringCase(name, ageHeader)) 369 if (equalIgnoringCase(name, ageHeader))
379 m_haveParsedAgeHeader = false; 370 m_haveParsedAgeHeader = false;
380 else if (equalIgnoringCase(name, cacheControlHeaderString()) || 371 else if (equalIgnoringCase(name, cacheControlHeader) ||
381 equalIgnoringCase(name, pragmaHeaderString())) 372 equalIgnoringCase(name, pragmaHeader))
382 m_cacheControlHeader = CacheControlHeader(); 373 m_cacheControlHeader = CacheControlHeader();
383 else if (equalIgnoringCase(name, dateHeader)) 374 else if (equalIgnoringCase(name, dateHeader))
384 m_haveParsedDateHeader = false; 375 m_haveParsedDateHeader = false;
385 else if (equalIgnoringCase(name, expiresHeader)) 376 else if (equalIgnoringCase(name, expiresHeader))
386 m_haveParsedExpiresHeader = false; 377 m_haveParsedExpiresHeader = false;
387 else if (equalIgnoringCase(name, lastModifiedHeader)) 378 else if (equalIgnoringCase(name, lastModifiedHeader))
388 m_haveParsedLastModifiedHeader = false; 379 m_haveParsedLastModifiedHeader = false;
389 } 380 }
390 381
391 void ResourceResponse::setSecurityDetails( 382 void ResourceResponse::setSecurityDetails(
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 424
434 void ResourceResponse::clearHTTPHeaderField(const AtomicString& name) { 425 void ResourceResponse::clearHTTPHeaderField(const AtomicString& name) {
435 m_httpHeaderFields.remove(name); 426 m_httpHeaderFields.remove(name);
436 } 427 }
437 428
438 const HTTPHeaderMap& ResourceResponse::httpHeaderFields() const { 429 const HTTPHeaderMap& ResourceResponse::httpHeaderFields() const {
439 return m_httpHeaderFields; 430 return m_httpHeaderFields;
440 } 431 }
441 432
442 bool ResourceResponse::cacheControlContainsNoCache() const { 433 bool ResourceResponse::cacheControlContainsNoCache() const {
443 if (!m_cacheControlHeader.parsed) 434 if (!m_cacheControlHeader.parsed) {
444 m_cacheControlHeader = parseCacheControlDirectives( 435 m_cacheControlHeader =
445 m_httpHeaderFields.get(cacheControlHeaderString()), 436 parseCacheControlDirectives(m_httpHeaderFields.get(cacheControlHeader),
446 m_httpHeaderFields.get(pragmaHeaderString())); 437 m_httpHeaderFields.get(pragmaHeader));
438 }
447 return m_cacheControlHeader.containsNoCache; 439 return m_cacheControlHeader.containsNoCache;
448 } 440 }
449 441
450 bool ResourceResponse::cacheControlContainsNoStore() const { 442 bool ResourceResponse::cacheControlContainsNoStore() const {
451 if (!m_cacheControlHeader.parsed) 443 if (!m_cacheControlHeader.parsed) {
452 m_cacheControlHeader = parseCacheControlDirectives( 444 m_cacheControlHeader =
453 m_httpHeaderFields.get(cacheControlHeaderString()), 445 parseCacheControlDirectives(m_httpHeaderFields.get(cacheControlHeader),
454 m_httpHeaderFields.get(pragmaHeaderString())); 446 m_httpHeaderFields.get(pragmaHeader));
447 }
455 return m_cacheControlHeader.containsNoStore; 448 return m_cacheControlHeader.containsNoStore;
456 } 449 }
457 450
458 bool ResourceResponse::cacheControlContainsMustRevalidate() const { 451 bool ResourceResponse::cacheControlContainsMustRevalidate() const {
459 if (!m_cacheControlHeader.parsed) 452 if (!m_cacheControlHeader.parsed) {
460 m_cacheControlHeader = parseCacheControlDirectives( 453 m_cacheControlHeader =
461 m_httpHeaderFields.get(cacheControlHeaderString()), 454 parseCacheControlDirectives(m_httpHeaderFields.get(cacheControlHeader),
462 m_httpHeaderFields.get(pragmaHeaderString())); 455 m_httpHeaderFields.get(pragmaHeader));
456 }
463 return m_cacheControlHeader.containsMustRevalidate; 457 return m_cacheControlHeader.containsMustRevalidate;
464 } 458 }
465 459
466 bool ResourceResponse::hasCacheValidatorFields() const { 460 bool ResourceResponse::hasCacheValidatorFields() const {
467 DEFINE_STATIC_LOCAL(const AtomicString, lastModifiedHeader, 461 static const char lastModifiedHeader[] = "last-modified";
468 ("last-modified")); 462 static const char eTagHeader[] = "etag";
469 DEFINE_STATIC_LOCAL(const AtomicString, eTagHeader, ("etag"));
470 return !m_httpHeaderFields.get(lastModifiedHeader).isEmpty() || 463 return !m_httpHeaderFields.get(lastModifiedHeader).isEmpty() ||
471 !m_httpHeaderFields.get(eTagHeader).isEmpty(); 464 !m_httpHeaderFields.get(eTagHeader).isEmpty();
472 } 465 }
473 466
474 double ResourceResponse::cacheControlMaxAge() const { 467 double ResourceResponse::cacheControlMaxAge() const {
475 if (!m_cacheControlHeader.parsed) 468 if (!m_cacheControlHeader.parsed) {
476 m_cacheControlHeader = parseCacheControlDirectives( 469 m_cacheControlHeader =
477 m_httpHeaderFields.get(cacheControlHeaderString()), 470 parseCacheControlDirectives(m_httpHeaderFields.get(cacheControlHeader),
478 m_httpHeaderFields.get(pragmaHeaderString())); 471 m_httpHeaderFields.get(pragmaHeader));
472 }
479 return m_cacheControlHeader.maxAge; 473 return m_cacheControlHeader.maxAge;
480 } 474 }
481 475
482 double ResourceResponse::cacheControlStaleWhileRevalidate() const { 476 double ResourceResponse::cacheControlStaleWhileRevalidate() const {
483 if (!m_cacheControlHeader.parsed) 477 if (!m_cacheControlHeader.parsed) {
484 m_cacheControlHeader = parseCacheControlDirectives( 478 m_cacheControlHeader =
485 m_httpHeaderFields.get(cacheControlHeaderString()), 479 parseCacheControlDirectives(m_httpHeaderFields.get(cacheControlHeader),
486 m_httpHeaderFields.get(pragmaHeaderString())); 480 m_httpHeaderFields.get(pragmaHeader));
481 }
487 return m_cacheControlHeader.staleWhileRevalidate; 482 return m_cacheControlHeader.staleWhileRevalidate;
488 } 483 }
489 484
490 static double parseDateValueInHeader(const HTTPHeaderMap& headers, 485 static double parseDateValueInHeader(const HTTPHeaderMap& headers,
491 const AtomicString& headerName) { 486 const AtomicString& headerName) {
492 const AtomicString& headerValue = headers.get(headerName); 487 const AtomicString& headerValue = headers.get(headerName);
493 if (headerValue.isEmpty()) 488 if (headerValue.isEmpty())
494 return std::numeric_limits<double>::quiet_NaN(); 489 return std::numeric_limits<double>::quiet_NaN();
495 // This handles all date formats required by RFC2616: 490 // This handles all date formats required by RFC2616:
496 // Sun, 06 Nov 1994 08:49:37 GMT ; RFC 822, updated by RFC 1123 491 // Sun, 06 Nov 1994 08:49:37 GMT ; RFC 822, updated by RFC 1123
497 // Sunday, 06-Nov-94 08:49:37 GMT ; RFC 850, obsoleted by RFC 1036 492 // Sunday, 06-Nov-94 08:49:37 GMT ; RFC 850, obsoleted by RFC 1036
498 // Sun Nov 6 08:49:37 1994 ; ANSI C's asctime() format 493 // Sun Nov 6 08:49:37 1994 ; ANSI C's asctime() format
499 double dateInMilliseconds = parseDate(headerValue); 494 double dateInMilliseconds = parseDate(headerValue);
500 if (!std::isfinite(dateInMilliseconds)) 495 if (!std::isfinite(dateInMilliseconds))
501 return std::numeric_limits<double>::quiet_NaN(); 496 return std::numeric_limits<double>::quiet_NaN();
502 return dateInMilliseconds / 1000; 497 return dateInMilliseconds / 1000;
503 } 498 }
504 499
505 double ResourceResponse::date() const { 500 double ResourceResponse::date() const {
506 if (!m_haveParsedDateHeader) { 501 if (!m_haveParsedDateHeader) {
507 DEFINE_STATIC_LOCAL(const AtomicString, headerName, ("date")); 502 static const char headerName[] = "date";
508 m_date = parseDateValueInHeader(m_httpHeaderFields, headerName); 503 m_date = parseDateValueInHeader(m_httpHeaderFields, headerName);
509 m_haveParsedDateHeader = true; 504 m_haveParsedDateHeader = true;
510 } 505 }
511 return m_date; 506 return m_date;
512 } 507 }
513 508
514 double ResourceResponse::age() const { 509 double ResourceResponse::age() const {
515 if (!m_haveParsedAgeHeader) { 510 if (!m_haveParsedAgeHeader) {
516 DEFINE_STATIC_LOCAL(const AtomicString, headerName, ("age")); 511 static const char headerName[] = "age";
517 const AtomicString& headerValue = m_httpHeaderFields.get(headerName); 512 const AtomicString& headerValue = m_httpHeaderFields.get(headerName);
518 bool ok; 513 bool ok;
519 m_age = headerValue.toDouble(&ok); 514 m_age = headerValue.toDouble(&ok);
520 if (!ok) 515 if (!ok)
521 m_age = std::numeric_limits<double>::quiet_NaN(); 516 m_age = std::numeric_limits<double>::quiet_NaN();
522 m_haveParsedAgeHeader = true; 517 m_haveParsedAgeHeader = true;
523 } 518 }
524 return m_age; 519 return m_age;
525 } 520 }
526 521
527 double ResourceResponse::expires() const { 522 double ResourceResponse::expires() const {
528 if (!m_haveParsedExpiresHeader) { 523 if (!m_haveParsedExpiresHeader) {
529 DEFINE_STATIC_LOCAL(const AtomicString, headerName, ("expires")); 524 static const char headerName[] = "expires";
530 m_expires = parseDateValueInHeader(m_httpHeaderFields, headerName); 525 m_expires = parseDateValueInHeader(m_httpHeaderFields, headerName);
531 m_haveParsedExpiresHeader = true; 526 m_haveParsedExpiresHeader = true;
532 } 527 }
533 return m_expires; 528 return m_expires;
534 } 529 }
535 530
536 double ResourceResponse::lastModified() const { 531 double ResourceResponse::lastModified() const {
537 if (!m_haveParsedLastModifiedHeader) { 532 if (!m_haveParsedLastModifiedHeader) {
538 DEFINE_STATIC_LOCAL(const AtomicString, headerName, ("last-modified")); 533 static const char headerName[] = "last-modified";
539 m_lastModified = parseDateValueInHeader(m_httpHeaderFields, headerName); 534 m_lastModified = parseDateValueInHeader(m_httpHeaderFields, headerName);
540 m_haveParsedLastModifiedHeader = true; 535 m_haveParsedLastModifiedHeader = true;
541 } 536 }
542 return m_lastModified; 537 return m_lastModified;
543 } 538 }
544 539
545 bool ResourceResponse::isAttachment() const { 540 bool ResourceResponse::isAttachment() const {
546 DEFINE_STATIC_LOCAL(const AtomicString, headerName, ("content-disposition")); 541 static const char headerName[] = "content-disposition";
542 static const char attachmentString[] = "attachment";
547 String value = m_httpHeaderFields.get(headerName); 543 String value = m_httpHeaderFields.get(headerName);
548 size_t loc = value.find(';'); 544 size_t loc = value.find(';');
549 if (loc != kNotFound) 545 if (loc != kNotFound)
550 value = value.left(loc); 546 value = value.left(loc);
551 value = value.stripWhiteSpace(); 547 value = value.stripWhiteSpace();
552 DEFINE_STATIC_LOCAL(const AtomicString, attachmentString, ("attachment"));
553 return equalIgnoringCase(value, attachmentString); 548 return equalIgnoringCase(value, attachmentString);
554 } 549 }
555 550
556 void ResourceResponse::setLastModifiedDate(time_t lastModifiedDate) { 551 void ResourceResponse::setLastModifiedDate(time_t lastModifiedDate) {
557 m_lastModifiedDate = lastModifiedDate; 552 m_lastModifiedDate = lastModifiedDate;
558 } 553 }
559 554
560 time_t ResourceResponse::lastModifiedDate() const { 555 time_t ResourceResponse::lastModifiedDate() const {
561 return m_lastModifiedDate; 556 return m_lastModifiedDate;
562 } 557 }
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
665 if (a.resourceLoadTiming() != b.resourceLoadTiming()) 660 if (a.resourceLoadTiming() != b.resourceLoadTiming())
666 return false; 661 return false;
667 if (a.encodedBodyLength() != b.encodedBodyLength()) 662 if (a.encodedBodyLength() != b.encodedBodyLength())
668 return false; 663 return false;
669 if (a.decodedBodyLength() != b.decodedBodyLength()) 664 if (a.decodedBodyLength() != b.decodedBodyLength())
670 return false; 665 return false;
671 return true; 666 return true;
672 } 667 }
673 668
674 } // namespace blink 669 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698