diff options
Diffstat (limited to 'chromium/third_party/blink/renderer/platform/loader/fetch/resource_load_scheduler.cc')
-rw-r--r-- | chromium/third_party/blink/renderer/platform/loader/fetch/resource_load_scheduler.cc | 108 |
1 files changed, 58 insertions, 50 deletions
diff --git a/chromium/third_party/blink/renderer/platform/loader/fetch/resource_load_scheduler.cc b/chromium/third_party/blink/renderer/platform/loader/fetch/resource_load_scheduler.cc index a9e198f9d32..b5d3569cfe0 100644 --- a/chromium/third_party/blink/renderer/platform/loader/fetch/resource_load_scheduler.cc +++ b/chromium/third_party/blink/renderer/platform/loader/fetch/resource_load_scheduler.cc @@ -10,7 +10,9 @@ #include "base/strings/string_number_conversions.h" #include "third_party/blink/public/platform/platform.h" #include "third_party/blink/renderer/platform/histogram.h" +#include "third_party/blink/renderer/platform/loader/fetch/console_logger.h" #include "third_party/blink/renderer/platform/loader/fetch/fetch_context.h" +#include "third_party/blink/renderer/platform/loader/fetch/resource_fetcher_properties.h" #include "third_party/blink/renderer/platform/runtime_enabled_features.h" #include "third_party/blink/renderer/platform/scheduler/public/aggregated_metric_reporter.h" #include "third_party/blink/renderer/platform/scheduler/public/frame_status.h" @@ -90,9 +92,8 @@ uint32_t GetFieldTrialUint32Param(const char* trial_name, return param; } -size_t GetOutstandingThrottledLimit(FetchContext* context) { - DCHECK(context); - +size_t GetOutstandingThrottledLimit( + const ResourceFetcherProperties& properties) { if (!RuntimeEnabledFeatures::ResourceLoadSchedulerEnabled()) return ResourceLoadScheduler::kOutstandingUnlimited; @@ -103,7 +104,7 @@ size_t GetOutstandingThrottledLimit(FetchContext* context) { kResourceLoadThrottlingTrial, kOutstandingLimitForBackgroundSubFrameName, kOutstandingLimitForBackgroundSubFrameDefault); - return context->IsMainFrame() ? main_frame_limit : sub_frame_limit; + return properties.IsMainFrame() ? main_frame_limit : sub_frame_limit; } int TakeWholeKilobytes(int64_t& bytes) { @@ -157,16 +158,14 @@ class ResourceLoadScheduler::TrafficMonitor { }; ResourceLoadScheduler::TrafficMonitor::TrafficMonitor(FetchContext* context) - : is_main_frame_(context->IsMainFrame()), + : is_main_frame_(context->GetResourceFetcherProperties().IsMainFrame()), context_(context), traffic_kilobytes_per_frame_status_( "Blink.ResourceLoadScheduler.TrafficBytes.KBPerFrameStatus", &TakeWholeKilobytes), decoded_kilobytes_per_frame_status_( "Blink.ResourceLoadScheduler.DecodedBytes.KBPerFrameStatus", - &TakeWholeKilobytes) { - DCHECK(context_); -} + &TakeWholeKilobytes) {} ResourceLoadScheduler::TrafficMonitor::~TrafficMonitor() { ReportAll(); @@ -221,8 +220,8 @@ void ResourceLoadScheduler::TrafficMonitor::Report( } // Report kilobytes instead of bytes to avoid overflows. - size_t encoded_kilobytes = hints.encoded_data_length() / 1024; - size_t decoded_kilobytes = hints.decoded_body_length() / 1024; + int64_t encoded_kilobytes = hints.encoded_data_length() / 1024; + int64_t decoded_kilobytes = hints.decoded_body_length() / 1024; if (encoded_kilobytes) { traffic_kilobytes_per_frame_status_.RecordTask( @@ -348,9 +347,13 @@ void ResourceLoadScheduler::TrafficMonitor::ReportAll() { constexpr ResourceLoadScheduler::ClientId ResourceLoadScheduler::kInvalidClientId; -ResourceLoadScheduler::ResourceLoadScheduler(FetchContext* context) - : outstanding_limit_for_throttled_frame_scheduler_( - GetOutstandingThrottledLimit(context)), +ResourceLoadScheduler::ResourceLoadScheduler( + ThrottlingPolicy initial_throttling_policy, + FetchContext* context) + : policy_(initial_throttling_policy), + outstanding_limit_for_throttled_frame_scheduler_( + GetOutstandingThrottledLimit( + context->GetResourceFetcherProperties())), context_(context) { traffic_monitor_ = std::make_unique<ResourceLoadScheduler::TrafficMonitor>(context_); @@ -359,7 +362,6 @@ ResourceLoadScheduler::ResourceLoadScheduler(FetchContext* context) if (!scheduler) return; - policy_ = context->InitialLoadThrottlingPolicy(); normal_outstanding_limit_ = GetFieldTrialUint32Param(kRendererSideResourceScheduler, kLimitForRendererSideResourceSchedulerName, @@ -373,13 +375,6 @@ ResourceLoadScheduler::ResourceLoadScheduler(FetchContext* context) FrameScheduler::ObserverType::kLoader, this); } -ResourceLoadScheduler* ResourceLoadScheduler::Create(FetchContext* context) { - return MakeGarbageCollected<ResourceLoadScheduler>( - context - ? context - : &FetchContext::NullInstance(Thread::Current()->GetTaskRunner())); -} - ResourceLoadScheduler::~ResourceLoadScheduler() = default; void ResourceLoadScheduler::Trace(blink::Visitor* visitor) { @@ -428,6 +423,8 @@ void ResourceLoadScheduler::Request(ResourceLoadSchedulerClient* client, DCHECK(ThrottleOption::kStoppable == option || ThrottleOption::kThrottleable == option); + if (pending_requests_[option].empty()) + pending_queue_update_times_[option] = base::TimeTicks::Now(); pending_requests_[option].insert(request_info); pending_request_map_.insert( *id, MakeGarbageCollected<ClientInfo>(client, option, priority, @@ -435,22 +432,7 @@ void ResourceLoadScheduler::Request(ResourceLoadSchedulerClient* client, // Remember the ClientId since MaybeRun() below may destruct the caller // instance and |id| may be inaccessible after the call. - ResourceLoadScheduler::ClientId client_id = *id; MaybeRun(); - - if (!omit_console_log_ && IsThrottledState() && - pending_request_map_.find(client_id) != pending_request_map_.end()) { - // Note that this doesn't show the message when a frame is stopped (vs. - // this DOES when throttled). - context_->AddInfoConsoleMessage( - "Active resource loading counts reached a per-frame limit while the " - "tab was in background. Network requests will be delayed until a " - "previous loading finishes, or the tab is brought to the foreground. " - "See https://www.chromestatus.com/feature/5527160148197376 for more " - "details", - FetchContext::kOtherSource); - omit_console_log_ = true; - } } void ResourceLoadScheduler::SetPriority(ClientId client_id, @@ -544,13 +526,13 @@ void ResourceLoadScheduler::OnNetworkQuiet() { switch (throttling_history_) { case ThrottlingHistory::kInitial: case ThrottlingHistory::kNotThrottled: - if (context_->IsMainFrame()) + if (context_->GetResourceFetcherProperties().IsMainFrame()) main_frame_not_throttled.Count(maximum_running_requests_seen_); else sub_frame_not_throttled.Count(maximum_running_requests_seen_); break; case ThrottlingHistory::kThrottled: - if (context_->IsMainFrame()) + if (context_->GetResourceFetcherProperties().IsMainFrame()) main_frame_throttled.Count(maximum_running_requests_seen_); else sub_frame_throttled.Count(maximum_running_requests_seen_); @@ -597,8 +579,6 @@ void ResourceLoadScheduler::OnLifecycleStateChanged( frame_scheduler_lifecycle_state_ = state; - omit_console_log_ = false; - switch (state) { case scheduler::SchedulingLifecycleState::kHidden: case scheduler::SchedulingLifecycleState::kThrottled: @@ -612,6 +592,7 @@ void ResourceLoadScheduler::OnLifecycleStateChanged( throttling_history_ = ThrottlingHistory::kNotThrottled; else if (throttling_history_ == ThrottlingHistory::kThrottled) throttling_history_ = ThrottlingHistory::kPartiallyThrottled; + ShowConsoleMessageIfNeeded(); break; case scheduler::SchedulingLifecycleState::kStopped: throttling_history_ = ThrottlingHistory::kStopped; @@ -656,14 +637,19 @@ bool ResourceLoadScheduler::GetNextPendingRequest(ClientId* id) { (!has_runnable_throttleable_request || compare(*stoppable_it, *throttleable_it)); - // Remove the iterator from the correct set of pending_requests_. + // Remove the iterator from the correct set of |pending_requests_|, and update + // corresponding |pending_queue_update_times_|. if (use_stoppable) { *id = stoppable_it->client_id; stoppable_queue.erase(stoppable_it); + pending_queue_update_times_[ThrottleOption::kStoppable] = + base::TimeTicks::Now(); return true; } *id = throttleable_it->client_id; throttleable_queue.erase(throttleable_it); + pending_queue_update_times_[ThrottleOption::kThrottleable] = + base::TimeTicks::Now(); return true; } @@ -723,16 +709,38 @@ size_t ResourceLoadScheduler::GetOutstandingLimit() const { return limit; } -bool ResourceLoadScheduler::IsThrottledState() const { - switch (frame_scheduler_lifecycle_state_) { - case scheduler::SchedulingLifecycleState::kHidden: - case scheduler::SchedulingLifecycleState::kThrottled: - return true; - case scheduler::SchedulingLifecycleState::kStopped: - case scheduler::SchedulingLifecycleState::kNotThrottled: - break; +void ResourceLoadScheduler::ShowConsoleMessageIfNeeded() { + if (is_console_info_shown_ || pending_request_map_.IsEmpty()) + return; + + const base::TimeTicks limit = + base::TimeTicks::Now() - base::TimeDelta::FromMinutes(1); + ThrottleOption target_option; + if (pending_queue_update_times_[ThrottleOption::kThrottleable] < limit && + !pending_requests_[ThrottleOption::kThrottleable].empty()) { + target_option = ThrottleOption::kThrottleable; + } else if (pending_queue_update_times_[ThrottleOption::kStoppable] < limit && + !pending_requests_[ThrottleOption::kStoppable].empty()) { + target_option = ThrottleOption::kStoppable; + } else { + // At least, one of the top requests in pending queues was handled in the + // last 1 minutes, or there is no pending requests in the inactive queue. + return; } - return false; + auto client_it = pending_request_map_.find( + pending_requests_[target_option].begin()->client_id); + DCHECK_NE(pending_request_map_.end(), client_it); + ConsoleLogger* logger = client_it->value->client->GetConsoleLogger(); + DCHECK(logger); + + logger->AddInfoMessage( + ConsoleLogger::Source::kOther, + "Some resource load requests were throttled while the tab was in " + "background, and no request was sent from the queue in the last 1 " + "minute. This means previously requested in-flight requests haven't " + "received any response from servers. See" + "https://www.chromestatus.com/feature/5527160148197376 for more details"); + is_console_info_shown_ = true; } } // namespace blink |