summaryrefslogtreecommitdiff
path: root/chromium/services/network/throttling/network_conditions.cc
blob: 18b2b6e0efdc2e17dbbbfaa411b4ab49ec787bc4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "services/network/throttling/network_conditions.h"

#include <algorithm>

namespace network {

NetworkConditions::NetworkConditions() : NetworkConditions(false) {}

NetworkConditions::NetworkConditions(bool offline)
    : NetworkConditions(offline, 0, 0, 0) {}

NetworkConditions::NetworkConditions(bool offline,
                                     double latency,
                                     double download_throughput,
                                     double upload_throughput)
    : offline_(offline),
      latency_(std::max(latency, 0.0)),
      download_throughput_(std::max(download_throughput, 0.0)),
      upload_throughput_(std::max(upload_throughput, 0.0)) {}

NetworkConditions::~NetworkConditions() {}

bool NetworkConditions::IsThrottling() const {
  return !offline_ && ((latency_ != 0) || (download_throughput_ != 0.0) ||
                       (upload_throughput_ != 0));
}

}  // namespace network