OLD | NEW |
---|---|
1 /* | 1 /* |
2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de) | 2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de) |
3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org) | 3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org) |
4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org) | 4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org) |
5 Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) | 5 Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) |
6 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All | 6 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All |
7 rights reserved. | 7 rights reserved. |
8 | 8 |
9 This library is free software; you can redistribute it and/or | 9 This library is free software; you can redistribute it and/or |
10 modify it under the terms of the GNU Library General Public | 10 modify it under the terms of the GNU Library General Public |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
262 type_(type), | 262 type_(type), |
263 status_(ResourceStatus::kNotStarted), | 263 status_(ResourceStatus::kNotStarted), |
264 needs_synchronous_cache_hit_(false), | 264 needs_synchronous_cache_hit_(false), |
265 link_preload_(false), | 265 link_preload_(false), |
266 is_revalidating_(false), | 266 is_revalidating_(false), |
267 is_alive_(false), | 267 is_alive_(false), |
268 is_add_remove_client_prohibited_(false), | 268 is_add_remove_client_prohibited_(false), |
269 integrity_disposition_(ResourceIntegrityDisposition::kNotChecked), | 269 integrity_disposition_(ResourceIntegrityDisposition::kNotChecked), |
270 options_(options), | 270 options_(options), |
271 response_timestamp_(CurrentTime()), | 271 response_timestamp_(CurrentTime()), |
272 cancel_timer_(Platform::Current()->MainThread()->GetWebTaskRunner(), | 272 cancel_timer_(IsMainThread() |
273 ? Platform::Current()->MainThread()->GetWebTaskRunner() | |
274 : Platform::Current() | |
275 ->CurrentThread() | |
276 ->Scheduler() | |
277 ->LoadingTaskRunner(), | |
kinuko
2017/05/12 08:41:45
It feels slightly weird why we don't use loading t
horo
2017/05/12 09:06:02
I think so too...
But I don't want to change the e
kinuko
2017/05/13 05:54:55
Yep, ok to leave it as is in this CL.
+yhirano@:
yhirano
2017/05/15 01:43:26
No.
I also think this should be the loading task
| |
273 this, | 278 this, |
274 &Resource::CancelTimerFired), | 279 &Resource::CancelTimerFired), |
275 resource_request_(request) { | 280 resource_request_(request) { |
276 InstanceCounters::IncrementCounter(InstanceCounters::kResourceCounter); | 281 InstanceCounters::IncrementCounter(InstanceCounters::kResourceCounter); |
277 | 282 |
278 // Currently we support the metadata caching only for HTTP family. | 283 // Currently we support the metadata caching only for HTTP family. |
279 if (GetResourceRequest().Url().ProtocolIsInHTTPFamily()) | 284 if (GetResourceRequest().Url().ProtocolIsInHTTPFamily()) |
280 cache_handler_ = CachedMetadataHandlerImpl::Create(this); | 285 cache_handler_ = CachedMetadataHandlerImpl::Create(this); |
281 MemoryCoordinator::Instance().RegisterClient(this); | 286 if (IsMainThread()) |
287 MemoryCoordinator::Instance().RegisterClient(this); | |
282 } | 288 } |
283 | 289 |
284 Resource::~Resource() { | 290 Resource::~Resource() { |
285 InstanceCounters::DecrementCounter(InstanceCounters::kResourceCounter); | 291 InstanceCounters::DecrementCounter(InstanceCounters::kResourceCounter); |
286 } | 292 } |
287 | 293 |
288 DEFINE_TRACE(Resource) { | 294 DEFINE_TRACE(Resource) { |
289 visitor->Trace(loader_); | 295 visitor->Trace(loader_); |
290 visitor->Trace(cache_handler_); | 296 visitor->Trace(cache_handler_); |
291 visitor->Trace(clients_); | 297 visitor->Trace(clients_); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
350 options_.data_buffering_policy = data_buffering_policy; | 356 options_.data_buffering_policy = data_buffering_policy; |
351 ClearData(); | 357 ClearData(); |
352 SetEncodedSize(0); | 358 SetEncodedSize(0); |
353 } | 359 } |
354 | 360 |
355 void Resource::FinishAsError(const ResourceError& error) { | 361 void Resource::FinishAsError(const ResourceError& error) { |
356 DCHECK(!error.IsNull()); | 362 DCHECK(!error.IsNull()); |
357 error_ = error; | 363 error_ = error; |
358 is_revalidating_ = false; | 364 is_revalidating_ = false; |
359 | 365 |
360 if (error_.IsCancellation() || !IsPreloaded()) | 366 if ((error_.IsCancellation() || !IsPreloaded()) && IsMainThread()) |
361 GetMemoryCache()->Remove(this); | 367 GetMemoryCache()->Remove(this); |
362 | 368 |
363 if (!ErrorOccurred()) | 369 if (!ErrorOccurred()) |
364 SetStatus(ResourceStatus::kLoadError); | 370 SetStatus(ResourceStatus::kLoadError); |
365 DCHECK(ErrorOccurred()); | 371 DCHECK(ErrorOccurred()); |
366 ClearData(); | 372 ClearData(); |
367 loader_ = nullptr; | 373 loader_ = nullptr; |
368 CheckNotify(); | 374 CheckNotify(); |
369 } | 375 } |
370 | 376 |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
579 builder.Append(' '); | 585 builder.Append(' '); |
580 builder.Append("loader_"); | 586 builder.Append("loader_"); |
581 } | 587 } |
582 if (preload_count_) { | 588 if (preload_count_) { |
583 if (!builder.IsEmpty()) | 589 if (!builder.IsEmpty()) |
584 builder.Append(' '); | 590 builder.Append(' '); |
585 builder.Append("preload_count_("); | 591 builder.Append("preload_count_("); |
586 builder.AppendNumber(preload_count_); | 592 builder.AppendNumber(preload_count_); |
587 builder.Append(')'); | 593 builder.Append(')'); |
588 } | 594 } |
589 if (GetMemoryCache()->Contains(this)) { | 595 if (IsMainThread() && GetMemoryCache()->Contains(this)) { |
590 if (!builder.IsEmpty()) | 596 if (!builder.IsEmpty()) |
591 builder.Append(' '); | 597 builder.Append(' '); |
592 builder.Append("in_memory_cache"); | 598 builder.Append("in_memory_cache"); |
593 } | 599 } |
594 return builder.ToString(); | 600 return builder.ToString(); |
595 } | 601 } |
596 | 602 |
597 void Resource::DidAddClient(ResourceClient* c) { | 603 void Resource::DidAddClient(ResourceClient* c) { |
598 if (IsLoaded()) { | 604 if (IsLoaded()) { |
599 c->NotifyFinished(this); | 605 c->NotifyFinished(this); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
705 is_alive_ = false; | 711 is_alive_ = false; |
706 AllClientsAndObserversRemoved(); | 712 AllClientsAndObserversRemoved(); |
707 | 713 |
708 // RFC2616 14.9.2: | 714 // RFC2616 14.9.2: |
709 // "no-store: ... MUST make a best-effort attempt to remove the information | 715 // "no-store: ... MUST make a best-effort attempt to remove the information |
710 // from volatile storage as promptly as possible" | 716 // from volatile storage as promptly as possible" |
711 // "... History buffers MAY store such responses as part of their normal | 717 // "... History buffers MAY store such responses as part of their normal |
712 // operation." | 718 // operation." |
713 // We allow non-secure content to be reused in history, but we do not allow | 719 // We allow non-secure content to be reused in history, but we do not allow |
714 // secure content to be reused. | 720 // secure content to be reused. |
715 if (HasCacheControlNoStoreHeader() && Url().ProtocolIs("https")) | 721 if (HasCacheControlNoStoreHeader() && Url().ProtocolIs("https") && |
722 IsMainThread()) | |
716 GetMemoryCache()->Remove(this); | 723 GetMemoryCache()->Remove(this); |
717 } | 724 } |
718 } | 725 } |
719 | 726 |
720 void Resource::AllClientsAndObserversRemoved() { | 727 void Resource::AllClientsAndObserversRemoved() { |
721 if (!loader_) | 728 if (!loader_) |
722 return; | 729 return; |
723 if (!cancel_timer_.IsActive()) | 730 if (!cancel_timer_.IsActive()) |
724 cancel_timer_.StartOneShot(0, BLINK_FROM_HERE); | 731 cancel_timer_.StartOneShot(0, BLINK_FROM_HERE); |
725 } | 732 } |
726 | 733 |
727 void Resource::CancelTimerFired(TimerBase* timer) { | 734 void Resource::CancelTimerFired(TimerBase* timer) { |
728 DCHECK_EQ(timer, &cancel_timer_); | 735 DCHECK_EQ(timer, &cancel_timer_); |
729 if (!HasClientsOrObservers() && loader_) | 736 if (!HasClientsOrObservers() && loader_) |
730 loader_->Cancel(); | 737 loader_->Cancel(); |
731 } | 738 } |
732 | 739 |
733 void Resource::SetDecodedSize(size_t decoded_size) { | 740 void Resource::SetDecodedSize(size_t decoded_size) { |
734 if (decoded_size == decoded_size_) | 741 if (decoded_size == decoded_size_) |
735 return; | 742 return; |
736 size_t old_size = size(); | 743 size_t old_size = size(); |
737 decoded_size_ = decoded_size; | 744 decoded_size_ = decoded_size; |
738 GetMemoryCache()->Update(this, old_size, size()); | 745 if (IsMainThread()) |
746 GetMemoryCache()->Update(this, old_size, size()); | |
739 } | 747 } |
740 | 748 |
741 void Resource::SetEncodedSize(size_t encoded_size) { | 749 void Resource::SetEncodedSize(size_t encoded_size) { |
742 if (encoded_size == encoded_size_ && | 750 if (encoded_size == encoded_size_ && |
743 encoded_size == encoded_size_memory_usage_) | 751 encoded_size == encoded_size_memory_usage_) |
744 return; | 752 return; |
745 size_t old_size = size(); | 753 size_t old_size = size(); |
746 encoded_size_ = encoded_size; | 754 encoded_size_ = encoded_size; |
747 encoded_size_memory_usage_ = encoded_size; | 755 encoded_size_memory_usage_ = encoded_size; |
748 GetMemoryCache()->Update(this, old_size, size()); | 756 if (IsMainThread()) |
757 GetMemoryCache()->Update(this, old_size, size()); | |
749 } | 758 } |
750 | 759 |
751 void Resource::FinishPendingClients() { | 760 void Resource::FinishPendingClients() { |
752 // We're going to notify clients one by one. It is simple if the client does | 761 // We're going to notify clients one by one. It is simple if the client does |
753 // nothing. However there are a couple other things that can happen. | 762 // nothing. However there are a couple other things that can happen. |
754 // | 763 // |
755 // 1. Clients can be added during the loop. Make sure they are not processed. | 764 // 1. Clients can be added during the loop. Make sure they are not processed. |
756 // 2. Clients can be removed during the loop. Make sure they are always | 765 // 2. Clients can be removed during the loop. Make sure they are always |
757 // available to be removed. Also don't call removed clients or add them | 766 // available to be removed. Also don't call removed clients or add them |
758 // back. | 767 // back. |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1070 case Resource::kMedia: | 1079 case Resource::kMedia: |
1071 case Resource::kManifest: | 1080 case Resource::kManifest: |
1072 case Resource::kMock: | 1081 case Resource::kMock: |
1073 return false; | 1082 return false; |
1074 } | 1083 } |
1075 NOTREACHED(); | 1084 NOTREACHED(); |
1076 return false; | 1085 return false; |
1077 } | 1086 } |
1078 | 1087 |
1079 } // namespace blink | 1088 } // namespace blink |
OLD | NEW |