Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 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. | |
| 4 | |
| 5 #include "components/metrics/net/cellular_logic_helper.h" | |
| 6 | |
| 7 #include "components/variations/variations_associated_data.h" | |
| 8 #include "net/base/network_change_notifier.h" | |
| 9 | |
| 10 namespace metrics { | |
| 11 | |
| 12 // Standard interval between log uploads, in seconds. | |
| 13 #if defined(OS_ANDROID) || defined(OS_IOS) | |
| 14 const int kStandardUploadIntervalSeconds = 5 * 60; // Five minutes. | |
| 15 const int kStandardUploadIntervalCellularSeconds = 15 * 60; // Fifteen minutes. | |
| 16 #else | |
| 17 const int kStandardUploadIntervalSeconds = 30 * 60; // Thirty minutes. | |
| 18 #endif | |
| 19 | |
| 20 const bool kDefaultCellularLogicEnabled = true; | |
| 21 const bool kDefaultCellularLogicOptimization = true; | |
|
Alexei Svitkine (slow)
2016/05/13 18:37:13
These should be in the anon namespace.
gayane -on leave until 09-2017
2016/05/13 19:17:02
Done.
| |
| 22 | |
| 23 base::TimeDelta GetUploadInterval() { | |
| 24 #if defined(OS_ANDROID) || defined(OS_IOS) | |
| 25 if (IsCellularLogicEnabled()) | |
| 26 return base::TimeDelta::FromSeconds(kStandardUploadIntervalCellularSeconds); | |
| 27 #endif | |
| 28 return base::TimeDelta::FromSeconds(kStandardUploadIntervalSeconds); | |
| 29 } | |
| 30 | |
| 31 // Returns true if current connection type is cellular and user is assigned to | |
| 32 // experimental group for enabled cellular uploads. | |
| 33 bool IsCellularLogicEnabled() { | |
|
Alexei Svitkine (slow)
2016/05/13 18:37:13
Should we make this return false when platform is
gayane -on leave until 09-2017
2016/05/13 19:17:02
Done.
| |
| 34 std::string enabled = variations::GetVariationParamValue( | |
| 35 "UMA_EnableCellularLogUpload", "Enabled"); | |
| 36 std::string optimized = variations::GetVariationParamValue( | |
| 37 "UMA_EnableCellularLogUpload", "Optimize"); | |
| 38 bool is_enabled; | |
| 39 if (enabled.empty()) | |
| 40 is_enabled = kDefaultCellularLogicEnabled; | |
| 41 else | |
| 42 is_enabled = enabled == "true"; | |
|
Alexei Svitkine (slow)
2016/05/13 18:37:13
Nit: How about this structure:
bool is_enabled =
gayane -on leave until 09-2017
2016/05/13 19:17:01
Done.
| |
| 43 | |
| 44 bool is_optimized; | |
| 45 if (optimized.empty()) | |
| 46 is_optimized = kDefaultCellularLogicOptimization; | |
| 47 else | |
| 48 is_optimized = optimized == "true"; | |
| 49 | |
| 50 if (!is_enabled || !is_optimized) | |
| 51 return false; | |
| 52 | |
| 53 return net::NetworkChangeNotifier::IsConnectionCellular( | |
| 54 net::NetworkChangeNotifier::GetConnectionType()); | |
| 55 } | |
| 56 } // namespace metrics | |
| OLD | NEW |