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

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: Track background requests 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..4d40be52a62f6d47bb840037f5ef708191f1801c
--- /dev/null
+++ b/content/browser/renderer_host/resource_scheduler.h
@@ -0,0 +1,125 @@
+// 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 "base/memory/scoped_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;
+ typedef int64 BackgroundRequestId;
+
+ // 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.
+ scoped_ptr<LoadHandle> ScheduleLoad(int child_id,
+ int route_id,
+ int request_id,
+ const linked_ptr<ResourceLoader>& loader);
willchan no longer on Chromium 2012/12/03 02:30:16 This should take a ResourceLoader* and not increme
James Simonsen 2012/12/05 01:52:45 Done.
+
+ // 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:
+ class BackgroundLoadHandle;
+ class ScheduledLoadHandle;
+ struct Client;
+ struct Request;
+
+ typedef std::vector<Request> RequestQueue;
+ typedef std::set<int> RequestIdSet;
+ typedef std::set<BackgroundRequestId> BackgroundRequestSet;
+ typedef std::map<ClientId, Client*> ClientMap;
+
+ struct Request {
+ int request_id;
+ ResourceLoader* loader;
+ };
+
+ struct Client {
+ Client();
willchan no longer on Chromium 2012/12/03 02:30:16 How about declaring the destructor here and defini
James Simonsen 2012/12/05 01:52:45 Done.
+
+ bool has_painted;
+ bool closed;
+ RequestQueue pending_requests;
+ RequestIdSet in_flight_requests;
+ };
+
+ // Called when a ScheduledLoadHandle is destroyed.
+ void RemoveLoad(ClientId client_id, int request_id);
+
+ // Called when a BackgroundLoadHandle is destroyed.
willchan no longer on Chromium 2012/12/03 02:30:16 I think we should kill off this function. I think
James Simonsen 2012/12/05 01:52:45 Done.
+ void RemoveBackgroundLoad(BackgroundRequestId 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_;
+ BackgroundRequestSet background_requests_;
+};
+
+} // namespace content
+
+#endif // CONTENT_BROWSER_RENDERER_HOST_RESOURCE_SCHEDULER_H_

Powered by Google App Engine
This is Rietveld 408576698