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

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

Issue 465363003: ResourceScheduler get visual signal from RenderViewHostImpl (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add VisualObserver Created 6 years, 4 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 | Annotate | Revision Log
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 #ifndef CONTENT_BROWSER_LOADER_RESOURCE_SCHEDULER_H_ 5 #ifndef CONTENT_BROWSER_LOADER_RESOURCE_SCHEDULER_H_
6 #define CONTENT_BROWSER_LOADER_RESOURCE_SCHEDULER_H_ 6 #define CONTENT_BROWSER_LOADER_RESOURCE_SCHEDULER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/threading/non_thread_safe.h" 14 #include "base/threading/non_thread_safe.h"
15 #include "base/timer/timer.h" 15 #include "base/timer/timer.h"
16 #include "content/browser/web_contents/web_contents_impl.h"
16 #include "content/common/content_export.h" 17 #include "content/common/content_export.h"
17 #include "net/base/priority_queue.h" 18 #include "net/base/priority_queue.h"
18 #include "net/base/request_priority.h" 19 #include "net/base/request_priority.h"
19 20
20 namespace net { 21 namespace net {
21 class HostPortPair; 22 class HostPortPair;
22 class URLRequest; 23 class URLRequest;
23 } 24 }
24 25
25 namespace content { 26 namespace content {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 // Note that clients which would be COALESCED are UNTHROTTLED until 75 // Note that clients which would be COALESCED are UNTHROTTLED until
75 // coalescing is turned on. 76 // coalescing is turned on.
76 UNTHROTTLED, 77 UNTHROTTLED,
77 // Observable (active) loading client. 78 // Observable (active) loading client.
78 ACTIVE_AND_LOADING, 79 ACTIVE_AND_LOADING,
79 }; 80 };
80 81
81 ResourceScheduler(); 82 ResourceScheduler();
82 ~ResourceScheduler(); 83 ~ResourceScheduler();
83 84
85 // VisualObserver observes WebContents and lives on the UI thread. It notifies
86 // the client about the visibility change. Each VisualObserver corresponds to
87 // one and only one Client. The VisualObserver will be deleted when the client
88 // is destructed.
89 class VisualObserver;
90 VisualObserver* CreateVisualObserver(WebContentsImpl* web_content);
91 void DeleteVisualObserver(VisualObserver* observer);
92
84 // Use a mock timer when testing. 93 // Use a mock timer when testing.
85 void set_timer_for_testing(scoped_ptr<base::Timer> timer) { 94 void set_timer_for_testing(scoped_ptr<base::Timer> timer) {
86 coalescing_timer_.reset(timer.release()); 95 coalescing_timer_.reset(timer.release());
87 } 96 }
88 97
89 // TODO(aiolos): Remove when throttling and coalescing have landed 98 // TODO(aiolos): Remove when throttling and coalescing have landed
90 void SetThrottleOptionsForTesting(bool should_throttle, bool should_coalesce); 99 void SetThrottleOptionsForTesting(bool should_throttle, bool should_coalesce);
91 100
92 bool should_coalesce() const { return should_coalesce_; } 101 bool should_coalesce() const { return should_coalesce_; }
93 bool should_throttle() const { return should_throttle_; } 102 bool should_throttle() const { return should_throttle_; }
94 103
95 ClientThrottleState GetClientStateForTesting(int child_id, int route_id); 104 ClientThrottleState GetClientStateForTesting(int child_id, int route_id);
96 105
97 // Requests that this ResourceScheduler schedule, and eventually loads, the 106 // Requests that this ResourceScheduler schedule, and eventually loads, the
98 // specified |url_request|. Caller should delete the returned ResourceThrottle 107 // specified |url_request|. Caller should delete the returned ResourceThrottle
99 // when the load completes or is canceled. 108 // when the load completes or is canceled.
100 scoped_ptr<ResourceThrottle> ScheduleRequest( 109 scoped_ptr<ResourceThrottle> ScheduleRequest(
101 int child_id, int route_id, net::URLRequest* url_request); 110 int child_id, int route_id, net::URLRequest* url_request);
102 111
103 // Signals from the UI thread, posted as tasks on the IO thread: 112 // Signals from the UI thread, posted as tasks on the IO thread:
104 113
105 // Called when a renderer is created. 114 // Called when a renderer is created.
106 void OnClientCreated(int child_id, int route_id); 115 void OnClientCreated(int child_id,
116 int route_id,
117 VisualObserver* visual_observer,
118 bool is_visible);
107 119
108 // Called when a renderer is destroyed. 120 // Called when a renderer is destroyed. It will also delete the corresponding
121 // VisualObserver in turn.
109 void OnClientDeleted(int child_id, int route_id); 122 void OnClientDeleted(int child_id, int route_id);
110 123
111 // Signals from IPC messages directly from the renderers: 124 // Signals from IPC messages directly from the renderers:
112 125
113 // Called when a client navigates to a new main document. 126 // Called when a client navigates to a new main document.
114 void OnNavigate(int child_id, int route_id); 127 void OnNavigate(int child_id, int route_id);
115 128
116 // Called when the client has parsed the <body> element. This is a signal that 129 // Called when the client has parsed the <body> element. This is a signal that
117 // resource loads won't interfere with first paint. 130 // resource loads won't interfere with first paint.
118 void OnWillInsertBody(int child_id, int route_id); 131 void OnWillInsertBody(int child_id, int route_id);
119 132
120 // Signals from the IO thread: 133 // Signals from the IO thread:
121 134
122 // Called when we received a response to a http request that was served 135 // Called when we received a response to a http request that was served
123 // from a proxy using SPDY. 136 // from a proxy using SPDY.
124 void OnReceivedSpdyProxiedHttpResponse(int child_id, int route_id); 137 void OnReceivedSpdyProxiedHttpResponse(int child_id, int route_id);
125 138
126 // Client functions: 139 // Client functions:
127 140
128 // Called to check if all user observable tabs have completed loading. 141 // Called to check if all user observable tabs have completed loading.
129 bool active_clients_loaded() const { return active_clients_loading_ == 0; } 142 bool active_clients_loaded() const { return active_clients_loading_ == 0; }
130 143
131 // Called when a Client starts or stops playing audio. 144 // Called when a Client starts or stops playing audio.
132 void OnAudibilityChanged(int child_id, int route_id, bool is_audible); 145 void OnAudibilityChanged(int child_id, int route_id, bool is_audible);
133 146
134 // Called when a Client is shown or hidden. 147 void OnLoadingStateChanged(int child_id, int route_id, bool is_loaded);
135 void OnVisibilityChanged(int child_id, int route_id, bool is_visible);
136 148
137 void OnLoadingStateChanged(int child_id, int route_id, bool is_loaded); 149 bool IsClientVisibleForTesting(int child_id, int route_id);
138 150
139 private: 151 private:
140 class RequestQueue; 152 class RequestQueue;
141 class ScheduledResourceRequest; 153 class ScheduledResourceRequest;
142 struct RequestPriorityParams; 154 struct RequestPriorityParams;
143 struct ScheduledResourceSorter { 155 struct ScheduledResourceSorter {
144 bool operator()(const ScheduledResourceRequest* a, 156 bool operator()(const ScheduledResourceRequest* a,
145 const ScheduledResourceRequest* b) const; 157 const ScheduledResourceRequest* b) const;
146 }; 158 };
147 class Client; 159 class Client;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 size_t active_clients_loading_; 208 size_t active_clients_loading_;
197 size_t coalesced_clients_; 209 size_t coalesced_clients_;
198 // This is a repeating timer to initiate requests on COALESCED Clients. 210 // This is a repeating timer to initiate requests on COALESCED Clients.
199 scoped_ptr<base::Timer> coalescing_timer_; 211 scoped_ptr<base::Timer> coalescing_timer_;
200 RequestSet unowned_requests_; 212 RequestSet unowned_requests_;
201 }; 213 };
202 214
203 } // namespace content 215 } // namespace content
204 216
205 #endif // CONTENT_BROWSER_LOADER_RESOURCE_SCHEDULER_H_ 217 #endif // CONTENT_BROWSER_LOADER_RESOURCE_SCHEDULER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698