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

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

Issue 11270027: Add a ResourceScheduler to ResourceDispatcherHost. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use ResourceThrottle Created 8 years 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/loader/resource_scheduler.h
diff --git a/content/browser/loader/resource_scheduler.h b/content/browser/loader/resource_scheduler.h
new file mode 100644
index 0000000000000000000000000000000000000000..3af4da514556bb11bb6a0d4c458794663792c195
--- /dev/null
+++ b/content/browser/loader/resource_scheduler.h
@@ -0,0 +1,103 @@
+// 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_LOADER_RESOURCE_SCHEDULER_H_
+#define CONTENT_BROWSER_LOADER_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 net {
+class URLRequest;
+}
+
+namespace content {
+class ResourceThrottle;
+
+// 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.
+class CONTENT_EXPORT ResourceScheduler {
+ public:
+ typedef int64 ClientId;
+
+ ResourceScheduler();
+ ~ResourceScheduler();
+
+ // Called when the ResourceDispatcherHost is ready to load a resource.
+ // Caller should delete the returned Throttle when the load completes or is
+ // canceled.
+ scoped_ptr<ResourceThrottle> ScheduleRequest(
+ int child_id, int route_id, const net::URLRequest& url_request);
+
+ // 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 the first time a client paints.
+ void OnFirstPaint(int child_id, int route_id);
+
+ // Called when a client is destroyed.
+ void OnDestroy(int child_id, int route_id);
+
+ private:
+ class ScheduledResourceThrottle;
+ friend class ScheduledResourceThrottle;
+ struct Client;
+
+ typedef std::vector<ScheduledResourceThrottle*> RequestQueue;
+ typedef std::set<ScheduledResourceThrottle*> RequestSet;
+ typedef std::map<ClientId, Client*> ClientMap;
+
+ struct Client {
+ Client();
+ ~Client();
+
+ bool has_painted;
+ bool has_closed;
+ RequestQueue pending_requests;
+ RequestSet in_flight_requests;
+ };
+
+ // Called when a ScheduledResourceThrottle is destroyed.
+ void RemoveRequest(ScheduledResourceThrottle* request);
+
+ // Unthrottles the |request| and adds it to |client|.
+ void StartRequest(ScheduledResourceThrottle* request, Client* client);
+
+ // Calls StartRequest on all pending requests for |client|.
+ void LoadPendingRequests(Client* client);
+
+ ClientMap client_map_;
+ RequestSet unowned_requests_;
+};
+
+} // namespace content
+
+#endif // CONTENT_BROWSER_LOADER_RESOURCE_SCHEDULER_H_

Powered by Google App Engine
This is Rietveld 408576698