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

Side by Side Diff: content/browser/loader/resource_dispatcher_host_impl.h

Issue 1603503002: Use scoped_ptr for loaders map in ResourceDispatcherHostImpl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months 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 unified diff | Download patch
« no previous file with comments | « no previous file | content/browser/loader/resource_dispatcher_host_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // This is the browser side of the resource dispatcher, it receives requests 5 // This is the browser side of the resource dispatcher, it receives requests
6 // from the child process (i.e. [Renderer, Plugin, Worker]ProcessHost), and 6 // from the child process (i.e. [Renderer, Plugin, Worker]ProcessHost), and
7 // dispatches them to URLRequests. It then forwards the messages from the 7 // dispatches them to URLRequests. It then forwards the messages from the
8 // URLRequests back to the correct process for handling. 8 // URLRequests back to the correct process for handling.
9 // 9 //
10 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc e-loading 10 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc e-loading
11 11
12 #ifndef CONTENT_BROWSER_LOADER_RESOURCE_DISPATCHER_HOST_IMPL_H_ 12 #ifndef CONTENT_BROWSER_LOADER_RESOURCE_DISPATCHER_HOST_IMPL_H_
13 #define CONTENT_BROWSER_LOADER_RESOURCE_DISPATCHER_HOST_IMPL_H_ 13 #define CONTENT_BROWSER_LOADER_RESOURCE_DISPATCHER_HOST_IMPL_H_
14 14
15 #include <stdint.h> 15 #include <stdint.h>
16 16
17 #include <map> 17 #include <map>
18 #include <set> 18 #include <set>
19 #include <string> 19 #include <string>
20 #include <vector> 20 #include <vector>
21 21
22 #include "base/gtest_prod_util.h" 22 #include "base/gtest_prod_util.h"
23 #include "base/macros.h" 23 #include "base/macros.h"
24 #include "base/memory/linked_ptr.h" 24 #include "base/memory/linked_ptr.h"
yhirano 2016/01/19 03:14:32 Can this be removed?
kinuko 2016/01/19 05:18:24 Done.
25 #include "base/memory/scoped_ptr.h" 25 #include "base/memory/scoped_ptr.h"
26 #include "base/observer_list.h" 26 #include "base/observer_list.h"
27 #include "base/time/time.h" 27 #include "base/time/time.h"
28 #include "base/timer/timer.h" 28 #include "base/timer/timer.h"
29 #include "content/browser/download/download_resource_handler.h" 29 #include "content/browser/download/download_resource_handler.h"
30 #include "content/browser/download/save_types.h" 30 #include "content/browser/download/save_types.h"
31 #include "content/browser/loader/global_routing_id.h" 31 #include "content/browser/loader/global_routing_id.h"
32 #include "content/browser/loader/resource_loader.h" 32 #include "content/browser/loader/resource_loader.h"
33 #include "content/browser/loader/resource_loader_delegate.h" 33 #include "content/browser/loader/resource_loader_delegate.h"
34 #include "content/browser/loader/resource_scheduler.h" 34 #include "content/browser/loader/resource_scheduler.h"
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 void OnInit(); 335 void OnInit();
336 336
337 // A shutdown helper that runs on the IO thread. 337 // A shutdown helper that runs on the IO thread.
338 void OnShutdown(); 338 void OnShutdown();
339 339
340 // Helper function for regular and download requests. 340 // Helper function for regular and download requests.
341 void BeginRequestInternal(scoped_ptr<net::URLRequest> request, 341 void BeginRequestInternal(scoped_ptr<net::URLRequest> request,
342 scoped_ptr<ResourceHandler> handler); 342 scoped_ptr<ResourceHandler> handler);
343 343
344 void StartLoading(ResourceRequestInfoImpl* info, 344 void StartLoading(ResourceRequestInfoImpl* info,
345 const linked_ptr<ResourceLoader>& loader); 345 scoped_ptr<ResourceLoader> loader);
346 346
347 // We keep track of how much memory each request needs and how many requests 347 // We keep track of how much memory each request needs and how many requests
348 // are issued by each renderer. These are known as OustandingRequestStats. 348 // are issued by each renderer. These are known as OustandingRequestStats.
349 // Memory limits apply to all requests sent to us by the renderers. There is a 349 // Memory limits apply to all requests sent to us by the renderers. There is a
350 // limit for each renderer. File descriptor limits apply to requests that are 350 // limit for each renderer. File descriptor limits apply to requests that are
351 // receiving their body. These are known as in-flight requests. There is a 351 // receiving their body. These are known as in-flight requests. There is a
352 // global limit that applies for the browser process. Each render is allowed 352 // global limit that applies for the browser process. Each render is allowed
353 // to use up to a fraction of that. 353 // to use up to a fraction of that.
354 354
355 // Returns the OustandingRequestsStats for |info|'s renderer, or an empty 355 // Returns the OustandingRequestsStats for |info|'s renderer, or an empty
(...skipping 26 matching lines...) Expand all
382 // acts like CancelRequestsForProcess when route_id is -1. 382 // acts like CancelRequestsForProcess when route_id is -1.
383 void CancelRequestsForRoute(int child_id, int route_id); 383 void CancelRequestsForRoute(int child_id, int route_id);
384 384
385 // The list of all requests that we have pending. This list is not really 385 // The list of all requests that we have pending. This list is not really
386 // optimized, and assumes that we have relatively few requests pending at once 386 // optimized, and assumes that we have relatively few requests pending at once
387 // since some operations require brute-force searching of the list. 387 // since some operations require brute-force searching of the list.
388 // 388 //
389 // It may be enhanced in the future to provide some kind of prioritization 389 // It may be enhanced in the future to provide some kind of prioritization
390 // mechanism. We should also consider a hashtable or binary tree if it turns 390 // mechanism. We should also consider a hashtable or binary tree if it turns
391 // out we have a lot of things here. 391 // out we have a lot of things here.
392 typedef std::map<GlobalRequestID, linked_ptr<ResourceLoader> > LoaderMap; 392 using LoaderMap = std::map<GlobalRequestID, scoped_ptr<ResourceLoader>>;
393 393
394 // Deletes the pending request identified by the iterator passed in. 394 // Deletes the pending request identified by the iterator passed in.
395 // This function will invalidate the iterator passed in. Callers should 395 // This function will invalidate the iterator passed in. Callers should
396 // not rely on this iterator being valid on return. 396 // not rely on this iterator being valid on return.
397 void RemovePendingLoader(const LoaderMap::iterator& iter); 397 void RemovePendingLoader(const LoaderMap::iterator& iter);
398 398
399 // This function returns true if the LoadInfo of |a| is "more interesting" 399 // This function returns true if the LoadInfo of |a| is "more interesting"
400 // than the LoadInfo of |b|. The load that is currently sending the larger 400 // than the LoadInfo of |b|. The load that is currently sending the larger
401 // request body is considered more interesting. If neither request is 401 // request body is considered more interesting. If neither request is
402 // sending a body (Neither request has a body, or any request that has a body 402 // sending a body (Neither request has a body, or any request that has a body
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 void OnSyncLoad(int request_id, 435 void OnSyncLoad(int request_id,
436 const ResourceHostMsg_Request& request_data, 436 const ResourceHostMsg_Request& request_data,
437 IPC::Message* sync_result); 437 IPC::Message* sync_result);
438 438
439 // Update the ResourceRequestInfo and internal maps when a request is 439 // Update the ResourceRequestInfo and internal maps when a request is
440 // transferred from one process to another. 440 // transferred from one process to another.
441 void UpdateRequestForTransfer(int child_id, 441 void UpdateRequestForTransfer(int child_id,
442 int route_id, 442 int route_id,
443 int request_id, 443 int request_id,
444 const ResourceHostMsg_Request& request_data, 444 const ResourceHostMsg_Request& request_data,
445 const linked_ptr<ResourceLoader>& loader); 445 LoaderMap::iterator iter);
446 446
447 void BeginRequest(int request_id, 447 void BeginRequest(int request_id,
448 const ResourceHostMsg_Request& request_data, 448 const ResourceHostMsg_Request& request_data,
449 IPC::Message* sync_result, // only valid for sync 449 IPC::Message* sync_result, // only valid for sync
450 int route_id); // only valid for async 450 int route_id); // only valid for async
451 451
452 // Creates a ResourceHandler to be used by BeginRequest() for normal resource 452 // Creates a ResourceHandler to be used by BeginRequest() for normal resource
453 // loading. 453 // loading.
454 scoped_ptr<ResourceHandler> CreateResourceHandler( 454 scoped_ptr<ResourceHandler> CreateResourceHandler(
455 net::URLRequest* request, 455 net::URLRequest* request,
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 // start at -2 and go down from there. (We need to start at -2 because -1 is 544 // start at -2 and go down from there. (We need to start at -2 because -1 is
545 // used as a special value all over the resource_dispatcher_host for 545 // used as a special value all over the resource_dispatcher_host for
546 // uninitialized variables.) This way, we no longer have the unlikely (but 546 // uninitialized variables.) This way, we no longer have the unlikely (but
547 // observed in the real world!) event where we have two requests with the same 547 // observed in the real world!) event where we have two requests with the same
548 // request_id_. 548 // request_id_.
549 int request_id_; 549 int request_id_;
550 550
551 // True if the resource dispatcher host has been shut down. 551 // True if the resource dispatcher host has been shut down.
552 bool is_shutdown_; 552 bool is_shutdown_;
553 553
554 typedef std::vector<linked_ptr<ResourceLoader> > BlockedLoadersList; 554 using BlockedLoadersList = std::vector<scoped_ptr<ResourceLoader>>;
555 typedef std::map<GlobalRoutingID, BlockedLoadersList*> BlockedLoadersMap; 555 using BlockedLoadersMap =
556 std::map<GlobalRoutingID, scoped_ptr<BlockedLoadersList>>;
556 BlockedLoadersMap blocked_loaders_map_; 557 BlockedLoadersMap blocked_loaders_map_;
557 558
558 // Maps the child_ids to the approximate number of bytes 559 // Maps the child_ids to the approximate number of bytes
559 // being used to service its resource requests. No entry implies 0 cost. 560 // being used to service its resource requests. No entry implies 0 cost.
560 typedef std::map<int, OustandingRequestsStats> OutstandingRequestsStatsMap; 561 typedef std::map<int, OustandingRequestsStats> OutstandingRequestsStatsMap;
561 OutstandingRequestsStatsMap outstanding_requests_stats_map_; 562 OutstandingRequestsStatsMap outstanding_requests_stats_map_;
562 563
563 // |num_in_flight_requests_| is the total number of requests currently issued 564 // |num_in_flight_requests_| is the total number of requests currently issued
564 // summed across all renderers. 565 // summed across all renderers.
565 int num_in_flight_requests_; 566 int num_in_flight_requests_;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 DelegateMap delegate_map_; 612 DelegateMap delegate_map_;
612 613
613 scoped_ptr<ResourceScheduler> scheduler_; 614 scoped_ptr<ResourceScheduler> scheduler_;
614 615
615 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcherHostImpl); 616 DISALLOW_COPY_AND_ASSIGN(ResourceDispatcherHostImpl);
616 }; 617 };
617 618
618 } // namespace content 619 } // namespace content
619 620
620 #endif // CONTENT_BROWSER_LOADER_RESOURCE_DISPATCHER_HOST_IMPL_H_ 621 #endif // CONTENT_BROWSER_LOADER_RESOURCE_DISPATCHER_HOST_IMPL_H_
OLDNEW
« no previous file with comments | « no previous file | content/browser/loader/resource_dispatcher_host_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698