OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "chrome/browser/sessions/tab_loader_delegate.h" | 5 #include "chrome/browser/sessions/tab_loader_delegate.h" |
6 | 6 |
7 #if !defined(OS_CHROMEOS) | 7 #include "net/base/network_change_notifier.h" |
8 | 8 |
9 namespace { | 9 namespace { |
10 | 10 |
11 // The timeout time after which the next tab gets loaded if the previous tab did | 11 // The timeout time after which the next tab gets loaded if the previous tab did |
12 // not finish loading yet. | 12 // not finish loading yet. The used value is half of the median value of all |
13 static const int kInitialDelayTimerMS = 100; | 13 // ChromeOS devices loading the 25 most common web pages. Half is chosen since |
| 14 // the loading time is a mix of server response and data bandwidth. |
| 15 static const int kInitialDelayTimerMS = 1500; |
14 | 16 |
15 class TabLoaderDelegateImpl : public TabLoaderDelegate { | 17 class TabLoaderDelegateImpl |
| 18 : public TabLoaderDelegate, |
| 19 public net::NetworkChangeNotifier::ConnectionTypeObserver { |
16 public: | 20 public: |
17 TabLoaderDelegateImpl() {} | 21 explicit TabLoaderDelegateImpl(TabLoaderCallback* callback); |
18 ~TabLoaderDelegateImpl() override {} | 22 ~TabLoaderDelegateImpl() override; |
19 | 23 |
20 // TabLoaderDelegate: | 24 // TabLoaderDelegate: |
21 base::TimeDelta GetTimeoutBeforeLoadingNextTab() const override { | 25 base::TimeDelta GetTimeoutBeforeLoadingNextTab() const override { |
22 return base::TimeDelta::FromMilliseconds(kInitialDelayTimerMS); | 26 return base::TimeDelta::FromMilliseconds(kInitialDelayTimerMS); |
23 } | 27 } |
24 | 28 |
| 29 // net::NetworkChangeNotifier::ConnectionTypeObserver: |
| 30 void OnConnectionTypeChanged( |
| 31 net::NetworkChangeNotifier::ConnectionType type) override; |
| 32 |
25 private: | 33 private: |
| 34 // The function to call when the connection type changes. |
| 35 TabLoaderCallback* callback_; |
| 36 |
26 DISALLOW_COPY_AND_ASSIGN(TabLoaderDelegateImpl); | 37 DISALLOW_COPY_AND_ASSIGN(TabLoaderDelegateImpl); |
27 }; | 38 }; |
| 39 |
| 40 TabLoaderDelegateImpl::TabLoaderDelegateImpl(TabLoaderCallback* callback) |
| 41 : callback_(callback) { |
| 42 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); |
| 43 if (net::NetworkChangeNotifier::IsOffline()) { |
| 44 // When we are off-line we do not allow loading of tabs, since each of |
| 45 // these tabs would start loading simultaneously when going online. |
| 46 // TODO(skuhne): Once we get a higher level resource control logic which |
| 47 // distributes network access, we can remove this. |
| 48 callback->SetTabLoadingEnabled(false); |
| 49 } |
| 50 } |
| 51 |
| 52 TabLoaderDelegateImpl::~TabLoaderDelegateImpl() { |
| 53 net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this); |
| 54 } |
| 55 |
| 56 void TabLoaderDelegateImpl::OnConnectionTypeChanged( |
| 57 net::NetworkChangeNotifier::ConnectionType type) { |
| 58 callback_->SetTabLoadingEnabled( |
| 59 type != net::NetworkChangeNotifier::CONNECTION_NONE); |
| 60 } |
28 } // namespace | 61 } // namespace |
29 | 62 |
30 // static | 63 // static |
31 scoped_ptr<TabLoaderDelegate> TabLoaderDelegate::Create( | 64 scoped_ptr<TabLoaderDelegate> TabLoaderDelegate::Create( |
32 TabLoaderCallback* callback) { | 65 TabLoaderCallback* callback) { |
33 return scoped_ptr<TabLoaderDelegate>(new TabLoaderDelegateImpl()); | 66 return scoped_ptr<TabLoaderDelegate>( |
| 67 new TabLoaderDelegateImpl(callback)); |
34 } | 68 } |
35 | |
36 #endif // !defined(OS_CHROMEOS) | |
OLD | NEW |