Move CellularDataPlanInfo to CellularDataPlan conversion code to cros_network_functions.cc

Move CellularDataPlan from network_library.* to its own files.
Move CellularDataInfo to CellularData conversion code to cros_network_functions.cc

BUG=chromium-os:16557
TEST=unit_tests --gtest_filter="CrosNetworkFunctionsLibcrosTest.CrosMonitorCellularDataPlan"

Review URL: https://chromiumcodereview.appspot.com/10207006

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@133918 0039d316-1c4b-4281-b951-d872f2087c98
parent 5d9a4b9c
// Copyright (c) 2012 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 "chrome/browser/chromeos/cros/cellular_data_plan.h"
#include "base/i18n/time_formatting.h"
#include "base/string_number_conversions.h"
#include "base/utf_string_conversions.h"
#include "chrome/common/time_format.h"
#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/text/bytes_formatting.h"
namespace chromeos {
// Cellular network is considered low data when less than 60 minues.
const int kCellularDataLowSecs = 60 * 60;
// Cellular network is considered low data when less than 30 minues.
const int kCellularDataVeryLowSecs = 30 * 60;
// Cellular network is considered low data when less than 100MB.
const int kCellularDataLowBytes = 100 * 1024 * 1024;
// Cellular network is considered very low data when less than 50MB.
const int kCellularDataVeryLowBytes = 50 * 1024 * 1024;
CellularDataPlan::CellularDataPlan()
: plan_name("Unknown"),
plan_type(CELLULAR_DATA_PLAN_UNLIMITED),
plan_data_bytes(0),
data_bytes_used(0) {
}
CellularDataPlan::CellularDataPlan(const CellularDataPlanInfo &plan)
: plan_name(plan.plan_name ? plan.plan_name : ""),
plan_type(plan.plan_type),
update_time(base::Time::FromInternalValue(plan.update_time)),
plan_start_time(base::Time::FromInternalValue(plan.plan_start_time)),
plan_end_time(base::Time::FromInternalValue(plan.plan_end_time)),
plan_data_bytes(plan.plan_data_bytes),
data_bytes_used(plan.data_bytes_used) {
}
CellularDataPlan::~CellularDataPlan() {}
string16 CellularDataPlan::GetPlanDesciption() const {
switch (plan_type) {
case chromeos::CELLULAR_DATA_PLAN_UNLIMITED: {
return l10n_util::GetStringFUTF16(
IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PURCHASE_UNLIMITED_DATA,
base::TimeFormatFriendlyDate(plan_start_time));
break;
}
case chromeos::CELLULAR_DATA_PLAN_METERED_PAID: {
return l10n_util::GetStringFUTF16(
IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PURCHASE_DATA,
ui::FormatBytes(plan_data_bytes),
base::TimeFormatFriendlyDate(plan_start_time));
}
case chromeos::CELLULAR_DATA_PLAN_METERED_BASE: {
return l10n_util::GetStringFUTF16(
IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_RECEIVED_FREE_DATA,
ui::FormatBytes(plan_data_bytes),
base::TimeFormatFriendlyDate(plan_start_time));
default:
break;
}
}
return string16();
}
string16 CellularDataPlan::GetRemainingWarning() const {
if (plan_type == chromeos::CELLULAR_DATA_PLAN_UNLIMITED) {
// Time based plan. Show nearing expiration and data expiration.
if (remaining_time().InSeconds() <= chromeos::kCellularDataVeryLowSecs) {
return GetPlanExpiration();
}
} else if (plan_type == chromeos::CELLULAR_DATA_PLAN_METERED_PAID ||
plan_type == chromeos::CELLULAR_DATA_PLAN_METERED_BASE) {
// Metered plan. Show low data and out of data.
if (remaining_data() <= chromeos::kCellularDataVeryLowBytes) {
int64 remaining_mbytes = remaining_data() / (1024 * 1024);
return l10n_util::GetStringFUTF16(
IDS_NETWORK_DATA_REMAINING_MESSAGE,
UTF8ToUTF16(base::Int64ToString(remaining_mbytes)));
}
}
return string16();
}
string16 CellularDataPlan::GetDataRemainingDesciption() const {
int64 remaining_bytes = remaining_data();
switch (plan_type) {
case chromeos::CELLULAR_DATA_PLAN_UNLIMITED: {
return l10n_util::GetStringUTF16(
IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_UNLIMITED);
}
case chromeos::CELLULAR_DATA_PLAN_METERED_PAID: {
return ui::FormatBytes(remaining_bytes);
}
case chromeos::CELLULAR_DATA_PLAN_METERED_BASE: {
return ui::FormatBytes(remaining_bytes);
}
default:
break;
}
return string16();
}
string16 CellularDataPlan::GetUsageInfo() const {
if (plan_type == chromeos::CELLULAR_DATA_PLAN_UNLIMITED) {
// Time based plan. Show nearing expiration and data expiration.
return GetPlanExpiration();
} else if (plan_type == chromeos::CELLULAR_DATA_PLAN_METERED_PAID ||
plan_type == chromeos::CELLULAR_DATA_PLAN_METERED_BASE) {
// Metered plan. Show low data and out of data.
int64 remaining_bytes = remaining_data();
if (remaining_bytes == 0) {
return l10n_util::GetStringUTF16(
IDS_NETWORK_DATA_NONE_AVAILABLE_MESSAGE);
} else if (remaining_bytes < 1024 * 1024) {
return l10n_util::GetStringUTF16(
IDS_NETWORK_DATA_LESS_THAN_ONE_MB_AVAILABLE_MESSAGE);
} else {
int64 remaining_mb = remaining_bytes / (1024 * 1024);
return l10n_util::GetStringFUTF16(
IDS_NETWORK_DATA_MB_AVAILABLE_MESSAGE,
UTF8ToUTF16(base::Int64ToString(remaining_mb)));
}
}
return string16();
}
std::string CellularDataPlan::GetUniqueIdentifier() const {
// A cellular plan is uniquely described by the union of name, type,
// start time, end time, and max bytes.
// So we just return a union of all these variables.
return plan_name + "|" +
base::Int64ToString(plan_type) + "|" +
base::Int64ToString(plan_start_time.ToInternalValue()) + "|" +
base::Int64ToString(plan_end_time.ToInternalValue()) + "|" +
base::Int64ToString(plan_data_bytes);
}
base::TimeDelta CellularDataPlan::remaining_time() const {
base::TimeDelta time = plan_end_time - base::Time::Now();
return time.InMicroseconds() < 0 ? base::TimeDelta() : time;
}
int64 CellularDataPlan::remaining_minutes() const {
return remaining_time().InMinutes();
}
int64 CellularDataPlan::remaining_data() const {
int64 data = plan_data_bytes - data_bytes_used;
return data < 0 ? 0 : data;
}
string16 CellularDataPlan::GetPlanExpiration() const {
return TimeFormat::TimeRemaining(remaining_time());
}
} // namespace chromeos
// Copyright (c) 2012 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.
#ifndef CHROME_BROWSER_CHROMEOS_CROS_CELLULAR_DATA_PLAN_H_
#define CHROME_BROWSER_CHROMEOS_CROS_CELLULAR_DATA_PLAN_H_
#include <string>
#include "base/memory/scoped_vector.h"
#include "base/string16.h"
#include "base/time.h"
#include "third_party/cros/chromeos_network.h"
namespace chromeos {
// Cellular network is considered low data when less than 60 minues.
extern const int kCellularDataLowSecs;
// Cellular network is considered low data when less than 30 minues.
extern const int kCellularDataVeryLowSecs;
// Cellular network is considered low data when less than 100MB.
extern const int kCellularDataLowBytes;
// Cellular network is considered very low data when less than 50MB.
extern const int kCellularDataVeryLowBytes;
class CellularDataPlan {
public:
CellularDataPlan();
explicit CellularDataPlan(const CellularDataPlanInfo &plan);
~CellularDataPlan();
// Formats cellular plan description.
string16 GetPlanDesciption() const;
// Evaluates cellular plans status and returns warning string if it is near
// expiration.
string16 GetRemainingWarning() const;
// Formats remaining plan data description.
string16 GetDataRemainingDesciption() const;
// Formats plan expiration description.
string16 GetPlanExpiration() const;
// Formats plan usage info.
string16 GetUsageInfo() const;
// Returns a unique string for this plan that can be used for comparisons.
std::string GetUniqueIdentifier() const;
base::TimeDelta remaining_time() const;
int64 remaining_minutes() const;
// Returns plan data remaining in bytes.
int64 remaining_data() const;
// TODO(stevenjb): Make these private with accessors and properly named.
std::string plan_name;
CellularDataPlanType plan_type;
base::Time update_time;
base::Time plan_start_time;
base::Time plan_end_time;
int64 plan_data_bytes;
int64 data_bytes_used;
};
typedef ScopedVector<CellularDataPlan> CellularDataPlanVector;
} // namespace chromeos
#endif // CHROME_BROWSER_CHROMEOS_CROS_CELLULAR_DATA_PLAN_H_
......@@ -138,13 +138,37 @@ class NetworkDevicePropertiesWatcher : public CrosNetworkWatcher {
// Class to watch data plan update with Libcros.
class CrosDataPlanUpdateWatcher : public CrosNetworkWatcher {
public:
CrosDataPlanUpdateWatcher(MonitorDataPlanCallback callback, void* object)
: monitor_(chromeos::MonitorCellularDataPlan(callback, object)) {}
explicit CrosDataPlanUpdateWatcher(
const DataPlanUpdateWatcherCallback& callback)
: callback_(callback),
monitor_(chromeos::MonitorCellularDataPlan(&OnDataPlanUpdate, this)) {}
virtual ~CrosDataPlanUpdateWatcher() {
chromeos::DisconnectDataPlanUpdateMonitor(monitor_);
}
private:
static void OnDataPlanUpdate(void* object,
const char* modem_service_path,
const CellularDataPlanList* data_plan_list) {
CrosDataPlanUpdateWatcher* watcher =
static_cast<CrosDataPlanUpdateWatcher*>(object);
if (modem_service_path && data_plan_list) {
// Copy contents of |data_plan_list| from libcros to |data_plan_vector|.
CellularDataPlanVector* data_plan_vector = new CellularDataPlanVector;
for (size_t i = 0; i < data_plan_list->plans_size; ++i) {
const CellularDataPlanInfo* info =
data_plan_list->GetCellularDataPlan(i);
CellularDataPlan* plan = new CellularDataPlan(*info);
data_plan_vector->push_back(plan);
VLOG(2) << " Plan: " << plan->GetPlanDesciption()
<< " : " << plan->GetDataRemainingDesciption();
}
// |data_plan_vector| will be owned by callback.
watcher->callback_.Run(modem_service_path, data_plan_vector);
}
}
DataPlanUpdateWatcherCallback callback_;
DataPlanUpdateMonitor monitor_;
};
......@@ -396,8 +420,8 @@ CrosNetworkWatcher* CrosMonitorNetworkDeviceProperties(
}
CrosNetworkWatcher* CrosMonitorCellularDataPlan(
MonitorDataPlanCallback callback, void* object) {
return new CrosDataPlanUpdateWatcher(callback, object);
const DataPlanUpdateWatcherCallback& callback) {
return new CrosDataPlanUpdateWatcher(callback);
}
CrosNetworkWatcher* CrosMonitorSMS(const std::string& modem_device_path,
......
......@@ -14,6 +14,7 @@
#include "base/callback.h"
#include "base/memory/scoped_ptr.h"
#include "chrome/browser/chromeos/cros/cellular_data_plan.h"
#include "third_party/cros/chromeos_network.h"
namespace base {
......@@ -36,6 +37,11 @@ typedef base::Callback<void(
const std::string& key,
const base::Value& value)> NetworkPropertiesWatcherCallback;
// Callback for data plan update watchers.
typedef base::Callback<void(
const std::string& modem_service_path,
CellularDataPlanVector* data_plan_vector)> DataPlanUpdateWatcherCallback;
// Base class of signal watchers.
class CrosNetworkWatcher {
public:
......@@ -122,7 +128,7 @@ CrosNetworkWatcher* CrosMonitorNetworkDeviceProperties(
// Sets up monitoring of the cellular data plan updates from Cashew.
CrosNetworkWatcher* CrosMonitorCellularDataPlan(
MonitorDataPlanCallback callback, void* object);
const DataPlanUpdateWatcherCallback& callback);
// Similar to MonitorNetworkManagerProperties for a specified network device.
CrosNetworkWatcher* CrosMonitorSMS(const std::string& modem_device_path,
......
......@@ -83,6 +83,56 @@ class MockNetworkPropertiesWatcherCallback {
const base::Value& value));
};
// A mock to check arguments of CellularDataPlanWatcherCallback and ensure that
// the callback is called exactly once.
class MockDataPlanUpdateWatcherCallback {
public:
// Creates a NetworkPropertiesWatcherCallback with expectations.
static DataPlanUpdateWatcherCallback CreateCallback(
const std::string& expected_modem_service_path,
const CellularDataPlanVector& expected_data_plan_vector) {
MockDataPlanUpdateWatcherCallback* mock_callback =
new MockDataPlanUpdateWatcherCallback;
mock_callback->expected_data_plan_vector_ = &expected_data_plan_vector;
EXPECT_CALL(*mock_callback,
Run(expected_modem_service_path, _))
.WillOnce(Invoke(mock_callback,
&MockDataPlanUpdateWatcherCallback::CheckDataPlans));
return base::Bind(&MockDataPlanUpdateWatcherCallback::Run,
base::Owned(mock_callback));
}
MOCK_METHOD2(Run, void(const std::string& modem_service_path,
CellularDataPlanVector* data_plan_vector));
private:
void CheckDataPlans(const std::string& modem_service_path,
CellularDataPlanVector* data_plan_vector) {
ASSERT_EQ(expected_data_plan_vector_->size(), data_plan_vector->size());
for (size_t i = 0; i != data_plan_vector->size(); ++i) {
EXPECT_EQ((*expected_data_plan_vector_)[i]->plan_name,
(*data_plan_vector)[i]->plan_name);
EXPECT_EQ((*expected_data_plan_vector_)[i]->plan_type,
(*data_plan_vector)[i]->plan_type);
EXPECT_EQ((*expected_data_plan_vector_)[i]->update_time,
(*data_plan_vector)[i]->update_time);
EXPECT_EQ((*expected_data_plan_vector_)[i]->plan_start_time,
(*data_plan_vector)[i]->plan_start_time);
EXPECT_EQ((*expected_data_plan_vector_)[i]->plan_end_time,
(*data_plan_vector)[i]->plan_end_time);
EXPECT_EQ((*expected_data_plan_vector_)[i]->plan_data_bytes,
(*data_plan_vector)[i]->plan_data_bytes);
EXPECT_EQ((*expected_data_plan_vector_)[i]->data_bytes_used,
(*data_plan_vector)[i]->data_bytes_used);
}
delete data_plan_vector;
}
const CellularDataPlanVector* expected_data_plan_vector_;
};
} // namespace
// Test for cros_network_functions.cc with Libcros.
......@@ -177,11 +227,6 @@ class CrosNetworkFunctionsLibcrosTest : public testing::Test {
NetworkMethodErrorType error,
const char* error_message) {}
// Does nothing. Used as an argument.
static void OnDataPlansUpdate(void* object,
const char* modem_service_path,
const CellularDataPlanList* dataplan) {}
// Does nothing. Used as an argument.
static void OnSmsReceived(void* object,
const char* modem_device_path,
......@@ -376,18 +421,42 @@ TEST_F(CrosNetworkFunctionsLibcrosTest, CrosMonitorNetworkDeviceProperties) {
}
TEST_F(CrosNetworkFunctionsLibcrosTest, CrosMonitorCellularDataPlan) {
MonitorDataPlanCallback callback =
&CrosNetworkFunctionsLibcrosTest::OnDataPlansUpdate;
void* object = this;
DataPlanUpdateMonitor monitor = NULL; // dummy
const std::string modem_service_path = "/modem/path";
CellularDataPlanInfo data_plan = {};
data_plan.plan_name = "plan name";
data_plan.update_time = 123456;
data_plan.plan_start_time = 234567;
data_plan.plan_end_time = 345678;
data_plan.plan_data_bytes = 1024*1024;
data_plan.data_bytes_used = 12345;
CellularDataPlanList data_plans = {};
data_plans.plans = &data_plan;
data_plans.plans_size = 1;
data_plans.data_plan_size = sizeof(data_plan);
CellularDataPlanVector result;
result.push_back(new CellularDataPlan(data_plan));
// Set expectations.
DataPlanUpdateWatcherCallback callback =
MockDataPlanUpdateWatcherCallback::CreateCallback(modem_service_path,
result);
MonitorDataPlanCallback arg_callback = NULL;
void* arg_object = NULL;
EXPECT_CALL(*MockChromeOSNetwork::Get(), MonitorCellularDataPlan(_, _))
.WillOnce(DoAll(SaveArg<0>(&arg_callback), SaveArg<1>(&arg_object),
Return(monitor)));
// Start monitoring.
EXPECT_CALL(*MockChromeOSNetwork::Get(),
MonitorCellularDataPlan(callback, object)).Times(1);
CrosNetworkWatcher* watcher = CrosMonitorCellularDataPlan(callback, object);
CrosNetworkWatcher* watcher = CrosMonitorCellularDataPlan(callback);
// Run callback.
arg_callback(arg_object, modem_service_path.c_str(), &data_plans);
// Stop monitoring.
EXPECT_CALL(*MockChromeOSNetwork::Get(),
DisconnectDataPlanUpdateMonitor(_)).Times(1);
DisconnectDataPlanUpdateMonitor(monitor)).Times(1);
delete watcher;
}
......
......@@ -21,13 +21,11 @@
#include "chrome/browser/chromeos/cros/network_library_impl_cros.h"
#include "chrome/browser/chromeos/cros/network_library_impl_stub.h"
#include "chrome/browser/net/browser_url_util.h"
#include "chrome/common/time_format.h"
#include "chrome/common/net/x509_certificate_model.h"
#include "content/public/browser/browser_thread.h"
#include "grit/generated_resources.h"
#include "third_party/cros_system_api/dbus/service_constants.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/text/bytes_formatting.h"
using content::BrowserThread;
......@@ -746,145 +744,6 @@ void VirtualNetwork::MatchCertificatePattern(bool allow_enroll,
////////////////////////////////////////////////////////////////////////////////
// WirelessNetwork
////////////////////////////////////////////////////////////////////////////////
// CellularDataPlan
CellularDataPlan::CellularDataPlan()
: plan_name("Unknown"),
plan_type(CELLULAR_DATA_PLAN_UNLIMITED),
plan_data_bytes(0),
data_bytes_used(0) {
}
CellularDataPlan::CellularDataPlan(const CellularDataPlanInfo &plan)
: plan_name(plan.plan_name ? plan.plan_name : ""),
plan_type(plan.plan_type),
update_time(base::Time::FromInternalValue(plan.update_time)),
plan_start_time(base::Time::FromInternalValue(plan.plan_start_time)),
plan_end_time(base::Time::FromInternalValue(plan.plan_end_time)),
plan_data_bytes(plan.plan_data_bytes),
data_bytes_used(plan.data_bytes_used) {
}
CellularDataPlan::~CellularDataPlan() {}
string16 CellularDataPlan::GetPlanDesciption() const {
switch (plan_type) {
case chromeos::CELLULAR_DATA_PLAN_UNLIMITED: {
return l10n_util::GetStringFUTF16(
IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PURCHASE_UNLIMITED_DATA,
base::TimeFormatFriendlyDate(plan_start_time));
break;
}
case chromeos::CELLULAR_DATA_PLAN_METERED_PAID: {
return l10n_util::GetStringFUTF16(
IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PURCHASE_DATA,
ui::FormatBytes(plan_data_bytes),
base::TimeFormatFriendlyDate(plan_start_time));
}
case chromeos::CELLULAR_DATA_PLAN_METERED_BASE: {
return l10n_util::GetStringFUTF16(
IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_RECEIVED_FREE_DATA,
ui::FormatBytes(plan_data_bytes),
base::TimeFormatFriendlyDate(plan_start_time));
default:
break;
}
}
return string16();
}
string16 CellularDataPlan::GetRemainingWarning() const {
if (plan_type == chromeos::CELLULAR_DATA_PLAN_UNLIMITED) {
// Time based plan. Show nearing expiration and data expiration.
if (remaining_time().InSeconds() <= chromeos::kCellularDataVeryLowSecs) {
return GetPlanExpiration();
}
} else if (plan_type == chromeos::CELLULAR_DATA_PLAN_METERED_PAID ||
plan_type == chromeos::CELLULAR_DATA_PLAN_METERED_BASE) {
// Metered plan. Show low data and out of data.
if (remaining_data() <= chromeos::kCellularDataVeryLowBytes) {
int64 remaining_mbytes = remaining_data() / (1024 * 1024);
return l10n_util::GetStringFUTF16(
IDS_NETWORK_DATA_REMAINING_MESSAGE,
UTF8ToUTF16(base::Int64ToString(remaining_mbytes)));
}
}
return string16();
}
string16 CellularDataPlan::GetDataRemainingDesciption() const {
int64 remaining_bytes = remaining_data();
switch (plan_type) {
case chromeos::CELLULAR_DATA_PLAN_UNLIMITED: {
return l10n_util::GetStringUTF16(
IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_UNLIMITED);
}
case chromeos::CELLULAR_DATA_PLAN_METERED_PAID: {
return ui::FormatBytes(remaining_bytes);
}
case chromeos::CELLULAR_DATA_PLAN_METERED_BASE: {
return ui::FormatBytes(remaining_bytes);
}
default:
break;
}
return string16();
}
string16 CellularDataPlan::GetUsageInfo() const {
if (plan_type == chromeos::CELLULAR_DATA_PLAN_UNLIMITED) {
// Time based plan. Show nearing expiration and data expiration.
return GetPlanExpiration();
} else if (plan_type == chromeos::CELLULAR_DATA_PLAN_METERED_PAID ||
plan_type == chromeos::CELLULAR_DATA_PLAN_METERED_BASE) {
// Metered plan. Show low data and out of data.
int64 remaining_bytes = remaining_data();
if (remaining_bytes == 0) {
return l10n_util::GetStringUTF16(
IDS_NETWORK_DATA_NONE_AVAILABLE_MESSAGE);
} else if (remaining_bytes < 1024 * 1024) {
return l10n_util::GetStringUTF16(
IDS_NETWORK_DATA_LESS_THAN_ONE_MB_AVAILABLE_MESSAGE);
} else {
int64 remaining_mb = remaining_bytes / (1024 * 1024);
return l10n_util::GetStringFUTF16(
IDS_NETWORK_DATA_MB_AVAILABLE_MESSAGE,
UTF8ToUTF16(base::Int64ToString(remaining_mb)));
}
}
return string16();
}
std::string CellularDataPlan::GetUniqueIdentifier() const {
// A cellular plan is uniquely described by the union of name, type,
// start time, end time, and max bytes.
// So we just return a union of all these variables.
return plan_name + "|" +
base::Int64ToString(plan_type) + "|" +
base::Int64ToString(plan_start_time.ToInternalValue()) + "|" +
base::Int64ToString(plan_end_time.ToInternalValue()) + "|" +
base::Int64ToString(plan_data_bytes);
}
base::TimeDelta CellularDataPlan::remaining_time() const {
base::TimeDelta time = plan_end_time - base::Time::Now();
return time.InMicroseconds() < 0 ? base::TimeDelta() : time;
}
int64 CellularDataPlan::remaining_minutes() const {
return remaining_time().InMinutes();
}
int64 CellularDataPlan::remaining_data() const {
int64 data = plan_data_bytes - data_bytes_used;
return data < 0 ? 0 : data;
}
string16 CellularDataPlan::GetPlanExpiration() const {
return TimeFormat::TimeRemaining(remaining_time());
}
////////////////////////////////////////////////////////////////////////////////
// CellTower
......
......@@ -13,11 +13,9 @@
#include "base/compiler_specific.h"
#include "base/gtest_prod_util.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/scoped_vector.h"
#include "base/memory/singleton.h"
#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
#include "base/string16.h"
#include "base/timer.h"
#include "chrome/browser/chromeos/cros/cros_network_functions.h"
#include "chrome/browser/chromeos/cros/network_constants.h"
......@@ -73,18 +71,6 @@ struct CellularApn {
};
typedef std::vector<CellularApn> CellularApnList;
// Cellular network is considered low data when less than 60 minues.
static const int kCellularDataLowSecs = 60 * 60;
// Cellular network is considered low data when less than 30 minues.
static const int kCellularDataVeryLowSecs = 30 * 60;
// Cellular network is considered low data when less than 100MB.
static const int kCellularDataLowBytes = 100 * 1024 * 1024;
// Cellular network is considered very low data when less than 50MB.
static const int kCellularDataVeryLowBytes = 50 * 1024 * 1024;
// The value of priority if it is not set.
const int kPriorityNotSet = 0;
// The value of priority if network is preferred.
......@@ -801,8 +787,6 @@ class WirelessNetwork : public Network {
};
// Class for networks of TYPE_CELLULAR.
class CellularDataPlan;
class CellularNetwork : public WirelessNetwork {
public:
enum DataLeft {
......@@ -1142,41 +1126,6 @@ class WifiNetwork : public WirelessNetwork {
};
typedef std::vector<WifiNetwork*> WifiNetworkVector;
// Cellular Data Plan management.
class CellularDataPlan {
public:
CellularDataPlan();
explicit CellularDataPlan(const CellularDataPlanInfo &plan);
~CellularDataPlan();
// Formats cellular plan description.
string16 GetPlanDesciption() const;
// Evaluates cellular plans status and returns warning string if it is near
// expiration.
string16 GetRemainingWarning() const;
// Formats remaining plan data description.
string16 GetDataRemainingDesciption() const;
// Formats plan expiration description.
string16 GetPlanExpiration() const;
// Formats plan usage info.
string16 GetUsageInfo() const;
// Returns a unique string for this plan that can be used for comparisons.
std::string GetUniqueIdentifier() const;
base::TimeDelta remaining_time() const;
int64 remaining_minutes() const;
// Returns plan data remaining in bytes.
int64 remaining_data() const;
// TODO(stevenjb): Make these private with accessors and properly named.
std::string plan_name;
CellularDataPlanType plan_type;
base::Time update_time;
base::Time plan_start_time;
base::Time plan_end_time;
int64 plan_data_bytes;
int64 data_bytes_used;
};
typedef ScopedVector<CellularDataPlan> CellularDataPlanVector;
// Geolocation data.
struct CellTower {
CellTower();
......
......@@ -58,7 +58,7 @@ void NetworkLibraryImplCros::Init() {
network_manager_watcher_.reset(CrosMonitorNetworkManagerProperties(
base::Bind(&NetworkManagerStatusChangedHandler, this)));
data_plan_watcher_.reset(
CrosMonitorCellularDataPlan(&DataPlanUpdateHandler, this));
CrosMonitorCellularDataPlan(base::Bind(&DataPlanUpdateHandler, this)));
// Always have at least one device obsever so that device updates are
// always received.
network_device_observer_.reset(new NetworkLibraryDeviceObserver());
......@@ -774,26 +774,11 @@ void NetworkLibraryImplCros::ParseNetworkManager(const DictionaryValue& dict) {
// static
void NetworkLibraryImplCros::DataPlanUpdateHandler(
void* object,
const char* modem_service_path,
const chromeos::CellularDataPlanList* data_plan_list) {
DCHECK(CrosLibrary::Get()->libcros_loaded());
const std::string& modem_service_path,
CellularDataPlanVector* data_plan_vector) {
NetworkLibraryImplCros* networklib =
static_cast<NetworkLibraryImplCros*>(object);
DCHECK(networklib);
if (modem_service_path && data_plan_list) {
// Copy contents of |data_plan_list| from libcros to |data_plan_vector|.
CellularDataPlanVector* data_plan_vector = new CellularDataPlanVector;
for (size_t i = 0; i < data_plan_list->plans_size; ++i) {
const CellularDataPlanInfo* info(data_plan_list->GetCellularDataPlan(i));
CellularDataPlan* plan = new CellularDataPlan(*info);
data_plan_vector->push_back(plan);
VLOG(2) << " Plan: " << plan->GetPlanDesciption()
<< " : " << plan->GetDataRemainingDesciption();
}
// |data_plan_vector| will become owned by networklib.
networklib->UpdateCellularDataPlan(std::string(modem_service_path),
data_plan_vector);
}
networklib->UpdateCellularDataPlan(modem_service_path, data_plan_vector);
}
////////////////////////////////////////////////////////////////////////////
......
......@@ -126,8 +126,8 @@ class NetworkLibraryImplCros : public NetworkLibraryImplBase {
static void DataPlanUpdateHandler(
void* object,
const char* modem_service_path,
const chromeos::CellularDataPlanList* data_plan_list);
const std::string& modem_service_path,
CellularDataPlanVector* data_plan_vector);
static void NetworkServiceUpdate(void* object,
const std::string& service_path,
......
......@@ -429,6 +429,8 @@
'browser/chromeos/chrome_browser_main_chromeos.h',
'browser/chromeos/cros/burn_library.cc',
'browser/chromeos/cros/burn_library.h',
'browser/chromeos/cros/cellular_data_plan.cc',
'browser/chromeos/cros/cellular_data_plan.h',
'browser/chromeos/cros/cert_library.cc',
'browser/chromeos/cros/cert_library.h',
'browser/chromeos/cros/certificate_pattern.cc',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment