Re-enable child account detection, now behind a flag.
[chromium-blink-merge.git] / chrome / browser / sessions / tab_loader_delegate.cc
blob640495ed68077d5f8379997dd0b7d310c539196f
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
3 // found in the LICENSE file.
5 #include "chrome/browser/sessions/tab_loader_delegate.h"
7 #include "net/base/network_change_notifier.h"
9 namespace {
11 // The timeout time after which the next tab gets loaded if the previous tab did
12 // not finish loading yet. The used value is half of the median value of all
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;
17 class TabLoaderDelegateImpl
18 : public TabLoaderDelegate,
19 public net::NetworkChangeNotifier::ConnectionTypeObserver {
20 public:
21 explicit TabLoaderDelegateImpl(TabLoaderCallback* callback);
22 ~TabLoaderDelegateImpl() override;
24 // TabLoaderDelegate:
25 base::TimeDelta GetTimeoutBeforeLoadingNextTab() const override {
26 return base::TimeDelta::FromMilliseconds(kInitialDelayTimerMS);
29 // net::NetworkChangeNotifier::ConnectionTypeObserver:
30 void OnConnectionTypeChanged(
31 net::NetworkChangeNotifier::ConnectionType type) override;
33 private:
34 // The function to call when the connection type changes.
35 TabLoaderCallback* callback_;
37 DISALLOW_COPY_AND_ASSIGN(TabLoaderDelegateImpl);
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);
52 TabLoaderDelegateImpl::~TabLoaderDelegateImpl() {
53 net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this);
56 void TabLoaderDelegateImpl::OnConnectionTypeChanged(
57 net::NetworkChangeNotifier::ConnectionType type) {
58 callback_->SetTabLoadingEnabled(
59 type != net::NetworkChangeNotifier::CONNECTION_NONE);
61 } // namespace
63 // static
64 scoped_ptr<TabLoaderDelegate> TabLoaderDelegate::Create(
65 TabLoaderCallback* callback) {
66 return scoped_ptr<TabLoaderDelegate>(
67 new TabLoaderDelegateImpl(callback));