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

Unified Diff: content/browser/renderer_host/resource_scheduler.h

Issue 11270027: Add a ResourceScheduler to ResourceDispatcherHost. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Manage ownership with handles Created 8 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/renderer_host/resource_scheduler.h
diff --git a/content/browser/renderer_host/resource_scheduler.h b/content/browser/renderer_host/resource_scheduler.h
new file mode 100644
index 0000000000000000000000000000000000000000..0e9140992bbe3af27ffb64b0efd11f5a9843787a
--- /dev/null
+++ b/content/browser/renderer_host/resource_scheduler.h
@@ -0,0 +1,147 @@
+// Copyright (c) 2012 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.
+
+#ifndef CONTENT_BROWSER_RENDERER_HOST_RESOURCE_SCHEDULER_H_
+#define CONTENT_BROWSER_RENDERER_HOST_RESOURCE_SCHEDULER_H_
+
+#include <map>
+#include <set>
+#include <vector>
+
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "base/memory/linked_ptr.h"
+#include "content/common/content_export.h"
+#include "content/public/browser/global_request_id.h"
+
+namespace content {
+class ResourceLoader;
+
+// There is one ResourceScheduler, which is owned by the ResourceDispatcherHost.
+//
+// These are sources of input to the scheduler:
+// 1. Requests to load, cancel, or finish resources from the
+// ResourceDispatcherHost.
+// 2. Notifications of renderer events from the ResourceSchedulerFilter.
+//
+// The ResourceScheduler tracks many Clients, which should correlate with tabs.
+// A client is uniquely identified by its child_id and route_id.
+//
+// Each Client may have many Requests in flight. Requests are uniquely
+// identified within a Client by their request_ids.
+//
+// The ResourceDispatcherHost should call ScheduleLoad() when it's ready to
+// load a request. The returned LoadHandle should be destroyed when the load
+// finishes or is canceled.
+//
+// The scheduling behavior mimicks WebKit's scheduler, which blocks fetching
+// low priority resources until the first paint has occurred. One exception is
+// if the client is not fetching anything else, low priority fetching begins
+// immediately.
+class CONTENT_EXPORT_PRIVATE ResourceScheduler {
+ public:
+ typedef int64 ClientId;
+
+ // A LoadHandle is returned to the ResourceDispatcherHost. When the host
+ // deletes the handle, it's automatically removed from ResourceScheduler's
+ // state.
+ class LoadHandle {
+ public:
+ virtual ~LoadHandle() {}
+ virtual linked_ptr<ResourceLoader>& loader() = 0;
+ };
+
+ ResourceScheduler();
+ ~ResourceScheduler();
+
+ // Called when the ResourceDispatcherHost is ready to load a resource.
+ // Caller should delete the returned handle when the load completes or is
+ // canceled.
+ LoadHandle* ScheduleLoad(int child_id,
willchan no longer on Chromium 2012/11/21 09:04:30 Perhaps return a scoped_ptr<LoadHandle> to convey
James Simonsen 2012/11/27 02:20:51 Done.
+ int route_id,
+ int request_id,
+ const linked_ptr<ResourceLoader>& loader);
+
+ // These events are triggered by ViewHostMsgs.
+
+ // Called when a new client is created.
+ void OnCreate(int child_id, int route_id);
+
+ // Called when a client navigates to a new main document.
+ void OnNavigate(int child_id, int route_id);
+
+ // Called any time a client paints.
+ void OnPaint(int child_id, int route_id);
+
+ // Called when a client is destroyed.
+ void OnDestroy(int child_id, int route_id);
+
+ private:
+ friend class ScheduledLoadHandle;
+ struct Client;
+ struct Request;
+
+ typedef std::vector<Request> RequestQueue;
+ typedef std::set<int> RequestIdSet;
+ typedef std::map<ClientId, Client*> ClientMap;
+
+ struct Request {
+ int request_id;
+ ResourceLoader* loader;
+ };
+
+ struct Client {
+ Client();
+
+ bool has_painted;
+ bool closed;
+ RequestQueue pending_requests;
+ RequestIdSet in_flight_requests;
+ };
+
+ // A load that must be managed by the ResourceScheduler.
+ class ScheduledLoadHandle : public LoadHandle {
willchan no longer on Chromium 2012/11/21 09:04:30 Move these subclasses to the .cc file to keep the
James Simonsen 2012/11/27 02:20:51 Done.
+ public:
+ ScheduledLoadHandle(ClientId client_id,
+ int request_id,
+ const linked_ptr<ResourceLoader>& loader,
+ ResourceScheduler* scheduler);
+ virtual ~ScheduledLoadHandle();
+
+ virtual linked_ptr<ResourceLoader>& loader() OVERRIDE { return loader_; }
willchan no longer on Chromium 2012/11/21 09:04:30 no returning non-const references. probably best j
James Simonsen 2012/11/27 02:20:51 Done.
+
+ private:
+ ClientId client_id_;
+ int request_id_;
+ linked_ptr<ResourceLoader> loader_;
+ ResourceScheduler* scheduler_;
+ };
+
+ // A load that fires immediately and is ignored by the ResourceScheduler.
willchan no longer on Chromium 2012/11/21 09:04:30 I think this class shouldn't exist and we should j
James Simonsen 2012/11/27 02:20:51 Good point. I prefer to handle the "background" re
+ class UnscheduledLoadHandle : public LoadHandle {
+ public:
+ UnscheduledLoadHandle(const linked_ptr<ResourceLoader>& loader);
+ virtual ~UnscheduledLoadHandle();
+
+ virtual linked_ptr<ResourceLoader>& loader() OVERRIDE { return loader_; }
+
+ private:
+ linked_ptr<ResourceLoader> loader_;
+ };
+
+ // Called when a ScheduledLoadHandle is destroyed.
+ void RemoveLoad(ClientId client_id, int request_id);
+
+ // Kicks off the loader for |request| and adds it to |client|.
+ void StartRequest(Request request, Client* client);
+
+ // Calls StartRequest on all pending requests for |client|.
+ void LoadPendingRequests(Client* client);
+
+ ClientMap client_map_;
+};
+
+} // namespace content
+
+#endif // CONTENT_BROWSER_RENDERER_HOST_RESOURCE_SCHEDULER_H_

Powered by Google App Engine
This is Rietveld 408576698