| Index: content/child/high_priority_resource_filter.cc
|
| diff --git a/content/child/high_priority_resource_filter.cc b/content/child/high_priority_resource_filter.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..7b68c33eed4fc80c646bb2301ce63d424a21de6d
|
| --- /dev/null
|
| +++ b/content/child/high_priority_resource_filter.cc
|
| @@ -0,0 +1,83 @@
|
| +// Copyright 2014 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "content/child/high_priority_resource_filter.h"
|
| +
|
| +#include "base/bind.h"
|
| +#include "base/debug/trace_event.h"
|
| +#include "base/message_loop/high_priority_task_runner.h"
|
| +#include "base/pickle.h"
|
| +#include "base/thread_task_runner_handle.h"
|
| +#include "content/child/resource_dispatcher.h"
|
| +#include "content/common/resource_messages.h"
|
| +
|
| +namespace content {
|
| +
|
| +namespace {
|
| +
|
| +// Runs on the main thread.
|
| +void DispatchMessage(ResourceDispatcher* resource_dispatcher,
|
| + base::TimeTicks io_timestamp,
|
| + const IPC::Message& message) {
|
| + TRACE_EVENT0("loader", "HighPriorityResourceFilter::DispatchMessage");
|
| + resource_dispatcher->set_io_timestamp(io_timestamp);
|
| + resource_dispatcher->OnMessageReceived(message);
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +HighPriorityResourceFilter::HighPriorityResourceFilter(
|
| + ResourceDispatcher* resource_dispatcher,
|
| + scoped_refptr<base::HighPriorityTaskRunner> runner)
|
| + : resource_dispatcher_(resource_dispatcher),
|
| + runner_(runner) {
|
| +}
|
| +
|
| +HighPriorityResourceFilter::~HighPriorityResourceFilter() {
|
| +}
|
| +
|
| +bool HighPriorityResourceFilter::OnMessageReceived(
|
| + const IPC::Message& message) {
|
| + if (IsHighPriorityResourceResonse(message)) {
|
| + runner_->PostTask(
|
| + FROM_HERE,
|
| + base::Bind(&DispatchMessage,
|
| + base::Unretained(resource_dispatcher_),
|
| + base::TimeTicks::Now(),
|
| + message));
|
| + return true;
|
| + }
|
| + return false;
|
| +}
|
| +
|
| +// Runs on the IO thread
|
| +bool HighPriorityResourceFilter::IsHighPriorityResourceResonse(
|
| + const IPC::Message& message) {
|
| + if (ResourceDispatcher::IsResourceDispatcherMessage(message)) {
|
| + int request_id;
|
| + PickleIterator iter(message);
|
| + if (!message.ReadInt(&iter, &request_id))
|
| + return false;
|
| +
|
| + base::AutoLock auto_lock(request_ids_lock_);
|
| + return request_ids_.find(request_id) != request_ids_.end();
|
| + }
|
| + return false;
|
| +}
|
| +
|
| +// Runs on the main thread
|
| +void HighPriorityResourceFilter::AddPendingRequest(
|
| + int request_id, ResourceType::Type resource_type) {
|
| + if (resource_type == ResourceType::FONT_RESOURCE) {
|
| + base::AutoLock auto_lock(request_ids_lock_);
|
| + request_ids_.insert(request_id);
|
| + }
|
| +}
|
| +
|
| +void HighPriorityResourceFilter::RemovePendingRequest(int request_id) {
|
| + base::AutoLock auto_lock(request_ids_lock_);
|
| + request_ids_.erase(request_id);
|
| +}
|
| +
|
| +} // namespace content
|
|
|