Chromium Code Reviews| Index: content/browser/loader/resource_scheduler.cc |
| diff --git a/content/browser/loader/resource_scheduler.cc b/content/browser/loader/resource_scheduler.cc |
| index 85adbdb30e275631b53af88286e75b658e73a16c..7207907fff9cf9bfd7c40eab97a7cbf3aae5eb93 100644 |
| --- a/content/browser/loader/resource_scheduler.cc |
| +++ b/content/browser/loader/resource_scheduler.cc |
| @@ -12,6 +12,7 @@ |
| #include "content/public/browser/resource_controller.h" |
| #include "content/public/browser/resource_request_info.h" |
| #include "content/public/browser/resource_throttle.h" |
| +#include "content/public/browser/web_contents_observer.h" |
| #include "ipc/ipc_message_macros.h" |
| #include "net/base/host_port_pair.h" |
| #include "net/base/load_flags.h" |
| @@ -228,10 +229,15 @@ void ResourceScheduler::RequestQueue::Insert( |
| } |
| // Each client represents a tab. |
| -class ResourceScheduler::Client { |
| +class ResourceScheduler::Client : public content::WebContentsObserver { |
| public: |
| - explicit Client(ResourceScheduler* scheduler) |
| - : is_audible_(false), |
| + explicit Client(ResourceScheduler* scheduler, |
| + int child_id, |
| + int route_id, |
| + WebContents* web_contents) |
| + : child_id_(child_id), |
| + route_id_(route_id), |
| + is_audible_(false), |
| is_visible_(false), |
| is_loaded_(false), |
| is_paused_(false), |
| @@ -240,9 +246,10 @@ class ResourceScheduler::Client { |
| total_delayable_count_(0), |
| throttle_state_(ResourceScheduler::THROTTLED) { |
| scheduler_ = scheduler; |
| + Observe(web_contents); |
|
aiolos (Not reviewing)
2014/08/13 21:40:33
Do you need to set the initial visibility on Clien
Zhen Wang
2014/08/14 22:19:52
I set the visibility here now. Test added.
On 201
|
| } |
| - ~Client() { |
| + virtual ~Client() { |
| // Update to default state and pause to ensure the scheduler has a |
| // correct count of relevant types of clients. |
| is_visible_ = false; |
| @@ -251,6 +258,16 @@ class ResourceScheduler::Client { |
| UpdateThrottleState(); |
| } |
| + // WebContentsObserver implementation. |
| + virtual void WasShown() OVERRIDE { |
| + scheduler_->OnVisibilityChanged(child_id_, route_id_, true); |
|
aiolos (Not reviewing)
2014/08/13 21:40:33
This makes a longer loop than needed to set the in
Zhen Wang
2014/08/14 22:19:52
Done.
|
| + } |
| + |
| + // WebContentsObserver implementation. |
| + virtual void WasHidden() OVERRIDE { |
| + scheduler_->OnVisibilityChanged(child_id_, route_id_, false); |
|
aiolos (Not reviewing)
2014/08/13 21:40:33
Same as above.
Zhen Wang
2014/08/14 22:19:52
Done.
|
| + } |
| + |
| void ScheduleRequest( |
| net::URLRequest* url_request, |
| ScheduledResourceRequest* request) { |
| @@ -288,6 +305,8 @@ class ResourceScheduler::Client { |
| bool is_loaded() const { return is_loaded_; } |
| + bool IsVisible() const { return is_visible_; } |
| + |
| void OnAudibilityChanged(bool is_audible) { |
| if (is_audible == is_audible_) { |
| return; |
| @@ -647,6 +666,8 @@ class ResourceScheduler::Client { |
| } |
| } |
| + const int child_id_; |
| + const int route_id_; |
| bool is_audible_; |
| bool is_visible_; |
| bool is_loaded_; |
| @@ -731,12 +752,14 @@ void ResourceScheduler::RemoveRequest(ScheduledResourceRequest* request) { |
| client->RemoveRequest(request); |
| } |
| -void ResourceScheduler::OnClientCreated(int child_id, int route_id) { |
| +void ResourceScheduler::OnClientCreated(int child_id, |
| + int route_id, |
| + WebContents* web_contents) { |
| DCHECK(CalledOnValidThread()); |
| ClientId client_id = MakeClientId(child_id, route_id); |
| DCHECK(!ContainsKey(client_map_, client_id)); |
| - Client* client = new Client(this); |
| + Client* client = new Client(this, child_id, route_id, web_contents); |
| client_map_[client_id] = client; |
| // TODO(aiolos): set Client visibility/audibility when signals are added |
| @@ -833,6 +856,12 @@ void ResourceScheduler::OnLoadingStateChanged(int child_id, |
| client->OnLoadingStateChanged(is_loaded); |
| } |
| +bool ResourceScheduler::ClientIsVisible(int child_id, int route_id) { |
|
aiolos (Not reviewing)
2014/08/13 21:40:33
nit: IsClientVisible instead.
Zhen Wang
2014/08/14 22:19:52
Done.
|
| + Client* client = GetClient(child_id, route_id); |
| + DCHECK(client); |
| + return client->IsVisible(); |
| +} |
| + |
| ResourceScheduler::Client* ResourceScheduler::GetClient(int child_id, |
| int route_id) { |
| ClientId client_id = MakeClientId(child_id, route_id); |