Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/browser/renderer_host/resource_scheduler.h" | |
| 6 | |
| 7 #include "base/stl_util.h" | |
| 8 #include "content/browser/renderer_host/resource_loader.h" | |
| 9 #include "net/base/request_priority.h" | |
| 10 #include "net/url_request/url_request.h" | |
| 11 | |
| 12 namespace content { | |
| 13 | |
| 14 namespace { | |
| 15 | |
| 16 int64 MakeClientId(int child_id, int route_id) { | |
| 17 return static_cast<int64>(child_id) << 32 | route_id; | |
|
willchan no longer on Chromium
2012/10/25 19:44:49
I don't memorize the order of operations between <
James Simonsen
2012/11/17 02:56:15
Done.
| |
| 18 } | |
| 19 | |
| 20 } // unnamed namespace | |
| 21 | |
| 22 ResourceScheduler::ResourceScheduler() { | |
| 23 } | |
| 24 | |
| 25 ResourceScheduler::~ResourceScheduler() { | |
| 26 } | |
| 27 | |
| 28 void ResourceScheduler::ScheduleLoad(int child_id, | |
| 29 int route_id, | |
| 30 int request_id, | |
| 31 ResourceLoader* loader) { | |
| 32 int64 client_id = MakeClientId(child_id, route_id); | |
| 33 if (!ContainsKey(client_map_, client_id)) { | |
|
willchan no longer on Chromium
2012/10/25 19:44:49
I don't understand this. If the client doesn't exi
James Simonsen
2012/11/17 02:56:15
Turns out these were the <a ping> requests. I adde
| |
| 34 loader->StartRequest(); | |
| 35 return; | |
| 36 } | |
| 37 | |
| 38 Client* client = client_map_[client_id]; | |
| 39 Request request = { request_id, loader }; | |
| 40 if (loader->request()->priority() < net::MEDIUM && | |
| 41 !client->in_flight_requests.empty() && !client->has_painted) { | |
| 42 client->pending_requests.push_back(request); | |
| 43 return; | |
| 44 } | |
| 45 | |
| 46 StartRequest(request, client); | |
| 47 } | |
| 48 | |
| 49 void ResourceScheduler::RemoveLoad(int child_id, int route_id, int request_id) { | |
| 50 int64 client_id = MakeClientId(child_id, route_id); | |
| 51 if (!ContainsKey(client_map_, client_id)) { | |
|
willchan no longer on Chromium
2012/10/25 19:44:49
Why would this ever happen? Is this a bug? Should
James Simonsen
2012/11/17 02:56:15
When a tab goes away suddenly the OnDestroy() come
| |
| 52 return; | |
| 53 } | |
| 54 | |
| 55 Client* client = client_map_[client_id]; | |
| 56 RequestIdSet::iterator it = client->in_flight_requests.find(request_id); | |
| 57 if (it == client->in_flight_requests.end()) { | |
| 58 bool removed = false; | |
| 59 RequestQueue::iterator queue_it; | |
| 60 for (queue_it = client->pending_requests.begin(); | |
| 61 queue_it != client->pending_requests.end(); ++queue_it) { | |
| 62 if (queue_it->request_id == request_id) { | |
| 63 client->pending_requests.erase(queue_it); | |
| 64 removed = true; | |
| 65 break; | |
| 66 } | |
| 67 } | |
| 68 DCHECK(removed); | |
| 69 DCHECK(!ContainsKey(client->in_flight_requests, request_id)); | |
| 70 } else { | |
| 71 bool erased = client->in_flight_requests.erase(request_id); | |
| 72 DCHECK(erased); | |
| 73 } | |
| 74 | |
| 75 if (client->in_flight_requests.empty()) { | |
| 76 LoadPendingRequests(client); | |
| 77 } | |
| 78 } | |
| 79 | |
| 80 void ResourceScheduler::OnCreate(int child_id, int route_id) { | |
| 81 int64 client_id = MakeClientId(child_id, route_id); | |
| 82 DCHECK(!ContainsKey(client_map_, client_id)); | |
| 83 client_map_[client_id] = new Client; | |
| 84 } | |
| 85 | |
| 86 void ResourceScheduler::OnNavigate(int child_id, int route_id) { | |
| 87 int64 client_id = MakeClientId(child_id, route_id); | |
| 88 DCHECK(ContainsKey(client_map_, client_id)); | |
| 89 Client* client = client_map_[client_id]; | |
| 90 client->has_painted = false; | |
| 91 } | |
| 92 | |
| 93 void ResourceScheduler::OnPaint(int child_id, int route_id) { | |
| 94 int64 client_id = MakeClientId(child_id, route_id); | |
| 95 DCHECK(ContainsKey(client_map_, client_id)); | |
| 96 Client* client = client_map_[client_id]; | |
| 97 if (!client->has_painted) { | |
| 98 client->has_painted = true; | |
| 99 LoadPendingRequests(client); | |
| 100 } | |
| 101 } | |
| 102 | |
| 103 void ResourceScheduler::OnDestroy(int child_id, int route_id) { | |
| 104 int64 client_id = MakeClientId(child_id, route_id); | |
| 105 bool erased = client_map_.erase(client_id); | |
| 106 DCHECK(erased); | |
| 107 } | |
| 108 | |
| 109 void ResourceScheduler::StartRequest(Request request, Client* client) { | |
| 110 client->in_flight_requests.insert(request.request_id); | |
| 111 request.loader->StartRequest(); | |
| 112 } | |
| 113 | |
| 114 void ResourceScheduler::LoadPendingRequests(Client* client) { | |
| 115 RequestQueue::iterator it; | |
| 116 for (it = client->pending_requests.begin(); | |
| 117 it != client->pending_requests.end(); ++it) { | |
| 118 StartRequest(*it, client); | |
| 119 } | |
| 120 client->pending_requests.clear(); | |
| 121 } | |
| 122 | |
| 123 ResourceScheduler::Client::Client() | |
| 124 : has_painted(false) { | |
| 125 } | |
| 126 | |
| 127 } // namespace content | |
| OLD | NEW |