Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * 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 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 32 | 32 |
| 33 #include "platform/exported/WebURLResponsePrivate.h" | 33 #include "platform/exported/WebURLResponsePrivate.h" |
| 34 #include "platform/network/ResourceLoadTiming.h" | 34 #include "platform/network/ResourceLoadTiming.h" |
| 35 #include "platform/network/ResourceResponse.h" | 35 #include "platform/network/ResourceResponse.h" |
| 36 #include "public/platform/WebHTTPHeaderVisitor.h" | 36 #include "public/platform/WebHTTPHeaderVisitor.h" |
| 37 #include "public/platform/WebHTTPLoadInfo.h" | 37 #include "public/platform/WebHTTPLoadInfo.h" |
| 38 #include "public/platform/WebString.h" | 38 #include "public/platform/WebString.h" |
| 39 #include "public/platform/WebURL.h" | 39 #include "public/platform/WebURL.h" |
| 40 #include "public/platform/WebURLLoadTiming.h" | 40 #include "public/platform/WebURLLoadTiming.h" |
| 41 #include "wtf/Allocator.h" | 41 #include "wtf/Allocator.h" |
| 42 #include "wtf/Assertions.h" | |
| 42 #include "wtf/PtrUtil.h" | 43 #include "wtf/PtrUtil.h" |
| 43 #include "wtf/RefPtr.h" | 44 #include "wtf/RefPtr.h" |
| 44 #include <memory> | 45 #include <memory> |
| 45 | 46 |
| 46 namespace blink { | 47 namespace blink { |
| 47 | 48 |
| 48 namespace { | 49 namespace { |
| 49 | 50 |
| 50 class ExtraDataContainer : public ResourceResponse::ExtraData { | 51 class ExtraDataContainer : public ResourceResponse::ExtraData { |
| 51 public: | 52 public: |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 69 // The standard implementation of WebURLResponsePrivate, which maintains | 70 // The standard implementation of WebURLResponsePrivate, which maintains |
| 70 // ownership of a ResourceResponse instance. | 71 // ownership of a ResourceResponse instance. |
| 71 class WebURLResponsePrivateImpl final : public WebURLResponsePrivate { | 72 class WebURLResponsePrivateImpl final : public WebURLResponsePrivate { |
| 72 USING_FAST_MALLOC(WebURLResponsePrivateImpl); | 73 USING_FAST_MALLOC(WebURLResponsePrivateImpl); |
| 73 public: | 74 public: |
| 74 WebURLResponsePrivateImpl() | 75 WebURLResponsePrivateImpl() |
| 75 { | 76 { |
| 76 m_resourceResponse = &m_resourceResponseAllocation; | 77 m_resourceResponse = &m_resourceResponseAllocation; |
| 77 } | 78 } |
| 78 | 79 |
| 79 WebURLResponsePrivateImpl(const WebURLResponsePrivate* p) | 80 WebURLResponsePrivateImpl(const WebURLResponsePrivate& p) |
| 80 : m_resourceResponseAllocation(*p->m_resourceResponse) | 81 : m_resourceResponseAllocation(*p.m_resourceResponse) |
| 81 { | 82 { |
| 82 m_resourceResponse = &m_resourceResponseAllocation; | 83 m_resourceResponse = &m_resourceResponseAllocation; |
| 83 } | 84 } |
| 84 | 85 |
| 85 virtual void dispose() { delete this; } | 86 ~WebURLResponsePrivateImpl() override {} |
| 86 | 87 |
| 87 private: | 88 private: |
| 88 virtual ~WebURLResponsePrivateImpl() { } | |
| 89 | |
| 90 ResourceResponse m_resourceResponseAllocation; | 89 ResourceResponse m_resourceResponseAllocation; |
| 91 }; | 90 }; |
| 92 | 91 |
| 93 void WebURLResponse::initialize() | 92 WebURLResponse::~WebURLResponse() |
| 94 { | 93 { |
| 95 assign(new WebURLResponsePrivateImpl()); | |
| 96 } | 94 } |
| 97 | 95 |
| 98 void WebURLResponse::reset() | 96 WebURLResponse::WebURLResponse() |
| 97 : m_owningPrivate(new WebURLResponsePrivateImpl()) | |
| 98 , m_private(m_owningPrivate.get()) | |
| 99 { | 99 { |
| 100 assign(0); | |
| 101 } | 100 } |
| 102 | 101 |
| 103 void WebURLResponse::assign(const WebURLResponse& r) | 102 WebURLResponse::WebURLResponse(const WebURLResponse& r) |
| 103 : m_owningPrivate(new WebURLResponsePrivateImpl(*r.m_private)) | |
| 104 , m_private(m_owningPrivate.get()) | |
| 104 { | 105 { |
| 106 } | |
| 107 | |
| 108 WebURLResponse::WebURLResponse(const WebURL& url) | |
| 109 : WebURLResponse() | |
| 110 { | |
| 111 setURL(url); | |
| 112 } | |
| 113 | |
| 114 WebURLResponse& WebURLResponse::operator=(const WebURLResponse& r) | |
| 115 { | |
| 116 // Copying subclasses that have different m_private ownership semantics | |
| 117 // via this operator is just not supported. | |
| 118 DCHECK(m_owningPrivate); | |
| 119 DCHECK(m_private->m_resourceResponse); | |
| 105 if (&r != this) | 120 if (&r != this) |
| 106 assign(r.m_private ? new WebURLResponsePrivateImpl(r.m_private) : 0); | 121 *m_private->m_resourceResponse = *r.m_private->m_resourceResponse; |
| 122 return *this; | |
| 107 } | 123 } |
| 108 | 124 |
| 109 bool WebURLResponse::isNull() const | 125 bool WebURLResponse::isNull() const |
| 110 { | 126 { |
| 111 return !m_private || m_private->m_resourceResponse->isNull(); | 127 return !m_private->m_resourceResponse || m_private->m_resourceResponse->isNu ll(); |
|
dcheng
2016/07/07 05:02:50
It looks like this can only happen when using the
kinuko
2016/07/07 09:23:04
Looks like the change works, and I like simplifyin
| |
| 112 } | 128 } |
| 113 | 129 |
| 114 WebURL WebURLResponse::url() const | 130 WebURL WebURLResponse::url() const |
| 115 { | 131 { |
| 116 return m_private->m_resourceResponse->url(); | 132 return m_private->m_resourceResponse->url(); |
| 117 } | 133 } |
| 118 | 134 |
| 119 void WebURLResponse::setURL(const WebURL& url) | 135 void WebURLResponse::setURL(const WebURL& url) |
| 120 { | 136 { |
| 121 m_private->m_resourceResponse->setURL(url); | 137 m_private->m_resourceResponse->setURL(url); |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 335 webSecurityDetails.mac, | 351 webSecurityDetails.mac, |
| 336 webSecurityDetails.certId, | 352 webSecurityDetails.certId, |
| 337 webSecurityDetails.numUnknownScts, | 353 webSecurityDetails.numUnknownScts, |
| 338 webSecurityDetails.numInvalidScts, | 354 webSecurityDetails.numInvalidScts, |
| 339 webSecurityDetails.numValidScts, | 355 webSecurityDetails.numValidScts, |
| 340 sctList); | 356 sctList); |
| 341 } | 357 } |
| 342 | 358 |
| 343 ResourceResponse& WebURLResponse::toMutableResourceResponse() | 359 ResourceResponse& WebURLResponse::toMutableResourceResponse() |
| 344 { | 360 { |
| 345 ASSERT(m_private); | 361 DCHECK(m_private->m_resourceResponse); |
| 346 ASSERT(m_private->m_resourceResponse); | |
| 347 | |
| 348 return *m_private->m_resourceResponse; | 362 return *m_private->m_resourceResponse; |
| 349 } | 363 } |
| 350 | 364 |
| 351 const ResourceResponse& WebURLResponse::toResourceResponse() const | 365 const ResourceResponse& WebURLResponse::toResourceResponse() const |
| 352 { | 366 { |
| 353 ASSERT(m_private); | 367 DCHECK(m_private->m_resourceResponse); |
| 354 ASSERT(m_private->m_resourceResponse); | |
| 355 | |
| 356 return *m_private->m_resourceResponse; | 368 return *m_private->m_resourceResponse; |
| 357 } | 369 } |
| 358 | 370 |
| 359 bool WebURLResponse::wasCached() const | 371 bool WebURLResponse::wasCached() const |
| 360 { | 372 { |
| 361 return m_private->m_resourceResponse->wasCached(); | 373 return m_private->m_resourceResponse->wasCached(); |
| 362 } | 374 } |
| 363 | 375 |
| 364 void WebURLResponse::setWasCached(bool value) | 376 void WebURLResponse::setWasCached(bool value) |
| 365 { | 377 { |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 504 if (!data) | 516 if (!data) |
| 505 return 0; | 517 return 0; |
| 506 return static_cast<ExtraDataContainer*>(data.get())->getExtraData(); | 518 return static_cast<ExtraDataContainer*>(data.get())->getExtraData(); |
| 507 } | 519 } |
| 508 | 520 |
| 509 void WebURLResponse::setExtraData(WebURLResponse::ExtraData* extraData) | 521 void WebURLResponse::setExtraData(WebURLResponse::ExtraData* extraData) |
| 510 { | 522 { |
| 511 m_private->m_resourceResponse->setExtraData(ExtraDataContainer::create(extra Data)); | 523 m_private->m_resourceResponse->setExtraData(ExtraDataContainer::create(extra Data)); |
| 512 } | 524 } |
| 513 | 525 |
| 514 void WebURLResponse::assign(WebURLResponsePrivate* p) | 526 WebURLResponse::WebURLResponse(WebURLResponsePrivate* p) |
| 527 : m_private(p) | |
| 515 { | 528 { |
| 516 // Subclasses may call this directly so a self-assignment check is needed | 529 DCHECK(p); |
| 517 // here as well as in the public assign method. | |
| 518 if (m_private == p) | |
| 519 return; | |
| 520 if (m_private) | |
| 521 m_private->dispose(); | |
| 522 m_private = p; | |
| 523 } | 530 } |
| 524 | 531 |
| 525 } // namespace blink | 532 } // namespace blink |
| OLD | NEW |