| 
 | 
 | 
 Chromium Code Reviews
 Chromium Code Reviews Issue 
            1144163008:
    Add in-memory caching of network quality estimates across network changes.  (Closed)
    
  
    Issue 
            1144163008:
    Add in-memory caching of network quality estimates across network changes.  (Closed) 
  | DescriptionAdd in-memory caching of network quality estimates across network changes.
This is the first step towards preserving network quality
estimates across browser session restarts.
User may switch between different networks within
the same browser session (e.g., from Wi-Fi to cellular
and back to Wi-Fi). This change caches the estimates
when the device switches networks. If the user
uses the same network again, the cached estimates
would be used to quickly arrive at quality
estimates.
BUG=509712
Committed: https://crrev.com/75540a59248efeb382e515971b762c17592a6ada
Cr-Commit-Position: refs/heads/master@{#338923}
   Patch Set 1 #Patch Set 2 : Minor modifications to comments and code #
      Total comments: 18
      
     Patch Set 3 : Addressed comments and reorganized tests #
      Total comments: 36
      
     Patch Set 4 : Addressed comments #
      Total comments: 14
      
     Patch Set 5 : Addressed comments #Patch Set 6 : Added DCHECK #Patch Set 7 : rebased and style fixes #
      Total comments: 11
      
     Patch Set 8 : Addressed comments #
      Total comments: 20
      
     Patch Set 9 : Using map instead of vector, added NetworkID struct #
      Total comments: 24
      
     Patch Set 10 : Addressed comments, added more tests, cleaned up tests #
      Total comments: 30
      
     Patch Set 11 : Addressed bengr comments #
      Total comments: 1
      
     Patch Set 12 : rebased and few cleanups #Patch Set 13 : rebased again #
      Total comments: 27
      
     Patch Set 14 : Addressed comments #
      Total comments: 20
      
     Patch Set 15 : Addressed Paul's comments #
      Total comments: 2
      
     Patch Set 16 : Addressed comments #Patch Set 17 : Addressed comments #
      Total comments: 35
      
     Patch Set 18 : Addressed comments #Patch Set 19 : rebased #
      Total comments: 11
      
     Patch Set 20 : Addressed comments #Patch Set 21 : Fixed static const #
      Total comments: 26
      
     Patch Set 22 : Addressed comments #Patch Set 23 : Removed Ethernet #Patch Set 24 : Change const_iterator to iterator to make MacOS compiler happy #Patch Set 25 : Add copy constructor #Patch Set 26 : Not use scoped_ptr #
 Messages
    Total messages: 93 (25 generated)
     
 tbansal@chromium.org changed reviewers: + bengr@chromium.org, mmenke@chromium.org, pauljensen@chromium.org 
 ptal 
 Some nits...I'll defer to Paul on this review. https://codereview.chromium.org/1144163008/diff/20001/net/base/network_qualit... File net/base/network_quality_estimator.cc (right): https://codereview.chromium.org/1144163008/diff/20001/net/base/network_qualit... net/base/network_quality_estimator.cc:324: DCHECK_EQ(kMaximumNetworkQualityCacheSize, cached_network_quality_.size()); include base/logging.h for DCHECK and NOTREACHED. https://codereview.chromium.org/1144163008/diff/20001/net/base/network_qualit... File net/base/network_quality_estimator.h (right): https://codereview.chromium.org/1144163008/diff/20001/net/base/network_qualit... net/base/network_quality_estimator.h:21: struct NET_EXPORT_PRIVATE CachedNetworkQuality { This should be a protected or private class - private seems better, see next comment. https://codereview.chromium.org/1144163008/diff/20001/net/base/network_qualit... net/base/network_quality_estimator.h:21: struct NET_EXPORT_PRIVATE CachedNetworkQuality { Since a subclass for testing only needs to be able to calculate the size of a vector of these, NET_EXPORT_PRIVATE seems overkill. Just add a protected method to NetworkQualityEstimator, and have the subclass expose it with a "using" directive. https://codereview.chromium.org/1144163008/diff/20001/net/base/network_qualit... net/base/network_quality_estimator.h:80: friend class NetworkQualityEstimatorTest; Should not need to friend a subclass. Just make protected accessors for anything it needs. https://codereview.chromium.org/1144163008/diff/20001/net/base/network_qualit... net/base/network_quality_estimator.h:112: virtual std::string GetCurrentNetworkName() const; include <string> https://codereview.chromium.org/1144163008/diff/20001/net/base/network_qualit... net/base/network_quality_estimator.h:139: std::vector<CachedNetworkQuality> cached_network_quality_; include <vector> https://codereview.chromium.org/1144163008/diff/20001/net/base/network_qualit... File net/base/network_quality_estimator_unittest.cc (right): https://codereview.chromium.org/1144163008/diff/20001/net/base/network_qualit... net/base/network_quality_estimator_unittest.cc:102: class NetworkQualityEstimatorTest : public NetworkQualityEstimator { This name is weird: This is the same name as you use in your TEST() lines, but it's not a test fixture (Nor is it a test). Maybe just TestNetworkQualityEstimator? https://codereview.chromium.org/1144163008/diff/20001/net/base/network_qualit... net/base/network_quality_estimator_unittest.cc:104: NetworkQualityEstimatorTest() : NetworkQualityEstimator() {} NetworkQualityEstimator() is not needed. https://codereview.chromium.org/1144163008/diff/20001/net/base/network_qualit... net/base/network_quality_estimator_unittest.cc:111: std::string GetCurrentNetworkName() const override { Should group the overridden methods with a comment along the lines of "NetworkQualityEstimator implementation" above them 
 ptal. thanks. https://codereview.chromium.org/1144163008/diff/20001/net/base/network_qualit... File net/base/network_quality_estimator.cc (right): https://codereview.chromium.org/1144163008/diff/20001/net/base/network_qualit... net/base/network_quality_estimator.cc:324: DCHECK_EQ(kMaximumNetworkQualityCacheSize, cached_network_quality_.size()); On 2015/05/28 15:25:02, mmenke wrote: > include base/logging.h for DCHECK and NOTREACHED. Done. https://codereview.chromium.org/1144163008/diff/20001/net/base/network_qualit... File net/base/network_quality_estimator.h (right): https://codereview.chromium.org/1144163008/diff/20001/net/base/network_qualit... net/base/network_quality_estimator.h:21: struct NET_EXPORT_PRIVATE CachedNetworkQuality { On 2015/05/28 15:25:02, mmenke wrote: > This should be a protected or private class - private seems better, see next > comment. Done. https://codereview.chromium.org/1144163008/diff/20001/net/base/network_qualit... net/base/network_quality_estimator.h:21: struct NET_EXPORT_PRIVATE CachedNetworkQuality { On 2015/05/28 15:25:02, mmenke wrote: > Since a subclass for testing only needs to be able to calculate the size of a > vector of these, NET_EXPORT_PRIVATE seems overkill. Just add a protected method > to NetworkQualityEstimator, and have the subclass expose it with a "using" > directive. Done. https://codereview.chromium.org/1144163008/diff/20001/net/base/network_qualit... net/base/network_quality_estimator.h:80: friend class NetworkQualityEstimatorTest; On 2015/05/28 15:25:02, mmenke wrote: > Should not need to friend a subclass. Just make protected accessors for > anything it needs. Done. https://codereview.chromium.org/1144163008/diff/20001/net/base/network_qualit... net/base/network_quality_estimator.h:112: virtual std::string GetCurrentNetworkName() const; On 2015/05/28 15:25:02, mmenke wrote: > include <string> Done. https://codereview.chromium.org/1144163008/diff/20001/net/base/network_qualit... net/base/network_quality_estimator.h:139: std::vector<CachedNetworkQuality> cached_network_quality_; On 2015/05/28 15:25:03, mmenke wrote: > include <vector> Done. https://codereview.chromium.org/1144163008/diff/20001/net/base/network_qualit... File net/base/network_quality_estimator_unittest.cc (right): https://codereview.chromium.org/1144163008/diff/20001/net/base/network_qualit... net/base/network_quality_estimator_unittest.cc:102: class NetworkQualityEstimatorTest : public NetworkQualityEstimator { On 2015/05/28 15:25:03, mmenke wrote: > This name is weird: This is the same name as you use in your TEST() lines, but > it's not a test fixture (Nor is it a test). > > Maybe just TestNetworkQualityEstimator? Done. https://codereview.chromium.org/1144163008/diff/20001/net/base/network_qualit... net/base/network_quality_estimator_unittest.cc:104: NetworkQualityEstimatorTest() : NetworkQualityEstimator() {} On 2015/05/28 15:25:03, mmenke wrote: > NetworkQualityEstimator() is not needed. Done. https://codereview.chromium.org/1144163008/diff/20001/net/base/network_qualit... net/base/network_quality_estimator_unittest.cc:111: std::string GetCurrentNetworkName() const override { On 2015/05/28 15:25:03, mmenke wrote: > Should group the overridden methods with a comment along the lines of > "NetworkQualityEstimator implementation" above them Done. 
 https://codereview.chromium.org/1144163008/diff/40001/net/base/network_qualit... File net/base/network_quality_estimator.cc (right): https://codereview.chromium.org/1144163008/diff/40001/net/base/network_qualit... net/base/network_quality_estimator.cc:216: NetworkChangeNotifier::ConnectionType::CONNECTION_UNKNOWN || Using a switch might be cleaner. https://codereview.chromium.org/1144163008/diff/40001/net/base/network_qualit... net/base/network_quality_estimator.cc:250: if (current_network_name_ == "") if (current_network_name_.empty()) https://codereview.chromium.org/1144163008/diff/40001/net/base/network_qualit... net/base/network_quality_estimator.cc:256: continue; Add curly braces. https://codereview.chromium.org/1144163008/diff/40001/net/base/network_qualit... net/base/network_quality_estimator.cc:258: // TOOD(tbansal): Populate these values back into the median computing Why are you not doing this in this CL? https://codereview.chromium.org/1144163008/diff/40001/net/base/network_qualit... net/base/network_quality_estimator.cc:272: if (current_network_name_ == "") current_network_name_.empty() https://codereview.chromium.org/1144163008/diff/40001/net/base/network_qualit... net/base/network_quality_estimator.cc:284: continue; Add curly braces. https://codereview.chromium.org/1144163008/diff/40001/net/base/network_qualit... net/base/network_quality_estimator.cc:299: // Overwrite the oldest entry. I guess this is ok, but how often will this code be needed in practice? Can't we just make kMaximumNetworkQualityCacheSize == 25ish, and then ignore additional networks? Also, how does this logic change once this persists? https://codereview.chromium.org/1144163008/diff/40001/net/base/network_qualit... File net/base/network_quality_estimator.h (right): https://codereview.chromium.org/1144163008/diff/40001/net/base/network_qualit... net/base/network_quality_estimator.h:58: void SetCurrentNetworkNameForTests(std::string network_name); const std::string& https://codereview.chromium.org/1144163008/diff/40001/net/base/network_qualit... net/base/network_quality_estimator.h:66: // The MCCMNC code of the cellular carrier if the device is connected to a nit: MCC/MNC https://codereview.chromium.org/1144163008/diff/40001/net/base/network_qualit... net/base/network_quality_estimator.h:85: std::string network_name, const std::string& https://codereview.chromium.org/1144163008/diff/40001/net/base/network_qualit... net/base/network_quality_estimator.h:93: DCHECK_NE(network_name_, std::string()); After reading the comment for UpdateCurrentNetworkName, I thought that network_name_ could be an empty string. https://codereview.chromium.org/1144163008/diff/40001/net/base/network_qualit... net/base/network_quality_estimator.h:101: median_rtt_milliseconds_ = updated_median_rtt_milliseconds; Why are these not TimeDeltas? https://codereview.chromium.org/1144163008/diff/40001/net/base/network_qualit... net/base/network_quality_estimator.h:106: std::string network_name) const { const std::string& https://codereview.chromium.org/1144163008/diff/40001/net/base/network_qualit... net/base/network_quality_estimator.h:115: int median_rtt_milliseconds_; TimeDelta? https://codereview.chromium.org/1144163008/diff/40001/net/base/network_qualit... File net/base/network_quality_estimator_unittest.cc (right): https://codereview.chromium.org/1144163008/diff/40001/net/base/network_qualit... net/base/network_quality_estimator_unittest.cc:122: NetworkQualityEstimator::SetCurrentNetworkNameForTests( It would be better, maybe, if you could use a test NCN instead of introducing a new pathway just for tests. https://codereview.chromium.org/1144163008/diff/40001/net/base/network_qualit... net/base/network_quality_estimator_unittest.cc:135: uint32_t cache_size = 0; Chromium style guide says: Do not use unsigned types to mean "this value should never be < 0". For that, use assertions or run-time checks (as appropriate). Search for "unsigned" in https://www.chromium.org/developers/coding-style 
 ptal. thanks. https://codereview.chromium.org/1144163008/diff/40001/net/base/network_qualit... File net/base/network_quality_estimator.cc (right): https://codereview.chromium.org/1144163008/diff/40001/net/base/network_qualit... net/base/network_quality_estimator.cc:216: NetworkChangeNotifier::ConnectionType::CONNECTION_UNKNOWN || On 2015/05/29 17:38:09, bengr wrote: > Using a switch might be cleaner. Done. https://codereview.chromium.org/1144163008/diff/40001/net/base/network_qualit... net/base/network_quality_estimator.cc:250: if (current_network_name_ == "") On 2015/05/29 17:38:09, bengr wrote: > if (current_network_name_.empty()) Done. https://codereview.chromium.org/1144163008/diff/40001/net/base/network_qualit... net/base/network_quality_estimator.cc:256: continue; On 2015/05/29 17:38:09, bengr wrote: > Add curly braces. Done. https://codereview.chromium.org/1144163008/diff/40001/net/base/network_qualit... net/base/network_quality_estimator.cc:258: // TOOD(tbansal): Populate these values back into the median computing On 2015/05/29 17:38:09, bengr wrote: > Why are you not doing this in this CL? I need to populate these values back into CircularBuffer (aka DecayingHistogram) which I do not have yet. https://codereview.chromium.org/1144163008/diff/40001/net/base/network_qualit... net/base/network_quality_estimator.cc:272: if (current_network_name_ == "") On 2015/05/29 17:38:09, bengr wrote: > current_network_name_.empty() Done. https://codereview.chromium.org/1144163008/diff/40001/net/base/network_qualit... net/base/network_quality_estimator.cc:284: continue; On 2015/05/29 17:38:09, bengr wrote: > Add curly braces. Done. https://codereview.chromium.org/1144163008/diff/40001/net/base/network_qualit... net/base/network_quality_estimator.cc:299: // Overwrite the oldest entry. On 2015/05/29 17:38:09, bengr wrote: > I guess this is ok, but how often will this code be needed in practice? Can't we > just make kMaximumNetworkQualityCacheSize == 25ish, and then ignore additional > networks? If we write the in-memory cache to prefs, 25 still would not be enough. So, at some point, we need to get rid of LRU entries. > > Also, how does this logic change once this persists? Not sure what it means by persists in this context? https://codereview.chromium.org/1144163008/diff/40001/net/base/network_qualit... File net/base/network_quality_estimator.h (right): https://codereview.chromium.org/1144163008/diff/40001/net/base/network_qualit... net/base/network_quality_estimator.h:58: void SetCurrentNetworkNameForTests(std::string network_name); On 2015/05/29 17:38:10, bengr wrote: > const std::string& Done. https://codereview.chromium.org/1144163008/diff/40001/net/base/network_qualit... net/base/network_quality_estimator.h:66: // The MCCMNC code of the cellular carrier if the device is connected to a On 2015/05/29 17:38:10, bengr wrote: > nit: MCC/MNC Done. https://codereview.chromium.org/1144163008/diff/40001/net/base/network_qualit... net/base/network_quality_estimator.h:85: std::string network_name, On 2015/05/29 17:38:10, bengr wrote: > const std::string& Done. https://codereview.chromium.org/1144163008/diff/40001/net/base/network_qualit... net/base/network_quality_estimator.h:93: DCHECK_NE(network_name_, std::string()); On 2015/05/29 17:38:10, bengr wrote: > After reading the comment for UpdateCurrentNetworkName, I thought that > network_name_ could be an empty string. The current network name may be empty but in that case, we should not cache (because empty network name is not distinctive enough). Added comment to explain that. https://codereview.chromium.org/1144163008/diff/40001/net/base/network_qualit... net/base/network_quality_estimator.h:101: median_rtt_milliseconds_ = updated_median_rtt_milliseconds; On 2015/05/29 17:38:10, bengr wrote: > Why are these not TimeDeltas? Initially, I did not make it TimeDelta because if we write this to the pref, we have to write it as an int. But, it is probably better to make this TimeDelta and then convert it to int when reading/writing pref. Done. Done. https://codereview.chromium.org/1144163008/diff/40001/net/base/network_qualit... net/base/network_quality_estimator.h:106: std::string network_name) const { On 2015/05/29 17:38:10, bengr wrote: > const std::string& Done. https://codereview.chromium.org/1144163008/diff/40001/net/base/network_qualit... net/base/network_quality_estimator.h:115: int median_rtt_milliseconds_; On 2015/05/29 17:38:10, bengr wrote: > TimeDelta? Done. https://codereview.chromium.org/1144163008/diff/40001/net/base/network_qualit... File net/base/network_quality_estimator_unittest.cc (right): https://codereview.chromium.org/1144163008/diff/40001/net/base/network_qualit... net/base/network_quality_estimator_unittest.cc:122: NetworkQualityEstimator::SetCurrentNetworkNameForTests( On 2015/05/29 17:38:10, bengr wrote: > It would be better, maybe, if you could use a test NCN instead of introducing a > new pathway just for tests. NCN only exposes ConnectionType and not the SSID name or MCC/MNC code. SSID/MCCMNC names comes from different codebases which IIUC do not have mocking/test classes. https://codereview.chromium.org/1144163008/diff/40001/net/base/network_qualit... net/base/network_quality_estimator_unittest.cc:135: uint32_t cache_size = 0; On 2015/05/29 17:38:10, bengr wrote: > Chromium style guide says: Do not use unsigned types to mean "this value should > never be < 0". For that, use assertions or run-time checks (as appropriate). > Search for "unsigned" in https://www.chromium.org/developers/coding-style > Changed to size_t (instead of int to avoid repeated type casting). 
 https://codereview.chromium.org/1144163008/diff/40001/net/base/network_qualit... File net/base/network_quality_estimator_unittest.cc (right): https://codereview.chromium.org/1144163008/diff/40001/net/base/network_qualit... net/base/network_quality_estimator_unittest.cc:122: NetworkQualityEstimator::SetCurrentNetworkNameForTests( On 2015/05/29 19:13:37, tbansal1 wrote: > On 2015/05/29 17:38:10, bengr wrote: > > It would be better, maybe, if you could use a test NCN instead of introducing > a > > new pathway just for tests. > > NCN only exposes ConnectionType and not > the SSID name or MCC/MNC code. > SSID/MCCMNC names comes from different codebases > which IIUC do not have mocking/test classes. Uggh. Could you configure NQE to register to listen to a little class you write that poses as an NCN? https://codereview.chromium.org/1144163008/diff/60001/net/base/network_qualit... File net/base/network_quality_estimator.cc (right): https://codereview.chromium.org/1144163008/diff/60001/net/base/network_qualit... net/base/network_quality_estimator.cc:275: base::TimeDelta median_rtt = base::TimeDelta(); No need to initialize. The default constructor will do that for you. https://codereview.chromium.org/1144163008/diff/60001/net/base/network_qualit... net/base/network_quality_estimator.cc:321: // Networks with empty names should not be cached since they are harder to I disagree. I think a cached entry is helpful regardless, even if it has no label. https://codereview.chromium.org/1144163008/diff/60001/net/base/network_qualit... net/base/network_quality_estimator.cc:331: const base::TimeDelta& median_rtt) { Would be good to sanity check the parameters, e.g., with DCHECKs. https://codereview.chromium.org/1144163008/diff/60001/net/base/network_qualit... File net/base/network_quality_estimator.h (right): https://codereview.chromium.org/1144163008/diff/60001/net/base/network_qualit... net/base/network_quality_estimator.h:50: // Returns true if cached network quality estimate was successfully read. "if" -> "if the" https://codereview.chromium.org/1144163008/diff/60001/net/base/network_qualit... net/base/network_quality_estimator.h:51: bool ReadCachedNetworkQualityEstimate(); You might want to bite the bullet now and make this interface asynchronous. You will almost certainly need to do so if you expect to persist these cache entries. 
 thanks for the comments. ptal. https://codereview.chromium.org/1144163008/diff/40001/net/base/network_qualit... File net/base/network_quality_estimator_unittest.cc (right): https://codereview.chromium.org/1144163008/diff/40001/net/base/network_qualit... net/base/network_quality_estimator_unittest.cc:122: NetworkQualityEstimator::SetCurrentNetworkNameForTests( On 2015/06/01 20:39:34, bengr wrote: > On 2015/05/29 19:13:37, tbansal1 wrote: > > On 2015/05/29 17:38:10, bengr wrote: > > > It would be better, maybe, if you could use a test NCN instead of > introducing > > a > > > new pathway just for tests. > > > > NCN only exposes ConnectionType and not > > the SSID name or MCC/MNC code. > > SSID/MCCMNC names comes from different codebases > > which IIUC do not have mocking/test classes. > > Uggh. Could you configure NQE to register to listen to a little class you write > that poses as an NCN? Not sure....NCN has nothing to do with SSID name or MCC/MNC names. To find out the current SSID/MCCMNC name, this code calls a synchronous network library API (that in turn calls platform specific code). Not sure how posing an NCN would help. Mocking the network library API would definitely help but I am not sure if that design is better than what I have now. https://codereview.chromium.org/1144163008/diff/60001/net/base/network_qualit... File net/base/network_quality_estimator.cc (right): https://codereview.chromium.org/1144163008/diff/60001/net/base/network_qualit... net/base/network_quality_estimator.cc:275: base::TimeDelta median_rtt = base::TimeDelta(); On 2015/06/01 20:39:34, bengr wrote: > No need to initialize. The default constructor will do that for you. Done. https://codereview.chromium.org/1144163008/diff/60001/net/base/network_qualit... net/base/network_quality_estimator.cc:321: // Networks with empty names should not be cached since they are harder to On 2015/06/01 20:39:34, bengr wrote: > I disagree. I think a cached entry is helpful regardless, even if it has no > label. Done. https://codereview.chromium.org/1144163008/diff/60001/net/base/network_qualit... net/base/network_quality_estimator.cc:331: const base::TimeDelta& median_rtt) { On 2015/06/01 20:39:34, bengr wrote: > Would be good to sanity check the parameters, e.g., with DCHECKs. Added a TODO in ReadCachedNetworkQualityEstimate(). I did not add DCHECK because some of the estimates can legitimately be 0. e.g., if the responses were small, then RTT estimate would be non-zero but the Kbps estimate would be zero. https://codereview.chromium.org/1144163008/diff/60001/net/base/network_qualit... File net/base/network_quality_estimator.h (right): https://codereview.chromium.org/1144163008/diff/60001/net/base/network_qualit... net/base/network_quality_estimator.h:50: // Returns true if cached network quality estimate was successfully read. On 2015/06/01 20:39:35, bengr wrote: > "if" -> "if the" Done. https://codereview.chromium.org/1144163008/diff/60001/net/base/network_qualit... net/base/network_quality_estimator.h:51: bool ReadCachedNetworkQualityEstimate(); On 2015/06/01 20:39:34, bengr wrote: > You might want to bite the bullet now and make this interface asynchronous. You > will almost certainly need to do so if you expect to persist these cache > entries. This CL is complete in the current form. I would prefer to do it when doing the disk based caching. 
 https://codereview.chromium.org/1144163008/diff/40001/net/base/network_qualit... File net/base/network_quality_estimator_unittest.cc (right): https://codereview.chromium.org/1144163008/diff/40001/net/base/network_qualit... net/base/network_quality_estimator_unittest.cc:122: NetworkQualityEstimator::SetCurrentNetworkNameForTests( On 2015/06/01 21:56:51, tbansal1 wrote: > On 2015/06/01 20:39:34, bengr wrote: > > On 2015/05/29 19:13:37, tbansal1 wrote: > > > On 2015/05/29 17:38:10, bengr wrote: > > > > It would be better, maybe, if you could use a test NCN instead of > > introducing > > > a > > > > new pathway just for tests. > > > > > > NCN only exposes ConnectionType and not > > > the SSID name or MCC/MNC code. > > > SSID/MCCMNC names comes from different codebases > > > which IIUC do not have mocking/test classes. > > > > Uggh. Could you configure NQE to register to listen to a little class you > write > > that poses as an NCN? > > Not sure....NCN has nothing to do with SSID name or MCC/MNC names. > To find out the current SSID/MCCMNC name, this code calls a > synchronous network library API (that in turn calls platform specific code). Not > sure how posing an NCN would help. > > Mocking the network library API would definitely help but > I am not sure if that design is better than what I have now. > My mistake. I guess what you have is fine. https://codereview.chromium.org/1144163008/diff/60001/net/base/network_qualit... File net/base/network_quality_estimator.cc (right): https://codereview.chromium.org/1144163008/diff/60001/net/base/network_qualit... net/base/network_quality_estimator.cc:331: const base::TimeDelta& median_rtt) { On 2015/06/01 21:56:51, tbansal1 wrote: > On 2015/06/01 20:39:34, bengr wrote: > > Would be good to sanity check the parameters, e.g., with DCHECKs. > > Added a TODO in ReadCachedNetworkQualityEstimate(). > > I did not add DCHECK because some of the estimates can > legitimately be 0. > e.g., if the responses were small, then RTT estimate would be > non-zero but the Kbps estimate would be zero. I'm not sure what you mean. rtt and kbps should never be negative, e.g. Also, both should probably have an upper bound as well, though I'm not sure what good values would be. Maybe 5 minutes for rtt? https://codereview.chromium.org/1144163008/diff/60001/net/base/network_qualit... File net/base/network_quality_estimator.h (right): https://codereview.chromium.org/1144163008/diff/60001/net/base/network_qualit... net/base/network_quality_estimator.h:51: bool ReadCachedNetworkQualityEstimate(); On 2015/06/01 21:56:51, tbansal1 wrote: > On 2015/06/01 20:39:34, bengr wrote: > > You might want to bite the bullet now and make this interface asynchronous. > You > > will almost certainly need to do so if you expect to persist these cache > > entries. > > This CL is complete in the current form. > I would prefer to do it when doing the disk based caching. Acknowledged. 
 Patchset #6 (id:100001) has been deleted 
 ptal https://codereview.chromium.org/1144163008/diff/40001/net/base/network_qualit... File net/base/network_quality_estimator_unittest.cc (right): https://codereview.chromium.org/1144163008/diff/40001/net/base/network_qualit... net/base/network_quality_estimator_unittest.cc:122: NetworkQualityEstimator::SetCurrentNetworkNameForTests( On 2015/06/01 23:21:10, bengr wrote: > On 2015/06/01 21:56:51, tbansal1 wrote: > > On 2015/06/01 20:39:34, bengr wrote: > > > On 2015/05/29 19:13:37, tbansal1 wrote: > > > > On 2015/05/29 17:38:10, bengr wrote: > > > > > It would be better, maybe, if you could use a test NCN instead of > > > introducing > > > > a > > > > > new pathway just for tests. > > > > > > > > NCN only exposes ConnectionType and not > > > > the SSID name or MCC/MNC code. > > > > SSID/MCCMNC names comes from different codebases > > > > which IIUC do not have mocking/test classes. > > > > > > Uggh. Could you configure NQE to register to listen to a little class you > > write > > > that poses as an NCN? > > > > Not sure....NCN has nothing to do with SSID name or MCC/MNC names. > > To find out the current SSID/MCCMNC name, this code calls a > > synchronous network library API (that in turn calls platform specific code). > Not > > sure how posing an NCN would help. > > > > Mocking the network library API would definitely help but > > I am not sure if that design is better than what I have now. > > > > My mistake. I guess what you have is fine. Done. https://codereview.chromium.org/1144163008/diff/60001/net/base/network_qualit... File net/base/network_quality_estimator.cc (right): https://codereview.chromium.org/1144163008/diff/60001/net/base/network_qualit... net/base/network_quality_estimator.cc:331: const base::TimeDelta& median_rtt) { On 2015/06/01 23:21:10, bengr wrote: > On 2015/06/01 21:56:51, tbansal1 wrote: > > On 2015/06/01 20:39:34, bengr wrote: > > > Would be good to sanity check the parameters, e.g., with DCHECKs. > > > > Added a TODO in ReadCachedNetworkQualityEstimate(). > > > > I did not add DCHECK because some of the estimates can > > legitimately be 0. > > e.g., if the responses were small, then RTT estimate would be > > non-zero but the Kbps estimate would be zero. > > I'm not sure what you mean. rtt and kbps should never be negative, e.g. Also, > both should probably have an upper bound as well, though I'm not sure what good > values would be. Maybe 5 minutes for rtt? Added DCHECKs. Also, added filters in NotifyDataReceived(). https://codereview.chromium.org/1144163008/diff/60001/net/base/network_qualit... File net/base/network_quality_estimator.h (right): https://codereview.chromium.org/1144163008/diff/60001/net/base/network_qualit... net/base/network_quality_estimator.h:51: bool ReadCachedNetworkQualityEstimate(); On 2015/06/01 23:21:10, bengr wrote: > On 2015/06/01 21:56:51, tbansal1 wrote: > > On 2015/06/01 20:39:34, bengr wrote: > > > You might want to bite the bullet now and make this interface asynchronous. > > You > > > will almost certainly need to do so if you expect to persist these cache > > > entries. > > > > This CL is complete in the current form. > > I would prefer to do it when doing the disk based caching. > > Acknowledged. Done. 
 ptal. thanks. 
 ptal. thanks. 
 https://codereview.chromium.org/1144163008/diff/140001/net/base/network_quali... File net/base/network_quality_estimator.cc (right): https://codereview.chromium.org/1144163008/diff/140001/net/base/network_quali... net/base/network_quality_estimator.cc:225: #if defined(OS_ANDROID) Could we have a NetworkQualityEstimatorAndroid that overrides this method? Maybe add a TODO. https://codereview.chromium.org/1144163008/diff/140001/net/base/network_quali... net/base/network_quality_estimator.cc:348: base::TimeTicks NetworkQualityEstimator::CachedNetworkQuality::GetLastUpdated() Can this be inlined in the .h and renamed last_update_time()? Rename the member variable last_update_time_ https://codereview.chromium.org/1144163008/diff/140001/net/base/network_quali... File net/base/network_quality_estimator.h (right): https://codereview.chromium.org/1144163008/diff/140001/net/base/network_quali... net/base/network_quality_estimator.h:70: // A network is uniquely identified by a combination of |connection_type_| Not always unique. name could be empty. 
 Sorry I didn't get around to doing a full pass today. I will on Monday. https://codereview.chromium.org/1144163008/diff/140001/net/base/network_quali... File net/base/network_quality_estimator.cc (right): https://codereview.chromium.org/1144163008/diff/140001/net/base/network_quali... net/base/network_quality_estimator.cc:226: case NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI: Erm...WIFI only on Android? https://codereview.chromium.org/1144163008/diff/140001/net/base/network_quali... net/base/network_quality_estimator.cc:234: #endif // OS_ANDROID Can't ChromeOS have cell connections? What about iOS? Heck, at some point, we may be getting these types on other platforms, too. 
 ptal. thanks. https://codereview.chromium.org/1144163008/diff/140001/net/base/network_quali... File net/base/network_quality_estimator.cc (right): https://codereview.chromium.org/1144163008/diff/140001/net/base/network_quali... net/base/network_quality_estimator.cc:225: #if defined(OS_ANDROID) On 2015/06/05 20:34:31, bengr wrote: > Could we have a NetworkQualityEstimatorAndroid that overrides this method? Maybe > add a TODO. Done. Added TODO https://codereview.chromium.org/1144163008/diff/140001/net/base/network_quali... net/base/network_quality_estimator.cc:226: case NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI: On 2015/06/05 20:37:21, mmenke wrote: > Erm...WIFI only on Android? Added Linux and ChromeOS. GetWiFiSSID() is only implemented on these 3 platforms. https://codereview.chromium.org/1144163008/diff/140001/net/base/network_quali... net/base/network_quality_estimator.cc:234: #endif // OS_ANDROID On 2015/06/05 20:37:20, mmenke wrote: > Can't ChromeOS have cell connections? What about iOS? Heck, at some point, we > may be getting these types on other platforms, too. AFAIK, GetTelephonyNetworkOperator() would compile only on Android. Is there some way to obtain the MCC/MNC for non Android platforms? Also, e.g., if the connection is cellular on iOS, this code will still do the caching. It will just be less inaccurate because the network name (MCC/MNC code) would be empty. Rearranged the code to make it more obvious. https://codereview.chromium.org/1144163008/diff/140001/net/base/network_quali... net/base/network_quality_estimator.cc:348: base::TimeTicks NetworkQualityEstimator::CachedNetworkQuality::GetLastUpdated() On 2015/06/05 20:34:31, bengr wrote: > Can this be inlined in the .h and renamed last_update_time()? Rename the member > variable last_update_time_ Done. https://codereview.chromium.org/1144163008/diff/140001/net/base/network_quali... File net/base/network_quality_estimator.h (right): https://codereview.chromium.org/1144163008/diff/140001/net/base/network_quali... net/base/network_quality_estimator.h:70: // A network is uniquely identified by a combination of |connection_type_| On 2015/06/05 20:34:31, bengr wrote: > Not always unique. name could be empty. I meant "This code uniquely identifies a network by..." because otherwise even if the name is non-empty, two completely different WiFi networks can have same name. 
 Mostly style nits. https://codereview.chromium.org/1144163008/diff/140001/net/base/network_quali... File net/base/network_quality_estimator.cc (right): https://codereview.chromium.org/1144163008/diff/140001/net/base/network_quali... net/base/network_quality_estimator.cc:234: #endif // OS_ANDROID On 2015/06/06 01:03:14, tbansal1 wrote: > On 2015/06/05 20:37:20, mmenke wrote: > > Can't ChromeOS have cell connections? What about iOS? Heck, at some point, > we > > may be getting these types on other platforms, too. > > AFAIK, GetTelephonyNetworkOperator() would compile only on Android. > Is there some way to obtain the MCC/MNC for non Android platforms? > > Also, e.g., if the connection is cellular on iOS, this code will still > do the caching. It will just be less inaccurate because the network > name (MCC/MNC code) would be empty. > > Rearranged the code to make it more obvious. There's not, but the old code defaulted to NOTREACHED() if we got NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI on a platform other than Android, which seemed to be a bug. https://codereview.chromium.org/1144163008/diff/160001/net/base/network_quali... File net/base/network_quality_estimator.cc (right): https://codereview.chromium.org/1144163008/diff/160001/net/base/network_quali... net/base/network_quality_estimator.cc:195: const std::string& network_name) { Suggest making UpdateCurrentNetworkName call a virtual GetCurrentNetworkName method instead, and override it in tests. That allows you to also validate we update the network internally on network changes, by simulating an NCN notification. https://codereview.chromium.org/1144163008/diff/160001/net/base/network_quali... net/base/network_quality_estimator.cc:216: // this method on Android platform. Is there a bug for this that we could link to, to give context? https://codereview.chromium.org/1144163008/diff/160001/net/base/network_quali... net/base/network_quality_estimator.cc:226: current_network_name_ = "ethernet"; I don't think this is needed - we're recording network type and name in the cache, right? https://codereview.chromium.org/1144163008/diff/160001/net/base/network_quali... net/base/network_quality_estimator.cc:237: current_network_name_ = android::GetTelephonyNetworkOperator(); Suggest a struct: struct NetworkID { ConnectionType type; std::string id; }; Having a string "id" as part of NetworkID is a little weird, but I think it's clearer than saying the "name" of a network is "ethernet" or the network operator name. Alternatively, could use prefixed strings ("wifi/" + GetWifiSSID(), "cell/" + GetTelephonyNetworkOperator()). Makes for simpler data structures, though does lose a bit in clarity. https://codereview.chromium.org/1144163008/diff/160001/net/base/network_quali... net/base/network_quality_estimator.cc:277: for (auto& network_quality : cached_network_quality_) { Why not just use an std::map? https://codereview.chromium.org/1144163008/diff/160001/net/base/network_quali... net/base/network_quality_estimator.cc:290: median_rtt)); Rather than duplicate this line, suggest you do: if (cached_network_quality_.size() >= kMaximumNetworkQualityCacheSize) { // Remove oldest entry here. } // Add new entry here, unconditionally. https://codereview.chromium.org/1144163008/diff/160001/net/base/network_quali... net/base/network_quality_estimator.cc:294: DCHECK_EQ(kMaximumNetworkQualityCacheSize, cached_network_quality_.size()); optional: Suggest a DCHECK_LE(kMaximumNetworkQualityCacheSize, cached_network_quality_.size()); at the start of this function instead. https://codereview.chromium.org/1144163008/diff/160001/net/base/network_quali... net/base/network_quality_estimator.cc:341: DCHECK_GE(median_rtt_, base::TimeDelta()); nit: DCHECKs to validate input are generally put at the start of methods. https://codereview.chromium.org/1144163008/diff/160001/net/base/network_quali... File net/base/network_quality_estimator.h (right): https://codereview.chromium.org/1144163008/diff/160001/net/base/network_quali... net/base/network_quality_estimator.h:71: // and |network_name_|. SSIDs are user-assigned, so unless GetWifiSSID() returns more than that, those aren't unique. Moreover, "ethernet" does not uniquely identify an ethernet network, and an empty string does not uniquely identify anything (On platforms we can't get an SSID on). https://codereview.chromium.org/1144163008/diff/160001/net/base/network_quali... net/base/network_quality_estimator.h:98: base::TimeDelta median_rtt_; Seems like we should just have a NetworkQuality object here. 
 Patchset #9 (id:180001) has been deleted 
 thanks for the comments. ptal. https://codereview.chromium.org/1144163008/diff/160001/net/base/network_quali... File net/base/network_quality_estimator.cc (right): https://codereview.chromium.org/1144163008/diff/160001/net/base/network_quali... net/base/network_quality_estimator.cc:195: const std::string& network_name) { On 2015/06/08 20:34:19, mmenke wrote: > Suggest making UpdateCurrentNetworkName call a virtual GetCurrentNetworkName > method instead, and override it in tests. That allows you to also validate we > update the network internally on network changes, by simulating an NCN > notification. Done. https://codereview.chromium.org/1144163008/diff/160001/net/base/network_quali... net/base/network_quality_estimator.cc:216: // this method on Android platform. On 2015/06/08 20:34:20, mmenke wrote: > Is there a bug for this that we could link to, to give context? Done. https://codereview.chromium.org/1144163008/diff/160001/net/base/network_quali... net/base/network_quality_estimator.cc:226: current_network_name_ = "ethernet"; On 2015/06/08 20:34:20, mmenke wrote: > I don't think this is needed - we're recording network type and name in the > cache, right? Yes, it was not really needed. https://codereview.chromium.org/1144163008/diff/160001/net/base/network_quali... net/base/network_quality_estimator.cc:237: current_network_name_ = android::GetTelephonyNetworkOperator(); On 2015/06/08 20:34:19, mmenke wrote: > Suggest a struct: > > struct NetworkID { > ConnectionType type; > std::string id; > }; > > Having a string "id" as part of NetworkID is a little weird, but I think it's > clearer than saying the "name" of a network is "ethernet" or the network > operator name. > > Alternatively, could use prefixed strings ("wifi/" + GetWifiSSID(), "cell/" + > GetTelephonyNetworkOperator()). Makes for simpler data structures, though does > lose a bit in clarity. Done. https://codereview.chromium.org/1144163008/diff/160001/net/base/network_quali... net/base/network_quality_estimator.cc:277: for (auto& network_quality : cached_network_quality_) { On 2015/06/08 20:34:20, mmenke wrote: > Why not just use an std::map? Did not do it before because I was not using struct NetworkID. Now, it makes more sense. Done. Unfortunately, this caused a lot of churn in the code. https://codereview.chromium.org/1144163008/diff/160001/net/base/network_quali... net/base/network_quality_estimator.cc:290: median_rtt)); On 2015/06/08 20:34:20, mmenke wrote: > Rather than duplicate this line, suggest you do: > > if (cached_network_quality_.size() >= kMaximumNetworkQualityCacheSize) { > // Remove oldest entry here. > } > > // Add new entry here, unconditionally. Done. https://codereview.chromium.org/1144163008/diff/160001/net/base/network_quali... net/base/network_quality_estimator.cc:294: DCHECK_EQ(kMaximumNetworkQualityCacheSize, cached_network_quality_.size()); On 2015/06/08 20:34:19, mmenke wrote: > optional: Suggest a DCHECK_LE(kMaximumNetworkQualityCacheSize, > cached_network_quality_.size()); at the start of this function instead. Done. https://codereview.chromium.org/1144163008/diff/160001/net/base/network_quali... net/base/network_quality_estimator.cc:341: DCHECK_GE(median_rtt_, base::TimeDelta()); On 2015/06/08 20:34:20, mmenke wrote: > nit: DCHECKs to validate input are generally put at the start of methods. Done. https://codereview.chromium.org/1144163008/diff/160001/net/base/network_quali... File net/base/network_quality_estimator.h (right): https://codereview.chromium.org/1144163008/diff/160001/net/base/network_quali... net/base/network_quality_estimator.h:71: // and |network_name_|. On 2015/06/08 20:34:21, mmenke wrote: > SSIDs are user-assigned, so unless GetWifiSSID() returns more than that, those > aren't unique. > > Moreover, "ethernet" does not uniquely identify an ethernet network, and an > empty string does not uniquely identify anything (On platforms we can't get an > SSID on). Agreed. Added more comments to make it clearer that "unique" is only from the perspective of this algorithm. https://codereview.chromium.org/1144163008/diff/160001/net/base/network_quali... net/base/network_quality_estimator.h:98: base::TimeDelta median_rtt_; On 2015/06/08 20:34:21, mmenke wrote: > Seems like we should just have a NetworkQuality object here. Done. 
 https://codereview.chromium.org/1144163008/diff/200001/net/base/network_quali... File net/base/network_quality_estimator.cc (right): https://codereview.chromium.org/1144163008/diff/200001/net/base/network_quali... net/base/network_quality_estimator.cc:179: CacheNetworkQualityEstimate(); Should we verify that the network actually changed before caching anything? https://codereview.chromium.org/1144163008/diff/200001/net/base/network_quali... File net/base/network_quality_estimator_unittest.cc (right): https://codereview.chromium.org/1144163008/diff/200001/net/base/network_quali... net/base/network_quality_estimator_unittest.cc:102: class TestNetworkQualityEstimator : public NetworkQualityEstimator { This should be in an anonymous namespace. May be able to put all the test in it as well. https://codereview.chromium.org/1144163008/diff/200001/net/base/network_quali... net/base/network_quality_estimator_unittest.cc:104: TestNetworkQualityEstimator() : current_network_name_(std::string()) {} nit: No need to explicitly initialize current_network_name_ https://codereview.chromium.org/1144163008/diff/200001/net/base/network_quali... net/base/network_quality_estimator_unittest.cc:118: // NetworkQualityEstimator implementation that returns the overriden network overriden -> overridden https://codereview.chromium.org/1144163008/diff/200001/net/base/network_quali... net/base/network_quality_estimator_unittest.cc:133: size_t cache_size = 1; expected_cache_size https://codereview.chromium.org/1144163008/diff/200001/net/base/network_quali... net/base/network_quality_estimator_unittest.cc:136: NetworkChangeNotifier::ConnectionType::CONNECTION_2G); Think this test would be much clearer as a single method. Something like: estimator.SimulateNetworkChangeTo(type, name); And get rid of SetCurrentNetworkName. https://codereview.chromium.org/1144163008/diff/200001/net/base/network_quali... net/base/network_quality_estimator_unittest.cc:137: // Cache entry will be added for (NONE, "") Suggest putting this above the line that actually adds a line. https://codereview.chromium.org/1144163008/diff/200001/net/base/network_quali... net/base/network_quality_estimator_unittest.cc:142: // not change with multiple iterations of the loop). Not true - the second iteration adds an entry. I think this test is sufficiently confusing that you should just unroll the first two loop iterations. https://codereview.chromium.org/1144163008/diff/200001/net/base/network_quali... net/base/network_quality_estimator_unittest.cc:157: NetworkChangeNotifier::ConnectionType::CONNECTION_2G); Should also make a test-1 connection with type 3G, and make sure we correctly distinguish the two. https://codereview.chromium.org/1144163008/diff/200001/net/base/network_quali... net/base/network_quality_estimator_unittest.cc:162: estimator.SetCurrentNetworkName("test-1"); BUG: This doesn't actually change current_network_id_. Need a network change notification, too. https://codereview.chromium.org/1144163008/diff/200001/net/base/network_quali... net/base/network_quality_estimator_unittest.cc:165: EXPECT_TRUE(estimator.ReadCachedNetworkQualityEstimate()); This seems like a very weak check that something was reached. I'd really like to store different information for test-1 and test-2, and see if we can retrieve it. https://codereview.chromium.org/1144163008/diff/200001/net/base/network_quali... net/base/network_quality_estimator_unittest.cc:188: } Suggest exposing NetworkQualityEstimator::kMaximumNetworkQualityCacheSize, and using that explicitly. 
 thanks for the comments. Tests look much cleaner now. ptal. https://codereview.chromium.org/1144163008/diff/200001/net/base/network_quali... File net/base/network_quality_estimator.cc (right): https://codereview.chromium.org/1144163008/diff/200001/net/base/network_quali... net/base/network_quality_estimator.cc:179: CacheNetworkQualityEstimate(); On 2015/06/09 19:48:07, mmenke wrote: > Should we verify that the network actually changed before caching anything? I think that would complicate the logic without much benefit. Right now, either both events (caching and clearing of NQE local state) happen or neither of them. If we decouple them, that means: we clear local state but do not write to cache. In this case, we still need to add an entry to the circular ring buffer (deque) to seed the estimator. This would require completely different logic than ReadCachedNQE(). I think when the device goes from 1 network to another, there is an intermediate notification with ConnectionType of None. So, it seems it would be very rare that OnConnectionTypeChanged() is called but there is no change in ConnectionType. WDYT? https://codereview.chromium.org/1144163008/diff/200001/net/base/network_quali... File net/base/network_quality_estimator_unittest.cc (right): https://codereview.chromium.org/1144163008/diff/200001/net/base/network_quali... net/base/network_quality_estimator_unittest.cc:102: class TestNetworkQualityEstimator : public NetworkQualityEstimator { On 2015/06/09 19:48:07, mmenke wrote: > This should be in an anonymous namespace. May be able to put all the test in it > as well. Moved to anon namespace. Not sure what test can I put there? https://codereview.chromium.org/1144163008/diff/200001/net/base/network_quali... net/base/network_quality_estimator_unittest.cc:104: TestNetworkQualityEstimator() : current_network_name_(std::string()) {} On 2015/06/09 19:48:07, mmenke wrote: > nit: No need to explicitly initialize current_network_name_ Done. https://codereview.chromium.org/1144163008/diff/200001/net/base/network_quali... net/base/network_quality_estimator_unittest.cc:118: // NetworkQualityEstimator implementation that returns the overriden network On 2015/06/09 19:48:08, mmenke wrote: > overriden -> overridden Done. https://codereview.chromium.org/1144163008/diff/200001/net/base/network_quali... net/base/network_quality_estimator_unittest.cc:133: size_t cache_size = 1; On 2015/06/09 19:48:07, mmenke wrote: > expected_cache_size Done. https://codereview.chromium.org/1144163008/diff/200001/net/base/network_quali... net/base/network_quality_estimator_unittest.cc:136: NetworkChangeNotifier::ConnectionType::CONNECTION_2G); On 2015/06/09 19:48:07, mmenke wrote: > Think this test would be much clearer as a single method. Something like: > > estimator.SimulateNetworkChangeTo(type, name); > > And get rid of SetCurrentNetworkName. Thanks, this helped a lot. https://codereview.chromium.org/1144163008/diff/200001/net/base/network_quali... net/base/network_quality_estimator_unittest.cc:137: // Cache entry will be added for (NONE, "") On 2015/06/09 19:48:07, mmenke wrote: > Suggest putting this above the line that actually adds a line. Done. https://codereview.chromium.org/1144163008/diff/200001/net/base/network_quali... net/base/network_quality_estimator_unittest.cc:142: // not change with multiple iterations of the loop). On 2015/06/09 19:48:08, mmenke wrote: > Not true - the second iteration adds an entry. > > I think this test is sufficiently confusing that you should just unroll the > first two loop iterations. Tried to make it simpler. Removed the for loop. https://codereview.chromium.org/1144163008/diff/200001/net/base/network_quali... net/base/network_quality_estimator_unittest.cc:157: NetworkChangeNotifier::ConnectionType::CONNECTION_2G); On 2015/06/09 19:48:08, mmenke wrote: > Should also make a test-1 connection with type 3G, and make sure we correctly > distinguish the two. Done. https://codereview.chromium.org/1144163008/diff/200001/net/base/network_quali... net/base/network_quality_estimator_unittest.cc:162: estimator.SetCurrentNetworkName("test-1"); On 2015/06/09 19:48:07, mmenke wrote: > BUG: This doesn't actually change current_network_id_. Need a network change > notification, too. Fixed. https://codereview.chromium.org/1144163008/diff/200001/net/base/network_quali... net/base/network_quality_estimator_unittest.cc:165: EXPECT_TRUE(estimator.ReadCachedNetworkQualityEstimate()); On 2015/06/09 19:48:07, mmenke wrote: > This seems like a very weak check that something was reached. I'd really like > to store different information for test-1 and test-2, and see if we can retrieve > it. Done. https://codereview.chromium.org/1144163008/diff/200001/net/base/network_quali... net/base/network_quality_estimator_unittest.cc:188: } On 2015/06/09 19:48:07, mmenke wrote: > Suggest exposing NetworkQualityEstimator::kMaximumNetworkQualityCacheSize, and > using that explicitly. Done. 
 https://codereview.chromium.org/1144163008/diff/220001/net/base/network_quali... File net/base/network_quality_estimator.cc (right): https://codereview.chromium.org/1144163008/diff/220001/net/base/network_quali... net/base/network_quality_estimator.cc:206: // that overrides this method on Android platform. on -> on the https://codereview.chromium.org/1144163008/diff/220001/net/base/network_quali... net/base/network_quality_estimator.cc:213: return std::string(); Can't you remove this line? https://codereview.chromium.org/1144163008/diff/220001/net/base/network_quali... net/base/network_quality_estimator.cc:227: return std::string(); Would it make sense to put this and the one on line 220 in #else clauses? I don't know if any compilers will complain about having a return that can't be reached. https://codereview.chromium.org/1144163008/diff/220001/net/base/network_quali... net/base/network_quality_estimator.cc:243: // Add UMA to record how frequently match happens. match happens -> matches happen https://codereview.chromium.org/1144163008/diff/220001/net/base/network_quali... net/base/network_quality_estimator.cc:244: // int64 median_kbps = network_quality.median_kbps; Why do you have this commented out code? https://codereview.chromium.org/1144163008/diff/220001/net/base/network_quali... net/base/network_quality_estimator.cc:261: // TODO(tbansal): Following variables should be initialized using the median Following -> The following by NetworkQualityEstimator -> by the NetworkQualityEstimator https://codereview.chromium.org/1144163008/diff/220001/net/base/network_quali... net/base/network_quality_estimator.cc:313: network_quality_.fastest_rtt = median_rtt; Can you just use a NetworkQuality constructor here? https://codereview.chromium.org/1144163008/diff/220001/net/base/network_quali... File net/base/network_quality_estimator.h (right): https://codereview.chromium.org/1144163008/diff/220001/net/base/network_quali... net/base/network_quality_estimator.h:71: // same name (e.g., different Wi-Fi networks with same SSID). same name -> the same name Also, could you use BSSID in addition to SSID to disambiguate? https://codereview.chromium.org/1144163008/diff/220001/net/base/network_quali... net/base/network_quality_estimator.h:121: typedef std::map<NetworkID, scoped_ptr<CachedNetworkQuality>> CachedQualities; Suggest renaming to CachedNetworkQualities. https://codereview.chromium.org/1144163008/diff/220001/net/base/network_quali... net/base/network_quality_estimator.h:148: // The MCC/MNC code of the cellular carrier if the device is connected to a The -> the https://codereview.chromium.org/1144163008/diff/220001/net/base/network_quali... net/base/network_quality_estimator.h:155: // Write the estimated quality of the current network to the cache. Write -> Writes https://codereview.chromium.org/1144163008/diff/220001/net/base/network_quali... net/base/network_quality_estimator.h:181: // NetworkID of the current network. NetworkID -> ID https://codereview.chromium.org/1144163008/diff/220001/net/base/network_quali... File net/base/network_quality_estimator_unittest.cc (right): https://codereview.chromium.org/1144163008/diff/220001/net/base/network_quali... net/base/network_quality_estimator_unittest.cc:46: // id (instead of invoking platform APIs). id -> ID https://codereview.chromium.org/1144163008/diff/220001/net/base/network_quali... net/base/network_quality_estimator_unittest.cc:47: std::string GetCurrentNetworkName() const override { Return a const&? 
 Thanks for the comments. ptal. https://codereview.chromium.org/1144163008/diff/220001/net/base/network_quali... File net/base/network_quality_estimator.cc (right): https://codereview.chromium.org/1144163008/diff/220001/net/base/network_quali... net/base/network_quality_estimator.cc:206: // that overrides this method on Android platform. On 2015/06/11 00:02:27, bengr wrote: > on -> on the Done. https://codereview.chromium.org/1144163008/diff/220001/net/base/network_quali... net/base/network_quality_estimator.cc:213: return std::string(); On 2015/06/11 00:02:27, bengr wrote: > Can't you remove this line? Done. https://codereview.chromium.org/1144163008/diff/220001/net/base/network_quali... net/base/network_quality_estimator.cc:227: return std::string(); On 2015/06/11 00:02:27, bengr wrote: > Would it make sense to put this and the one on line 220 in #else clauses? I > don't know if any compilers will complain about having a return that can't be > reached. Done. https://codereview.chromium.org/1144163008/diff/220001/net/base/network_quali... net/base/network_quality_estimator.cc:243: // Add UMA to record how frequently match happens. On 2015/06/11 00:02:27, bengr wrote: > match happens -> matches happen Done. https://codereview.chromium.org/1144163008/diff/220001/net/base/network_quali... net/base/network_quality_estimator.cc:244: // int64 median_kbps = network_quality.median_kbps; On 2015/06/11 00:02:28, bengr wrote: > Why do you have this commented out code? Removed. https://codereview.chromium.org/1144163008/diff/220001/net/base/network_quali... net/base/network_quality_estimator.cc:261: // TODO(tbansal): Following variables should be initialized using the median On 2015/06/11 00:02:28, bengr wrote: > Following -> The following > by NetworkQualityEstimator -> by the NetworkQualityEstimator Done. https://codereview.chromium.org/1144163008/diff/220001/net/base/network_quali... net/base/network_quality_estimator.cc:313: network_quality_.fastest_rtt = median_rtt; On 2015/06/11 00:02:27, bengr wrote: > Can you just use a NetworkQuality constructor here? Done. https://codereview.chromium.org/1144163008/diff/220001/net/base/network_quali... File net/base/network_quality_estimator.h (right): https://codereview.chromium.org/1144163008/diff/220001/net/base/network_quali... net/base/network_quality_estimator.h:71: // same name (e.g., different Wi-Fi networks with same SSID). On 2015/06/11 00:02:28, bengr wrote: > same name -> the same name > > Also, could you use BSSID in addition to SSID to disambiguate? I believe BSSID is currently exposed only on chromeOS. This is exposed by Android Java APIs but there is nothing in chromium that exposes it to native code. I am not even sure if it is worth indexing this by BSSID. It might actually cause harm in the sense that we might think that a network is different from a previously seen network (and not use the cached estimates), whereas in fact the performance of the two networks is very similar. https://codereview.chromium.org/1144163008/diff/220001/net/base/network_quali... net/base/network_quality_estimator.h:121: typedef std::map<NetworkID, scoped_ptr<CachedNetworkQuality>> CachedQualities; On 2015/06/11 00:02:28, bengr wrote: > Suggest renaming to CachedNetworkQualities. Done. https://codereview.chromium.org/1144163008/diff/220001/net/base/network_quali... net/base/network_quality_estimator.h:148: // The MCC/MNC code of the cellular carrier if the device is connected to a On 2015/06/11 00:02:28, bengr wrote: > The -> the Done. https://codereview.chromium.org/1144163008/diff/220001/net/base/network_quali... net/base/network_quality_estimator.h:155: // Write the estimated quality of the current network to the cache. On 2015/06/11 00:02:28, bengr wrote: > Write -> Writes Done. https://codereview.chromium.org/1144163008/diff/220001/net/base/network_quali... net/base/network_quality_estimator.h:181: // NetworkID of the current network. On 2015/06/11 00:02:28, bengr wrote: > NetworkID -> ID Done. https://codereview.chromium.org/1144163008/diff/220001/net/base/network_quali... File net/base/network_quality_estimator_unittest.cc (right): https://codereview.chromium.org/1144163008/diff/220001/net/base/network_quali... net/base/network_quality_estimator_unittest.cc:46: // id (instead of invoking platform APIs). On 2015/06/11 00:02:28, bengr wrote: > id -> ID "id" may be okay because this refers to NetworkID.id Not done. https://codereview.chromium.org/1144163008/diff/220001/net/base/network_quali... net/base/network_quality_estimator_unittest.cc:47: std::string GetCurrentNetworkName() const override { On 2015/06/11 00:02:28, bengr wrote: > Return a const&? Not possible. It has to match the signature of overridden function which can't have const std::string& return type. 
 Thanks for the comments. ptal. 
 ping. thanks. 
 lgtm with one variable renaming nit. https://codereview.chromium.org/1144163008/diff/220001/net/base/network_quali... File net/base/network_quality_estimator.h (right): https://codereview.chromium.org/1144163008/diff/220001/net/base/network_quali... net/base/network_quality_estimator.h:71: // same name (e.g., different Wi-Fi networks with same SSID). On 2015/06/11 02:20:23, tbansal1 wrote: > On 2015/06/11 00:02:28, bengr wrote: > > same name -> the same name > > > > Also, could you use BSSID in addition to SSID to disambiguate? > > I believe BSSID is currently exposed only on chromeOS. This is exposed by > Android Java APIs but there is nothing in chromium that exposes it to native > code. > > I am not even sure if it is worth indexing this by BSSID. It might > actually cause harm in the sense that we might think that a network > is different from a previously seen network (and not use the cached > estimates), whereas in fact the performance of the two networks is very similar. Acknowledged. https://codereview.chromium.org/1144163008/diff/220001/net/base/network_quali... File net/base/network_quality_estimator_unittest.cc (right): https://codereview.chromium.org/1144163008/diff/220001/net/base/network_quali... net/base/network_quality_estimator_unittest.cc:46: // id (instead of invoking platform APIs). On 2015/06/11 02:20:23, tbansal1 wrote: > On 2015/06/11 00:02:28, bengr wrote: > > id -> ID > > "id" may be okay because this refers to NetworkID.id > > Not done. Acknowledged. https://codereview.chromium.org/1144163008/diff/240001/net/base/network_quali... File net/base/network_quality_estimator.h (right): https://codereview.chromium.org/1144163008/diff/240001/net/base/network_quali... net/base/network_quality_estimator.h:174: CachedNetworkQualities cached_network_quality_; cached_network_qualities_ 
 Patchset #12 (id:260001) has been deleted 
 rebased and cleaned up, ptal. thanks. 
 Patchset #13 (id:300001) has been deleted 
 rebased again. ptal. 
 On 2015/05/28 15:25:03, mmenke wrote: > Some nits...I'll defer to Paul on this review. Do you want me to take a look? you seem to be making plenty of comments as it is. 
 On 2015/06/16 17:55:38, pauljensen wrote: > On 2015/05/28 15:25:03, mmenke wrote: > > Some nits...I'll defer to Paul on this review. > > Do you want me to take a look? you seem to be making plenty of comments as it > is. Please do, I think we're best off if one person does these review, and there are enough of them that I don't have the time - a lot of reviews these past couple weeks. 
 In commit description: Change this: This is the first step towards preserving network quality across session restarts. To this: This is the first step towards preserving network quality estimates across browser session restarts. So it doesn't sound like we're directly affecting network quality. Change this: User may hop between different networks within the same Chrome session To this: User may switch between different network connections within the same brwoser session Avoid "hop" as it has network significance. Change "CL" to "change" Change this: there is a change in the network To this: when the device switches networks So it doesn't sound like this is effected by changes in network-internal configuration 
 https://codereview.chromium.org/1144163008/diff/320001/net/base/network_quali... File net/base/network_quality_estimator.cc (right): https://codereview.chromium.org/1144163008/diff/320001/net/base/network_quali... net/base/network_quality_estimator.cc:33: const size_t NetworkQualityEstimator::kMaximumNetworkQualityCacheSize = 10; Please add a comment like this or preferably address the issue: This limit should not be increased unless the logic for removing the oldest cache entry is rewritten to use a doubly-linked-list LRU queue. As it stands now, your logic to purge the oldest entry makes adding one entry to the cache O(n) where n is kMaximumNetworkQualityCacheSize, and filling the cache is O(n^2). Here's a little example of a doubly-linked-list LRU queue and map: http://stackoverflow.com/questions/2057424/lru-implementation-in-production-code If you're going to add the comment, maybe adding a static_assert that checks kMaximumNetworkQualityCacheSize <= 10 is appropriate next to the other static_assert for kMaximumNetworkQualityCacheSize and putting the comment there is a good idea. https://codereview.chromium.org/1144163008/diff/320001/net/base/network_quali... net/base/network_quality_estimator.cc:318: switch (current_network_id_.type) { This is racy. You're using a potentially old value (current_network_id_.type) and assuming it's current. A similar race caused crashes in the NetworkChangeNotifierAutoDetect, see crrev.com/844146e. I don't know of a great solution that doesn't require a fair bit of work. I'd prefer we changed GetCurrentNetworkName to GetCurrentNetworkID. This will avoid the split initialization on lines 45 and 54, and at least reduce the race to one function making it easier to fix later. You could do something really ugly like: do { type = getCurrentType() if (type == wifi) id = GetWifiSSID(); } while (type != getCurrentType()) https://codereview.chromium.org/1144163008/diff/320001/net/base/network_quali... net/base/network_quality_estimator.cc:328: return std::string(); Does this mean every WiFi network will match every other WiFi network in the cache? Please fix this. https://codereview.chromium.org/1144163008/diff/320001/net/base/network_quali... File net/base/network_quality_estimator.h (right): https://codereview.chromium.org/1144163008/diff/320001/net/base/network_quali... net/base/network_quality_estimator.h:177: typedef std::map<NetworkID, scoped_ptr<CachedNetworkQuality>> I don't see an ordered traversal and assume we'll never need one, so please add a comment or preferably use a hash table: This does not use a unordered_map or hash_map for code simplicity (key just implements operator<, rather than hash and equality) and because the map is tiny. https://codereview.chromium.org/1144163008/diff/320001/net/base/network_quali... net/base/network_quality_estimator.h:209: size_t GetMaximumObservationBufferSizeForTests() const; Can we remove this and have the tests compare to the internal sizes? https://codereview.chromium.org/1144163008/diff/320001/net/base/network_quali... net/base/network_quality_estimator.h:213: bool VerifyBufferSizeForTests(size_t expected_size) const; Can we remove this and have the tests compare to the internal sizes? https://codereview.chromium.org/1144163008/diff/320001/net/base/network_quali... net/base/network_quality_estimator.h:216: // WiFi SSID (if the user is connected to a WiFi access point and the SSID can you add " - " before "WiFi" on this line and before "the" on line 218 so it's easier to read, and indent lines 217 and 219. 
 https://codereview.chromium.org/1144163008/diff/320001/net/base/network_quali... File net/base/network_quality_estimator.h (right): https://codereview.chromium.org/1144163008/diff/320001/net/base/network_quali... net/base/network_quality_estimator.h:124: base::TimeTicks last_update_time() const { return last_update_time_; } Slightly nicer encapsulation if we replaced this function with a "bool older_than(const CachedNetworkQuality&)" function. 
 https://codereview.chromium.org/1144163008/diff/320001/net/base/network_quali... File net/base/network_quality_estimator.cc (right): https://codereview.chromium.org/1144163008/diff/320001/net/base/network_quali... net/base/network_quality_estimator.cc:33: const size_t NetworkQualityEstimator::kMaximumNetworkQualityCacheSize = 10; On 2015/06/17 14:19:15, pauljensen wrote: > Please add a comment like this or preferably address the issue: > > This limit should not be increased unless the logic for removing the oldest > cache entry is rewritten to use a doubly-linked-list LRU queue. > > As it stands now, your logic to purge the oldest entry makes adding one entry to > the cache O(n) where n is kMaximumNetworkQualityCacheSize, and filling the cache > is O(n^2). > Here's a little example of a doubly-linked-list LRU queue and map: > http://stackoverflow.com/questions/2057424/lru-implementation-in-production-code > If you're going to add the comment, maybe adding a static_assert that checks > kMaximumNetworkQualityCacheSize <= 10 is appropriate next to the other > static_assert for kMaximumNetworkQualityCacheSize and putting the comment there > is a good idea. Another benefit to switching to an LRU queue is that we can remove the reliance on comparing TimeTicks::Now() values. Matt mentioned horror stories about different processor cores exhibiting Now() values significantly out of skew from other cores. Probably doesn't come in to play for your code (single threaded, hopefully large Now() separation) but good future-proofing. 
 Thanks for the comments. ptal. Unfortunately, changing virtual std::string GetCurrentNetworkName() const; to virtual NetworkID GetCurrentNetworkID() const; required making changes in several other places. https://codereview.chromium.org/1144163008/diff/320001/net/base/network_quali... File net/base/network_quality_estimator.cc (right): https://codereview.chromium.org/1144163008/diff/320001/net/base/network_quali... net/base/network_quality_estimator.cc:33: const size_t NetworkQualityEstimator::kMaximumNetworkQualityCacheSize = 10; On 2015/06/17 14:19:15, pauljensen wrote: > Please add a comment like this or preferably address the issue: > > This limit should not be increased unless the logic for removing the oldest > cache entry is rewritten to use a doubly-linked-list LRU queue. Done. > > As it stands now, your logic to purge the oldest entry makes adding one entry to > the cache O(n) where n is kMaximumNetworkQualityCacheSize, and filling the cache > is O(n^2). > Here's a little example of a doubly-linked-list LRU queue and map: > http://stackoverflow.com/questions/2057424/lru-implementation-in-production-code Yes, I thought of using map + deque, but I suspected that code complexity is not worth it (unless the combined data structure is already available somewhere in Chromium). Further, this happens only on network change, which is rare and already too slow (just something to note when considering trade-offs). Also, IIUC, complexity of filling cache is not really important because it happens over a long period of time (e.g, on average, device may take at least a few hours to switch over 10 different networks). > If you're going to add the comment, maybe adding a static_assert that checks > kMaximumNetworkQualityCacheSize <= 10 is appropriate next to the other > static_assert for kMaximumNetworkQualityCacheSize and putting the comment there > is a good idea. Done https://codereview.chromium.org/1144163008/diff/320001/net/base/network_quali... net/base/network_quality_estimator.cc:33: const size_t NetworkQualityEstimator::kMaximumNetworkQualityCacheSize = 10; On 2015/06/17 14:32:45, pauljensen wrote: > On 2015/06/17 14:19:15, pauljensen wrote: > > Please add a comment like this or preferably address the issue: > > > > This limit should not be increased unless the logic for removing the oldest > > cache entry is rewritten to use a doubly-linked-list LRU queue. > > > > As it stands now, your logic to purge the oldest entry makes adding one entry > to > > the cache O(n) where n is kMaximumNetworkQualityCacheSize, and filling the > cache > > is O(n^2). > > Here's a little example of a doubly-linked-list LRU queue and map: > > > http://stackoverflow.com/questions/2057424/lru-implementation-in-production-code > > If you're going to add the comment, maybe adding a static_assert that checks > > kMaximumNetworkQualityCacheSize <= 10 is appropriate next to the other > > static_assert for kMaximumNetworkQualityCacheSize and putting the comment > there > > is a good idea. > > Another benefit to switching to an LRU queue is that we can remove the reliance > on comparing TimeTicks::Now() values. Matt mentioned horror stories about > different processor cores exhibiting Now() values significantly out of skew from > other cores. Probably doesn't come in to play for your code (single threaded, > hopefully large Now() separation) but good future-proofing. Thats a valid point but I think here for some reason, if a recent entry is evicted (instead of the oldest one), it would still be okay. This cache is already best effort and probably code simplicity trumps slightly more accuracy that we can achieve by using double linked list + map. WDYT? I remember Ben once suggesting that I should just randomly remove some entry and don't even keep timestamps. https://codereview.chromium.org/1144163008/diff/320001/net/base/network_quali... net/base/network_quality_estimator.cc:318: switch (current_network_id_.type) { On 2015/06/17 14:19:15, pauljensen wrote: > This is racy. You're using a potentially old value (current_network_id_.type) > and assuming it's current. A similar race caused crashes in the > NetworkChangeNotifierAutoDetect, see crrev.com/844146e. > I don't know of a great solution that doesn't require a fair bit of work. > I'd prefer we changed GetCurrentNetworkName to GetCurrentNetworkID. This will > avoid the split initialization on lines 45 and 54, and at least reduce the race > to one function making it easier to fix later. > You could do something really ugly like: > do { > type = getCurrentType() > if (type == wifi) id = GetWifiSSID(); > } while (type != getCurrentType()) Thanks for catching this. I made the change but this required making changes at several other places. Done. https://codereview.chromium.org/1144163008/diff/320001/net/base/network_quali... net/base/network_quality_estimator.cc:328: return std::string(); On 2015/06/17 14:19:15, pauljensen wrote: > Does this mean every WiFi network will match every other WiFi network in the > cache? Please fix this. Yes, it does mean that on unsupported OSes. My previous logic was to not cache if the SSID is unavailable. However, we had a discussion where we weighed the pros/cons: Argument was that the slightly inaccurate value is better than no value at all. Slightly inaccurate because of the hypothesis that it is likely that users are always on slow Wi-Fi networks or always on fast Wi-Fi networks. https://codereview.chromium.org/1144163008/diff/320001/net/base/network_quali... File net/base/network_quality_estimator.h (right): https://codereview.chromium.org/1144163008/diff/320001/net/base/network_quali... net/base/network_quality_estimator.h:124: base::TimeTicks last_update_time() const { return last_update_time_; } On 2015/06/17 14:23:26, pauljensen wrote: > Slightly nicer encapsulation if we replaced this function with a "bool > older_than(const CachedNetworkQuality&)" function. Done. https://codereview.chromium.org/1144163008/diff/320001/net/base/network_quali... net/base/network_quality_estimator.h:177: typedef std::map<NetworkID, scoped_ptr<CachedNetworkQuality>> On 2015/06/17 14:19:15, pauljensen wrote: > I don't see an ordered traversal and assume we'll never need one, so please add > a comment or preferably use a hash table: > > This does not use a unordered_map or hash_map for code simplicity (key just > implements operator<, rather than hash and equality) and because the map is > tiny. Done. https://codereview.chromium.org/1144163008/diff/320001/net/base/network_quali... net/base/network_quality_estimator.h:209: size_t GetMaximumObservationBufferSizeForTests() const; On 2015/06/17 14:19:15, pauljensen wrote: > Can we remove this and have the tests compare to the internal sizes? Right now kMaximumObservationsBufferSize is defined in the cc file (because its type is size_t which can't be defined in .h). There is no way for the tests to access it without going through the function. So, still keeping this function. https://codereview.chromium.org/1144163008/diff/320001/net/base/network_quali... net/base/network_quality_estimator.h:213: bool VerifyBufferSizeForTests(size_t expected_size) const; On 2015/06/17 14:19:15, pauljensen wrote: > Can we remove this and have the tests compare to the internal sizes? Removed this function but had to add 2 more functions. It seems that I can't call estimator.kbps_observations_.Size() in the test code directly. It gives linking error on windows (it does work on all other platforms): http://build.chromium.org/p/tryserver.chromium.win/builders/win_chromium_comp.... I fixed the linking error by https://codereview.chromium.org/1164713004/diff2/380001:400001/net/base/netwo.... https://codereview.chromium.org/1144163008/diff/320001/net/base/network_quali... net/base/network_quality_estimator.h:216: // WiFi SSID (if the user is connected to a WiFi access point and the SSID On 2015/06/17 14:19:15, pauljensen wrote: > can you add " - " before "WiFi" on this line and before "the" on line 218 so > it's easier to read, and indent lines 217 and 219. Done. 
 https://codereview.chromium.org/1144163008/diff/320001/net/base/network_quali... File net/base/network_quality_estimator.cc (right): https://codereview.chromium.org/1144163008/diff/320001/net/base/network_quali... net/base/network_quality_estimator.cc:328: return std::string(); On 2015/06/17 21:18:46, tbansal1 wrote: > On 2015/06/17 14:19:15, pauljensen wrote: > > Does this mean every WiFi network will match every other WiFi network in the > > cache? Please fix this. > > Yes, it does mean that on unsupported OSes. My previous logic was to not cache > if the SSID is unavailable. However, we had a discussion where we weighed the > pros/cons: Argument was that the slightly inaccurate value is better than no > value at all. Slightly inaccurate because of the hypothesis that it is likely > that users are always on slow Wi-Fi networks or always on fast Wi-Fi networks. I don't think I agree with that. We already have logic to indicate when there is no estimate available, I think we should use it in this case. I don't think one Wi-Fi's quality gives much information about another Wi-Fi's quality. When someone changes Wi-Fi networks, they generally do so because one is significantly better than the other, the O/S's Wi-Fi logic generally has high hysteresis for changing APs. If this becomes a big problem, it shouldn't be too hard to implement GetWifiSSID() for windows. https://codereview.chromium.org/1144163008/diff/340001/net/base/network_quali... File net/base/network_quality_estimator.cc (right): https://codereview.chromium.org/1144163008/diff/340001/net/base/network_quali... net/base/network_quality_estimator.cc:355: // Due to race, it is possible that the connection type changed between when Remove "Due to race, " https://codereview.chromium.org/1144163008/diff/340001/net/base/network_quali... net/base/network_quality_estimator.cc:356: // GetCurrentConnectionType() was read and when network name was read. read->called https://codereview.chromium.org/1144163008/diff/340001/net/base/network_quali... net/base/network_quality_estimator.cc:356: // GetCurrentConnectionType() was read and when network name was read. network->the network https://codereview.chromium.org/1144163008/diff/340001/net/base/network_quali... net/base/network_quality_estimator.cc:357: // Check if that happened and retry. Mention that this isn't perfect but should catch the majority of cases, and this is just an estimate anyhow. https://codereview.chromium.org/1144163008/diff/340001/net/base/network_quali... net/base/network_quality_estimator.cc:359: return GetCurrentNetworkID(); Please use a loop rather than recursion. Waiting a long time is better than crashing quickly from stack overflow. https://codereview.chromium.org/1144163008/diff/340001/net/base/network_quali... File net/base/network_quality_estimator.h (right): https://codereview.chromium.org/1144163008/diff/340001/net/base/network_quali... net/base/network_quality_estimator.h:55: protected: Is this protected (rather than private) only for testing purposes? If so, add a comment. 
 Patchset #15 (id:360001) has been deleted 
 Patchset #15 (id:380001) has been deleted 
 ptal, thanks. https://codereview.chromium.org/1144163008/diff/320001/net/base/network_quali... File net/base/network_quality_estimator.cc (right): https://codereview.chromium.org/1144163008/diff/320001/net/base/network_quali... net/base/network_quality_estimator.cc:328: return std::string(); On 2015/06/18 16:20:25, pauljensen wrote: > On 2015/06/17 21:18:46, tbansal1 wrote: > > On 2015/06/17 14:19:15, pauljensen wrote: > > > Does this mean every WiFi network will match every other WiFi network in the > > > cache? Please fix this. > > > > Yes, it does mean that on unsupported OSes. My previous logic was to not cache > > if the SSID is unavailable. However, we had a discussion where we weighed the > > pros/cons: Argument was that the slightly inaccurate value is better than no > > value at all. Slightly inaccurate because of the hypothesis that it is likely > > that users are always on slow Wi-Fi networks or always on fast Wi-Fi networks. > > I don't think I agree with that. We already have logic to indicate when there > is no estimate available, I think we should use it in this case. I don't think > one Wi-Fi's quality gives much information about another Wi-Fi's quality. When > someone changes Wi-Fi networks, they generally do so because one is > significantly better than the other, the O/S's Wi-Fi logic generally has high > hysteresis for changing APs. > If this becomes a big problem, it shouldn't be too hard to implement > GetWifiSSID() for windows. I don't think I feel strongly either way (especially since I do not have any data to backup either approach). Removed read/write to cache if the network name is unavailable. Also, added test. https://codereview.chromium.org/1144163008/diff/340001/net/base/network_quali... File net/base/network_quality_estimator.cc (right): https://codereview.chromium.org/1144163008/diff/340001/net/base/network_quali... net/base/network_quality_estimator.cc:355: // Due to race, it is possible that the connection type changed between when On 2015/06/18 16:20:26, pauljensen wrote: > Remove "Due to race, " Done. https://codereview.chromium.org/1144163008/diff/340001/net/base/network_quali... net/base/network_quality_estimator.cc:356: // GetCurrentConnectionType() was read and when network name was read. On 2015/06/18 16:20:25, pauljensen wrote: > network->the network Done. https://codereview.chromium.org/1144163008/diff/340001/net/base/network_quali... net/base/network_quality_estimator.cc:356: // GetCurrentConnectionType() was read and when network name was read. On 2015/06/18 16:20:26, pauljensen wrote: > read->called Done. https://codereview.chromium.org/1144163008/diff/340001/net/base/network_quali... net/base/network_quality_estimator.cc:357: // Check if that happened and retry. On 2015/06/18 16:20:26, pauljensen wrote: > Mention that this isn't perfect but should catch the majority of cases, and this > is just an estimate anyhow. Done. https://codereview.chromium.org/1144163008/diff/340001/net/base/network_quali... net/base/network_quality_estimator.cc:359: return GetCurrentNetworkID(); On 2015/06/18 16:20:26, pauljensen wrote: > Please use a loop rather than recursion. Waiting a long time is better than > crashing quickly from stack overflow. Using while(true) now, which I found to be slightly cleaner -- I can define and declare NetworkID inside the loop. Using do-while, I had to declare it before the loop and update it inside the loop. WDYT? https://codereview.chromium.org/1144163008/diff/340001/net/base/network_quali... File net/base/network_quality_estimator.h (right): https://codereview.chromium.org/1144163008/diff/340001/net/base/network_quali... net/base/network_quality_estimator.h:55: protected: On 2015/06/18 16:20:26, pauljensen wrote: > Is this protected (rather than private) only for testing purposes? If so, add a > comment. Yes, it is only for testing. Added comment. Done. 
 https://codereview.chromium.org/1144163008/diff/320001/net/base/network_quali... File net/base/network_quality_estimator.h (right): https://codereview.chromium.org/1144163008/diff/320001/net/base/network_quali... net/base/network_quality_estimator.h:209: size_t GetMaximumObservationBufferSizeForTests() const; On 2015/06/17 21:18:46, tbansal1 wrote: > On 2015/06/17 14:19:15, pauljensen wrote: > > Can we remove this and have the tests compare to the internal sizes? > > Right now kMaximumObservationsBufferSize is defined in the cc file (because its > type is size_t which can't be defined in .h). There is no way for the tests to > access it without going through the function. So, still keeping this function. I don't understand. Why can't we replace this function declaration with "static const size_t kMaximumObservationsBufferSize = 500;" that the friended test classes can read? https://codereview.chromium.org/1144163008/diff/340001/net/base/network_quali... File net/base/network_quality_estimator.cc (right): https://codereview.chromium.org/1144163008/diff/340001/net/base/network_quali... net/base/network_quality_estimator.cc:359: return GetCurrentNetworkID(); On 2015/06/18 20:57:41, tbansal1 wrote: > On 2015/06/18 16:20:26, pauljensen wrote: > > Please use a loop rather than recursion. Waiting a long time is better than > > crashing quickly from stack overflow. > > Using while(true) now, which I found to be slightly cleaner -- I can define and > declare NetworkID inside the loop. Using do-while, I had to declare it before > the loop and update it inside the loop. WDYT? SGTM https://codereview.chromium.org/1144163008/diff/340001/net/base/network_quali... net/base/network_quality_estimator.cc:396: (it->second)->UpdateNetworkQuality(median_kbps, median_rtt); This in-place update seems odd. Why not just: cached_network_qualities_[current_network_id_] = CachedNetworkQuality(...) and then you can remove UpdateNetworkQuality() and make the members of CachedNetworkQuality const. https://codereview.chromium.org/1144163008/diff/340001/net/base/network_quali... File net/base/network_quality_estimator.h (right): https://codereview.chromium.org/1144163008/diff/340001/net/base/network_quali... net/base/network_quality_estimator.h:84: // - Wi-Fi SSID (if the user is connected to a Wi-Fi access point and the user->device remove () This will make it like the following bullet point https://codereview.chromium.org/1144163008/diff/400001/net/base/network_quali... File net/base/network_quality_estimator.cc (right): https://codereview.chromium.org/1144163008/diff/400001/net/base/network_quali... net/base/network_quality_estimator.cc:327: // GetCurrentConnectionType() was called and when the API to determine the GetCurrent->Get 
 Thanks for the comments. PTAL. https://codereview.chromium.org/1144163008/diff/320001/net/base/network_quali... File net/base/network_quality_estimator.h (right): https://codereview.chromium.org/1144163008/diff/320001/net/base/network_quali... net/base/network_quality_estimator.h:209: size_t GetMaximumObservationBufferSizeForTests() const; On 2015/06/19 03:10:07, pauljensen wrote: > On 2015/06/17 21:18:46, tbansal1 wrote: > > On 2015/06/17 14:19:15, pauljensen wrote: > > > Can we remove this and have the tests compare to the internal sizes? > > > > Right now kMaximumObservationsBufferSize is defined in the cc file (because > its > > type is size_t which can't be defined in .h). There is no way for the tests to > > access it without going through the function. So, still keeping this function. > > I don't understand. Why can't we replace this function declaration with "static > const size_t kMaximumObservationsBufferSize = 500;" that the friended test > classes can read? For some reason, this gives the linking error both in nqe.cc and nqe_test.cc. Typecasting it by size_t solves the linking error (this is what I am doing right now) but I am not sure if that's the right approach. Seems that it is not preferable to define static const size_t in header file. Another approach is to simply use const size_t (e.g., https://code.google.com/p/chromium/codesearch#chromium/src/net/quic/quic_fram...). So, there are 3 possible approaches (1) Typecase size_t like what I am doing now (2) Define the variables as const size_t (similar to quic code above) (3) Declare and define in anonymous namespace in .cc file and have functions that expose it to the tests. Please let me know which approach you think is best. https://codereview.chromium.org/1144163008/diff/340001/net/base/network_quali... File net/base/network_quality_estimator.cc (right): https://codereview.chromium.org/1144163008/diff/340001/net/base/network_quali... net/base/network_quality_estimator.cc:396: (it->second)->UpdateNetworkQuality(median_kbps, median_rtt); On 2015/06/19 03:10:07, pauljensen wrote: > This in-place update seems odd. Why not just: > cached_network_qualities_[current_network_id_] = CachedNetworkQuality(...) > and then you can remove UpdateNetworkQuality() and make the members of > CachedNetworkQuality const. For this, I will need to overload = operator for CachedNetworkQuality. That prevents me from making members of CachedNetworkQuality const. Other option is to reset the scoped ptr in the map by creating a new CachedNetworkQuality oject. This will call the constructor and not the assignment operator. That way I can make members of CachedNetworkQuality as const and not have to overload = operator. Please let me know if that SGTY? My only concern was that we would be calling destructor and constructor but I am not sure if that's a valid concern. Thanks. https://codereview.chromium.org/1144163008/diff/340001/net/base/network_quali... File net/base/network_quality_estimator.h (right): https://codereview.chromium.org/1144163008/diff/340001/net/base/network_quali... net/base/network_quality_estimator.h:84: // - Wi-Fi SSID (if the user is connected to a Wi-Fi access point and the On 2015/06/19 03:10:07, pauljensen wrote: > user->device > remove () > This will make it like the following bullet point Done. https://codereview.chromium.org/1144163008/diff/400001/net/base/network_quali... File net/base/network_quality_estimator.cc (right): https://codereview.chromium.org/1144163008/diff/400001/net/base/network_quali... net/base/network_quality_estimator.cc:327: // GetCurrentConnectionType() was called and when the API to determine the On 2015/06/19 03:10:07, pauljensen wrote: > GetCurrent->Get Thanks for the catch. Done. 
 https://codereview.chromium.org/1144163008/diff/320001/net/base/network_quali... File net/base/network_quality_estimator.h (right): https://codereview.chromium.org/1144163008/diff/320001/net/base/network_quali... net/base/network_quality_estimator.h:209: size_t GetMaximumObservationBufferSizeForTests() const; On 2015/06/19 23:34:40, tbansal1 wrote: > On 2015/06/19 03:10:07, pauljensen wrote: > > On 2015/06/17 21:18:46, tbansal1 wrote: > > > On 2015/06/17 14:19:15, pauljensen wrote: > > > > Can we remove this and have the tests compare to the internal sizes? > > > > > > Right now kMaximumObservationsBufferSize is defined in the cc file (because > > its > > > type is size_t which can't be defined in .h). There is no way for the tests > to > > > access it without going through the function. So, still keeping this > function. > > > > I don't understand. Why can't we replace this function declaration with > "static > > const size_t kMaximumObservationsBufferSize = 500;" that the friended test > > classes can read? > > For some reason, this gives the linking error both in nqe.cc and nqe_test.cc. > Typecasting it by size_t solves the linking error (this is what I am doing right > now) but I am not sure if that's the right approach. Seems that it is not > preferable to define static const size_t in header file. Another approach is to > simply use const size_t (e.g., > https://code.google.com/p/chromium/codesearch#chromium/src/net/quic/quic_fram...). > > > So, there are 3 possible approaches > (1) Typecase size_t like what I am doing now > (2) Define the variables as const size_t (similar to quic code above) > (3) Declare and define in anonymous namespace in .cc file and have functions > that expose it to the tests. > > Please let me know which approach you think is best. What link error are you seeing? There are plenty of places that define static const size_t's in headers: ~/chrome/src$ git grep " static const size_t" -- *.h | wc -l 181 https://codereview.chromium.org/1144163008/diff/340001/net/base/network_quali... File net/base/network_quality_estimator.cc (right): https://codereview.chromium.org/1144163008/diff/340001/net/base/network_quali... net/base/network_quality_estimator.cc:396: (it->second)->UpdateNetworkQuality(median_kbps, median_rtt); On 2015/06/19 23:34:40, tbansal1 wrote: > On 2015/06/19 03:10:07, pauljensen wrote: > > This in-place update seems odd. Why not just: > > cached_network_qualities_[current_network_id_] = CachedNetworkQuality(...) > > and then you can remove UpdateNetworkQuality() and make the members of > > CachedNetworkQuality const. > > For this, I will need to overload = operator for CachedNetworkQuality. SGTM > That > prevents me from making members of CachedNetworkQuality const. Fine; they're already non-const. > > Other option is to reset the scoped ptr in the map by creating a new > CachedNetworkQuality oject. This will call the constructor and not the > assignment operator. That way I can make members of CachedNetworkQuality as > const and not have to overload = operator. Please let me know if that SGTY? My > only concern was that we would be calling destructor and constructor but I am > not sure if that's a valid concern. Thanks. 
 ptal. thanks. https://codereview.chromium.org/1144163008/diff/320001/net/base/network_quali... File net/base/network_quality_estimator.h (right): https://codereview.chromium.org/1144163008/diff/320001/net/base/network_quali... net/base/network_quality_estimator.h:209: size_t GetMaximumObservationBufferSizeForTests() const; On 2015/06/20 01:30:45, pauljensen wrote: > On 2015/06/19 23:34:40, tbansal1 wrote: > > On 2015/06/19 03:10:07, pauljensen wrote: > > > On 2015/06/17 21:18:46, tbansal1 wrote: > > > > On 2015/06/17 14:19:15, pauljensen wrote: > > > > > Can we remove this and have the tests compare to the internal sizes? > > > > > > > > Right now kMaximumObservationsBufferSize is defined in the cc file > (because > > > its > > > > type is size_t which can't be defined in .h). There is no way for the > tests > > to > > > > access it without going through the function. So, still keeping this > > function. > > > > > > I don't understand. Why can't we replace this function declaration with > > "static > > > const size_t kMaximumObservationsBufferSize = 500;" that the friended test > > > classes can read? > > > > For some reason, this gives the linking error both in nqe.cc and nqe_test.cc. > > Typecasting it by size_t solves the linking error (this is what I am doing > right > > now) but I am not sure if that's the right approach. Seems that it is not > > preferable to define static const size_t in header file. Another approach is > to > > simply use const size_t (e.g., > > > https://code.google.com/p/chromium/codesearch#chromium/src/net/quic/quic_fram...). > > > > > > So, there are 3 possible approaches > > (1) Typecase size_t like what I am doing now > > (2) Define the variables as const size_t (similar to quic code above) > > (3) Declare and define in anonymous namespace in .cc file and have functions > > that expose it to the tests. > > > > Please let me know which approach you think is best. > > What link error are you seeing? There are plenty of places that define static > const size_t's in headers: > ~/chrome/src$ git grep " static const size_t" -- *.h | wc -l > 181 Forgot to mention that the linking error comes only in DCHECK or other macro statements. It does not show up in non-MACRO code. Weird. Here is the linking error: https://goto.google.com/linkingerror It works if the static const is not a class member but not as a class member. e.g., if you search for static\ const\ size_t.*_\ .* f:h$ -f:test -f:third_party in cs.chromium.org, there are only 3 results. (This regex "tries" to look only for static const class members that are defined in the header) 
 ptal. thanks. https://codereview.chromium.org/1144163008/diff/320001/net/base/network_quali... File net/base/network_quality_estimator.h (right): https://codereview.chromium.org/1144163008/diff/320001/net/base/network_quali... net/base/network_quality_estimator.h:209: size_t GetMaximumObservationBufferSizeForTests() const; On 2015/06/20 01:30:45, pauljensen wrote: > On 2015/06/19 23:34:40, tbansal1 wrote: > > On 2015/06/19 03:10:07, pauljensen wrote: > > > On 2015/06/17 21:18:46, tbansal1 wrote: > > > > On 2015/06/17 14:19:15, pauljensen wrote: > > > > > Can we remove this and have the tests compare to the internal sizes? > > > > > > > > Right now kMaximumObservationsBufferSize is defined in the cc file > (because > > > its > > > > type is size_t which can't be defined in .h). There is no way for the > tests > > to > > > > access it without going through the function. So, still keeping this > > function. > > > > > > I don't understand. Why can't we replace this function declaration with > > "static > > > const size_t kMaximumObservationsBufferSize = 500;" that the friended test > > > classes can read? > > > > For some reason, this gives the linking error both in nqe.cc and nqe_test.cc. > > Typecasting it by size_t solves the linking error (this is what I am doing > right > > now) but I am not sure if that's the right approach. Seems that it is not > > preferable to define static const size_t in header file. Another approach is > to > > simply use const size_t (e.g., > > > https://code.google.com/p/chromium/codesearch#chromium/src/net/quic/quic_fram...). > > > > > > So, there are 3 possible approaches > > (1) Typecase size_t like what I am doing now > > (2) Define the variables as const size_t (similar to quic code above) > > (3) Declare and define in anonymous namespace in .cc file and have functions > > that expose it to the tests. > > > > Please let me know which approach you think is best. > > What link error are you seeing? There are plenty of places that define static > const size_t's in headers: > ~/chrome/src$ git grep " static const size_t" -- *.h | wc -l > 181 Forgot to mention that the linking error comes only in DCHECK or other macro statements. It does not show up in non-MACRO code. Weird. Here is the linking error: https://goto.google.com/linkingerror It works if the static const is not a class member but not as a class member. e.g., if you search for static\ const\ size_t.*_\ .* f:h$ -f:test -f:third_party in cs.chromium.org, there are only 3 results. (This regex "tries" to look only for static const class members that are defined in the header) 
 https://codereview.chromium.org/1144163008/diff/320001/net/base/network_quali... File net/base/network_quality_estimator.h (right): https://codereview.chromium.org/1144163008/diff/320001/net/base/network_quali... net/base/network_quality_estimator.h:209: size_t GetMaximumObservationBufferSizeForTests() const; On 2015/06/20 03:09:30, tbansal1 wrote: > On 2015/06/20 01:30:45, pauljensen wrote: > > On 2015/06/19 23:34:40, tbansal1 wrote: > > > On 2015/06/19 03:10:07, pauljensen wrote: > > > > On 2015/06/17 21:18:46, tbansal1 wrote: > > > > > On 2015/06/17 14:19:15, pauljensen wrote: > > > > > > Can we remove this and have the tests compare to the internal sizes? > > > > > > > > > > Right now kMaximumObservationsBufferSize is defined in the cc file > > (because > > > > its > > > > > type is size_t which can't be defined in .h). There is no way for the > > tests > > > to > > > > > access it without going through the function. So, still keeping this > > > function. > > > > > > > > I don't understand. Why can't we replace this function declaration with > > > "static > > > > const size_t kMaximumObservationsBufferSize = 500;" that the friended test > > > > classes can read? > > > > > > For some reason, this gives the linking error both in nqe.cc and > nqe_test.cc. > > > Typecasting it by size_t solves the linking error (this is what I am doing > > right > > > now) but I am not sure if that's the right approach. Seems that it is not > > > preferable to define static const size_t in header file. Another approach is > > to > > > simply use const size_t (e.g., > > > > > > https://code.google.com/p/chromium/codesearch#chromium/src/net/quic/quic_fram...). > > > > > > > > > So, there are 3 possible approaches > > > (1) Typecase size_t like what I am doing now > > > (2) Define the variables as const size_t (similar to quic code above) > > > (3) Declare and define in anonymous namespace in .cc file and have functions > > > that expose it to the tests. > > > > > > Please let me know which approach you think is best. > > > > What link error are you seeing? There are plenty of places that define static > > const size_t's in headers: > > ~/chrome/src$ git grep " static const size_t" -- *.h | wc -l > > 181 > > Forgot to mention that the linking error comes only in DCHECK or other macro > statements. It does not show up in non-MACRO code. Weird. > > Here is the linking error: https://goto.google.com/linkingerror > > It works if the static const is not a class member but not as a class member. > e.g., if you search for > static\ const\ size_t.*_\ .* f:h$ -f:test -f:third_party > in http://cs.chromium.org, there are only 3 results. (This regex "tries" to look only > for static const class members that are defined in the header) My regex was incorrect. It does not capture variable names that start with k. Here is another one that captures that but does not guarantee that the variable is member of class: static\ const\ size_t\ k.*=.* f:h$ -f:test -f:third_party 
 https://codereview.chromium.org/1144163008/diff/320001/net/base/network_quali... File net/base/network_quality_estimator.h (right): https://codereview.chromium.org/1144163008/diff/320001/net/base/network_quali... net/base/network_quality_estimator.h:209: size_t GetMaximumObservationBufferSizeForTests() const; On 2015/06/20 03:13:56, tbansal1 wrote: > On 2015/06/20 03:09:30, tbansal1 wrote: > > On 2015/06/20 01:30:45, pauljensen wrote: > > > On 2015/06/19 23:34:40, tbansal1 wrote: > > > > On 2015/06/19 03:10:07, pauljensen wrote: > > > > > On 2015/06/17 21:18:46, tbansal1 wrote: > > > > > > On 2015/06/17 14:19:15, pauljensen wrote: > > > > > > > Can we remove this and have the tests compare to the internal sizes? > > > > > > > > > > > > Right now kMaximumObservationsBufferSize is defined in the cc file > > > (because > > > > > its > > > > > > type is size_t which can't be defined in .h). There is no way for the > > > tests > > > > to > > > > > > access it without going through the function. So, still keeping this > > > > function. > > > > > > > > > > I don't understand. Why can't we replace this function declaration with > > > > "static > > > > > const size_t kMaximumObservationsBufferSize = 500;" that the friended > test > > > > > classes can read? > > > > > > > > For some reason, this gives the linking error both in nqe.cc and > > nqe_test.cc. > > > > Typecasting it by size_t solves the linking error (this is what I am doing > > > right > > > > now) but I am not sure if that's the right approach. Seems that it is not > > > > preferable to define static const size_t in header file. Another approach > is > > > to > > > > simply use const size_t (e.g., > > > > > > > > > > https://code.google.com/p/chromium/codesearch#chromium/src/net/quic/quic_fram...). > > > > > > > > > > > > So, there are 3 possible approaches > > > > (1) Typecase size_t like what I am doing now > > > > (2) Define the variables as const size_t (similar to quic code above) > > > > (3) Declare and define in anonymous namespace in .cc file and have > functions > > > > that expose it to the tests. > > > > > > > > Please let me know which approach you think is best. > > > > > > What link error are you seeing? There are plenty of places that define > static > > > const size_t's in headers: > > > ~/chrome/src$ git grep " static const size_t" -- *.h | wc -l > > > 181 > > > > Forgot to mention that the linking error comes only in DCHECK or other macro > > statements. It does not show up in non-MACRO code. Weird. > > > > Here is the linking error: https://goto.google.com/linkingerror > > > > It works if the static const is not a class member but not as a class member. > > e.g., if you search for > > static\ const\ size_t.*_\ .* f:h$ -f:test -f:third_party > > in http://cs.chromium.org, there are only 3 results. (This regex "tries" to > look only > > for static const class members that are defined in the header) > > My regex was incorrect. It does not capture variable names that start with k. > Here is another one that captures that but does not > guarantee that the variable is member of class: > static\ const\ size_t\ k.*=.* f:h$ -f:test -f:third_party It seems like existing code also does typecast before putting it in a macro statement, see this e.g.: https://code.google.com/p/chromium/codesearch#chromium/src/gpu/command_buffer... Please let me know what you think is the best approach. I do not have much Chromium experience but this typecasting approach does not look very great. WDYT? 
 On 2015/06/20 03:21:17, tbansal1 wrote: > https://codereview.chromium.org/1144163008/diff/320001/net/base/network_quali... > File net/base/network_quality_estimator.h (right): > > https://codereview.chromium.org/1144163008/diff/320001/net/base/network_quali... > net/base/network_quality_estimator.h:209: size_t > GetMaximumObservationBufferSizeForTests() const; > On 2015/06/20 03:13:56, tbansal1 wrote: > > On 2015/06/20 03:09:30, tbansal1 wrote: > > > On 2015/06/20 01:30:45, pauljensen wrote: > > > > On 2015/06/19 23:34:40, tbansal1 wrote: > > > > > On 2015/06/19 03:10:07, pauljensen wrote: > > > > > > On 2015/06/17 21:18:46, tbansal1 wrote: > > > > > > > On 2015/06/17 14:19:15, pauljensen wrote: > > > > > > > > Can we remove this and have the tests compare to the internal > sizes? > > > > > > > > > > > > > > Right now kMaximumObservationsBufferSize is defined in the cc file > > > > (because > > > > > > its > > > > > > > type is size_t which can't be defined in .h). There is no way for > the > > > > tests > > > > > to > > > > > > > access it without going through the function. So, still keeping this > > > > > function. > > > > > > > > > > > > I don't understand. Why can't we replace this function declaration > with > > > > > "static > > > > > > const size_t kMaximumObservationsBufferSize = 500;" that the friended > > test > > > > > > classes can read? > > > > > > > > > > For some reason, this gives the linking error both in nqe.cc and > > > nqe_test.cc. > > > > > Typecasting it by size_t solves the linking error (this is what I am > doing > > > > right > > > > > now) but I am not sure if that's the right approach. Seems that it is > not > > > > > preferable to define static const size_t in header file. Another > approach > > is > > > > to > > > > > simply use const size_t (e.g., > > > > > > > > > > > > > > > https://code.google.com/p/chromium/codesearch#chromium/src/net/quic/quic_fram...). > > > > > > > > > > > > > > > So, there are 3 possible approaches > > > > > (1) Typecase size_t like what I am doing now > > > > > (2) Define the variables as const size_t (similar to quic code above) > > > > > (3) Declare and define in anonymous namespace in .cc file and have > > functions > > > > > that expose it to the tests. > > > > > > > > > > Please let me know which approach you think is best. > > > > > > > > What link error are you seeing? There are plenty of places that define > > static > > > > const size_t's in headers: > > > > ~/chrome/src$ git grep " static const size_t" -- *.h | wc -l > > > > 181 > > > > > > Forgot to mention that the linking error comes only in DCHECK or other macro > > > statements. It does not show up in non-MACRO code. Weird. > > > > > > Here is the linking error: https://goto.google.com/linkingerror > > > > > > It works if the static const is not a class member but not as a class > member. > > > e.g., if you search for > > > static\ const\ size_t.*_\ .* f:h$ -f:test -f:third_party > > > in http://cs.chromium.org, there are only 3 results. (This regex "tries" to > > look only > > > for static const class members that are defined in the header) > > > > My regex was incorrect. It does not capture variable names that start with k. > > Here is another one that captures that but does not > > guarantee that the variable is member of class: > > static\ const\ size_t\ k.*=.* f:h$ -f:test -f:third_party > > It seems like existing code also does typecast before putting it in a macro > statement, see this e.g.: > https://code.google.com/p/chromium/codesearch#chromium/src/gpu/command_buffer... > > Please let me know what you think is the best approach. I do not have much > Chromium experience but this typecasting approach does not look very great. > WDYT? I just want to keep the implementation simple and not complicated for testing, so I'd like those accessor functions removed. I wonder if this is related to whether the compiler outputs a reference for the variable and whether a definition is output (i.e. whether the constant has an address). See http://stackoverflow.com/questions/5391973/undefined-reference-to-static-cons... You could investigate by dumping the generated object files to see if a reference and definition are there. I think the solution is to add a definition of the variable to a .cc file. If that fails to work, I'm fine if you have to do "size_t var = kBlah" in tests. 
 Patchset #17 (id:440001) has been deleted 
 ptal. thnaks. https://codereview.chromium.org/1144163008/diff/320001/net/base/network_quali... File net/base/network_quality_estimator.h (right): https://codereview.chromium.org/1144163008/diff/320001/net/base/network_quali... net/base/network_quality_estimator.h:209: size_t GetMaximumObservationBufferSizeForTests() const; On 2015/06/20 03:21:17, tbansal1 wrote: > On 2015/06/20 03:13:56, tbansal1 wrote: > > On 2015/06/20 03:09:30, tbansal1 wrote: > > > On 2015/06/20 01:30:45, pauljensen wrote: > > > > On 2015/06/19 23:34:40, tbansal1 wrote: > > > > > On 2015/06/19 03:10:07, pauljensen wrote: > > > > > > On 2015/06/17 21:18:46, tbansal1 wrote: > > > > > > > On 2015/06/17 14:19:15, pauljensen wrote: > > > > > > > > Can we remove this and have the tests compare to the internal > sizes? > > > > > > > > > > > > > > Right now kMaximumObservationsBufferSize is defined in the cc file > > > > (because > > > > > > its > > > > > > > type is size_t which can't be defined in .h). There is no way for > the > > > > tests > > > > > to > > > > > > > access it without going through the function. So, still keeping this > > > > > function. > > > > > > > > > > > > I don't understand. Why can't we replace this function declaration > with > > > > > "static > > > > > > const size_t kMaximumObservationsBufferSize = 500;" that the friended > > test > > > > > > classes can read? > > > > > > > > > > For some reason, this gives the linking error both in nqe.cc and > > > nqe_test.cc. > > > > > Typecasting it by size_t solves the linking error (this is what I am > doing > > > > right > > > > > now) but I am not sure if that's the right approach. Seems that it is > not > > > > > preferable to define static const size_t in header file. Another > approach > > is > > > > to > > > > > simply use const size_t (e.g., > > > > > > > > > > > > > > > https://code.google.com/p/chromium/codesearch#chromium/src/net/quic/quic_fram...). > > > > > > > > > > > > > > > So, there are 3 possible approaches > > > > > (1) Typecase size_t like what I am doing now > > > > > (2) Define the variables as const size_t (similar to quic code above) > > > > > (3) Declare and define in anonymous namespace in .cc file and have > > functions > > > > > that expose it to the tests. > > > > > > > > > > Please let me know which approach you think is best. > > > > > > > > What link error are you seeing? There are plenty of places that define > > static > > > > const size_t's in headers: > > > > ~/chrome/src$ git grep " static const size_t" -- *.h | wc -l > > > > 181 > > > > > > Forgot to mention that the linking error comes only in DCHECK or other macro > > > statements. It does not show up in non-MACRO code. Weird. > > > > > > Here is the linking error: https://goto.google.com/linkingerror > > > > > > It works if the static const is not a class member but not as a class > member. > > > e.g., if you search for > > > static\ const\ size_t.*_\ .* f:h$ -f:test -f:third_party > > > in http://cs.chromium.org, there are only 3 results. (This regex "tries" to > > look only > > > for static const class members that are defined in the header) > > > > My regex was incorrect. It does not capture variable names that start with k. > > Here is another one that captures that but does not > > guarantee that the variable is member of class: > > static\ const\ size_t\ k.*=.* f:h$ -f:test -f:third_party > > It seems like existing code also does typecast before putting it in a macro > statement, see this e.g.: > https://code.google.com/p/chromium/codesearch#chromium/src/gpu/command_buffer... > > Please let me know what you think is the best approach. I do not have much > Chromium experience but this typecasting approach does not look very great. > WDYT? Done. 
 https://codereview.chromium.org/1144163008/diff/340001/net/base/network_quali... File net/base/network_quality_estimator.cc (right): https://codereview.chromium.org/1144163008/diff/340001/net/base/network_quali... net/base/network_quality_estimator.cc:396: (it->second)->UpdateNetworkQuality(median_kbps, median_rtt); On 2015/06/20 01:30:45, pauljensen wrote: > On 2015/06/19 23:34:40, tbansal1 wrote: > > On 2015/06/19 03:10:07, pauljensen wrote: > > > This in-place update seems odd. Why not just: > > > cached_network_qualities_[current_network_id_] = CachedNetworkQuality(...) > > > and then you can remove UpdateNetworkQuality() and make the members of > > > CachedNetworkQuality const. > > > > For this, I will need to overload = operator for CachedNetworkQuality. > SGTM > > > That > > prevents me from making members of CachedNetworkQuality const. > Fine; they're already non-const. > > > > > Other option is to reset the scoped ptr in the map by creating a new > > CachedNetworkQuality oject. This will call the constructor and not the > > assignment operator. That way I can make members of CachedNetworkQuality as > > const and not have to overload = operator. Please let me know if that SGTY? My > > only concern was that we would be calling destructor and constructor but I am > > not sure if that's a valid concern. Thanks. > You never implemented this change. https://codereview.chromium.org/1144163008/diff/460001/net/base/network_quali... File net/base/network_quality_estimator.cc (right): https://codereview.chromium.org/1144163008/diff/460001/net/base/network_quali... net/base/network_quality_estimator.cc:293: NetworkQualityEstimator::kMaximumObservationsBufferSize); Is NetworkQualityEstimator:: really necessary? Ditto for the other spots in this file. https://codereview.chromium.org/1144163008/diff/460001/net/base/network_quali... net/base/network_quality_estimator.cc:338: network_id.id = GetWifiSSID(); We should implement this for windows. It should be quite easy. Is there a bug filed for this? https://codereview.chromium.org/1144163008/diff/460001/net/base/network_quali... net/base/network_quality_estimator.cc:374: // Add UMA to record how frequently matches happen. Add a "TODO(tbansal):" here and the next line https://codereview.chromium.org/1144163008/diff/460001/net/base/network_quali... File net/base/network_quality_estimator.h (right): https://codereview.chromium.org/1144163008/diff/460001/net/base/network_quali... net/base/network_quality_estimator.h:65: Remove new line https://codereview.chromium.org/1144163008/diff/460001/net/base/network_quali... net/base/network_quality_estimator.h:66: NetworkID(const NetworkID& other) : type(other.type), id(other.id) {} does this need explicit? https://codereview.chromium.org/1144163008/diff/460001/net/base/network_quali... net/base/network_quality_estimator.h:67: Remove new line https://codereview.chromium.org/1144163008/diff/460001/net/base/network_quali... net/base/network_quality_estimator.h:129: friend class ObservationBuffer; What is this needed for? https://codereview.chromium.org/1144163008/diff/460001/net/base/network_quali... net/base/network_quality_estimator.h:135: Remove new line https://codereview.chromium.org/1144163008/diff/460001/net/base/network_quali... net/base/network_quality_estimator.h:164: Remove new line https://codereview.chromium.org/1144163008/diff/460001/net/base/network_quali... net/base/network_quality_estimator.h:178: remove new line https://codereview.chromium.org/1144163008/diff/460001/net/base/network_quali... net/base/network_quality_estimator.h:186: size_t Size() const; I think this function is dead once the unneeded "ForTest" functions are removed, so remove this function. https://codereview.chromium.org/1144163008/diff/460001/net/base/network_quali... net/base/network_quality_estimator.h:224: size_t GetKbpsObservationBufferSizeForTests() const; Can you get rid of this too? https://codereview.chromium.org/1144163008/diff/460001/net/base/network_quali... net/base/network_quality_estimator.h:227: size_t GetRTTObservationBufferSizeForTests() const; ditto https://codereview.chromium.org/1144163008/diff/460001/net/base/network_quali... net/base/network_quality_estimator.h:253: base::TimeDelta fastest_rtt_since_last_connection_change_; Could we combine fastest_rtt_since_last_connection_change_ and peak_kbps_since_last_connection_change_ into "NetworkQuality peak_quality_metrics_"? I think this might simplify UpdateNetworkQuality() and GetPeakEstimate(). I think these variables are just copied from NCN. 
 Patchset #18 (id:480001) has been deleted 
 Patchset #18 (id:500001) has been deleted 
 ptal. https://codereview.chromium.org/1144163008/diff/340001/net/base/network_quali... File net/base/network_quality_estimator.cc (right): https://codereview.chromium.org/1144163008/diff/340001/net/base/network_quali... net/base/network_quality_estimator.cc:396: (it->second)->UpdateNetworkQuality(median_kbps, median_rtt); On 2015/06/22 18:39:52, pauljensen wrote: > On 2015/06/20 01:30:45, pauljensen wrote: > > On 2015/06/19 23:34:40, tbansal1 wrote: > > > On 2015/06/19 03:10:07, pauljensen wrote: > > > > This in-place update seems odd. Why not just: > > > > cached_network_qualities_[current_network_id_] = > CachedNetworkQuality(...) > > > > and then you can remove UpdateNetworkQuality() and make the members of > > > > CachedNetworkQuality const. > > > > > > For this, I will need to overload = operator for CachedNetworkQuality. > > SGTM > > > > > That > > > prevents me from making members of CachedNetworkQuality const. > > Fine; they're already non-const. > > > > > > > > Other option is to reset the scoped ptr in the map by creating a new > > > CachedNetworkQuality oject. This will call the constructor and not the > > > assignment operator. That way I can make members of CachedNetworkQuality as > > > const and not have to overload = operator. Please let me know if that SGTY? > My > > > only concern was that we would be calling destructor and constructor but I > am > > > not sure if that's a valid concern. Thanks. > > > > You never implemented this change. Took a slightly different approach which allowed me to make members of CachedNetworkQuality const. Done. This simplified a lot. Thanks. https://codereview.chromium.org/1144163008/diff/460001/net/base/network_quali... File net/base/network_quality_estimator.cc (right): https://codereview.chromium.org/1144163008/diff/460001/net/base/network_quali... net/base/network_quality_estimator.cc:293: NetworkQualityEstimator::kMaximumObservationsBufferSize); On 2015/06/22 18:39:52, pauljensen wrote: > Is NetworkQualityEstimator:: really necessary? Ditto for the other spots in this > file. Its not really needed in this file but only in the unittest.cc. Removed. https://codereview.chromium.org/1144163008/diff/460001/net/base/network_quali... net/base/network_quality_estimator.cc:338: network_id.id = GetWifiSSID(); On 2015/06/22 18:39:52, pauljensen wrote: > We should implement this for windows. It should be quite easy. Is there a bug > filed for this? Filed crbug.com/503235 https://codereview.chromium.org/1144163008/diff/460001/net/base/network_quali... net/base/network_quality_estimator.cc:374: // Add UMA to record how frequently matches happen. On 2015/06/22 18:39:52, pauljensen wrote: > Add a "TODO(tbansal):" here and the next line Done. https://codereview.chromium.org/1144163008/diff/460001/net/base/network_quali... File net/base/network_quality_estimator.h (right): https://codereview.chromium.org/1144163008/diff/460001/net/base/network_quali... net/base/network_quality_estimator.h:65: On 2015/06/22 18:39:53, pauljensen wrote: > Remove new line Aah, did not know about the new line style. I thought I saw these separated by a newline somewhere (may be in data reduction proxy code). Done. https://codereview.chromium.org/1144163008/diff/460001/net/base/network_quali... net/base/network_quality_estimator.h:66: NetworkID(const NetworkID& other) : type(other.type), id(other.id) {} On 2015/06/22 18:39:53, pauljensen wrote: > does this need explicit? don't think so. From: http://google-styleguide.googlecode.com/svn/trunk/cppguide.html#Explicit_Cons... "Copy and move constructors are exceptions: they should not be explicit" https://codereview.chromium.org/1144163008/diff/460001/net/base/network_quali... net/base/network_quality_estimator.h:67: On 2015/06/22 18:39:53, pauljensen wrote: > Remove new line Done. https://codereview.chromium.org/1144163008/diff/460001/net/base/network_quali... net/base/network_quality_estimator.h:129: friend class ObservationBuffer; On 2015/06/22 18:39:52, pauljensen wrote: > What is this needed for? Done. https://codereview.chromium.org/1144163008/diff/460001/net/base/network_quali... net/base/network_quality_estimator.h:135: On 2015/06/22 18:39:53, pauljensen wrote: > Remove new line Done. https://codereview.chromium.org/1144163008/diff/460001/net/base/network_quali... net/base/network_quality_estimator.h:164: On 2015/06/22 18:39:52, pauljensen wrote: > Remove new line Done. https://codereview.chromium.org/1144163008/diff/460001/net/base/network_quali... net/base/network_quality_estimator.h:178: On 2015/06/22 18:39:52, pauljensen wrote: > remove new line Done. https://codereview.chromium.org/1144163008/diff/460001/net/base/network_quali... net/base/network_quality_estimator.h:186: size_t Size() const; On 2015/06/22 18:39:52, pauljensen wrote: > I think this function is dead once the unneeded "ForTest" functions are removed, > so remove this function. Please see the comment on the ForTest() functions. https://codereview.chromium.org/1144163008/diff/460001/net/base/network_quali... net/base/network_quality_estimator.h:224: size_t GetKbpsObservationBufferSizeForTests() const; On 2015/06/22 18:39:53, pauljensen wrote: > Can you get rid of this too? Can you please explain how I can get rid of them. using estimator.kbps_observations_.Size() in nqe_unittest.cc does not work on Windows. It gives linking error (it does work on all other platforms): http://build.chromium.org/p/tryserver.chromium.win/builders/win_chromium_comp... I fixed the linking error by https://codereview.chromium.org/1164713004/diff2/380001:400001/net/base/netwo... https://codereview.chromium.org/1144163008/diff/460001/net/base/network_quali... net/base/network_quality_estimator.h:227: size_t GetRTTObservationBufferSizeForTests() const; On 2015/06/22 18:39:52, pauljensen wrote: > ditto Please see above. https://codereview.chromium.org/1144163008/diff/460001/net/base/network_quali... net/base/network_quality_estimator.h:253: base::TimeDelta fastest_rtt_since_last_connection_change_; On 2015/06/22 18:39:52, pauljensen wrote: > Could we combine fastest_rtt_since_last_connection_change_ and > peak_kbps_since_last_connection_change_ into "NetworkQuality > peak_quality_metrics_"? I think this might simplify UpdateNetworkQuality() and > GetPeakEstimate(). I think these variables are just copied from NCN. Done. 
 https://codereview.chromium.org/1144163008/diff/460001/net/base/network_quali... File net/base/network_quality.h (right): https://codereview.chromium.org/1144163008/diff/460001/net/base/network_quali... net/base/network_quality.h:23: remove new line https://codereview.chromium.org/1144163008/diff/460001/net/base/network_quali... net/base/network_quality.h:25: remove new line https://codereview.chromium.org/1144163008/diff/460001/net/base/network_quali... File net/base/network_quality_estimator.h (right): https://codereview.chromium.org/1144163008/diff/460001/net/base/network_quali... net/base/network_quality_estimator.h:66: NetworkID(const NetworkID& other) : type(other.type), id(other.id) {} On 2015/06/22 20:28:26, tbansal1 wrote: > On 2015/06/22 18:39:53, pauljensen wrote: > > does this need explicit? > > don't think so. From: > http://google-styleguide.googlecode.com/svn/trunk/cppguide.html#Explicit_Cons... > > "Copy and move constructors are exceptions: they should not be explicit" Then please fix CachedNetworkQuality()'s copy constructor. https://codereview.chromium.org/1144163008/diff/460001/net/base/network_quali... net/base/network_quality_estimator.h:224: size_t GetKbpsObservationBufferSizeForTests() const; On 2015/06/22 20:28:26, tbansal1 wrote: > On 2015/06/22 18:39:53, pauljensen wrote: > > Can you get rid of this too? > > Can you please explain how I can get rid of them. > using estimator.kbps_observations_.Size() in nqe_unittest.cc does not work on > Windows. It gives > linking error (it does work on all other platforms): > http://build.chromium.org/p/tryserver.chromium.win/builders/win_chromium_comp... > I fixed the linking error by > https://codereview.chromium.org/1164713004/diff2/380001:400001/net/base/netwo... I cannot see the build logs. The build logs get wiped quickly. Please just copy and paste the error message here. 
 On 2015/06/23 11:52:10, pauljensen wrote: > https://codereview.chromium.org/1144163008/diff/460001/net/base/network_quali... > File net/base/network_quality.h (right): > > https://codereview.chromium.org/1144163008/diff/460001/net/base/network_quali... > net/base/network_quality.h:23: > remove new line > > https://codereview.chromium.org/1144163008/diff/460001/net/base/network_quali... > net/base/network_quality.h:25: > remove new line > > https://codereview.chromium.org/1144163008/diff/460001/net/base/network_quali... > File net/base/network_quality_estimator.h (right): > > https://codereview.chromium.org/1144163008/diff/460001/net/base/network_quali... > net/base/network_quality_estimator.h:66: NetworkID(const NetworkID& other) : > type(other.type), id(other.id) {} > On 2015/06/22 20:28:26, tbansal1 wrote: > > On 2015/06/22 18:39:53, pauljensen wrote: > > > does this need explicit? > > > > don't think so. From: > > > http://google-styleguide.googlecode.com/svn/trunk/cppguide.html#Explicit_Cons... > > > > "Copy and move constructors are exceptions: they should not be explicit" > > Then please fix CachedNetworkQuality()'s copy constructor. > > https://codereview.chromium.org/1144163008/diff/460001/net/base/network_quali... > net/base/network_quality_estimator.h:224: size_t > GetKbpsObservationBufferSizeForTests() const; > On 2015/06/22 20:28:26, tbansal1 wrote: > > On 2015/06/22 18:39:53, pauljensen wrote: > > > Can you get rid of this too? > > > > Can you please explain how I can get rid of them. > > using estimator.kbps_observations_.Size() in nqe_unittest.cc does not work on > > Windows. It gives > > linking error (it does work on all other platforms): > > > http://build.chromium.org/p/tryserver.chromium.win/builders/win_chromium_comp... > > I fixed the linking error by > > > https://codereview.chromium.org/1164713004/diff2/380001:400001/net/base/netwo... > > I cannot see the build logs. The build logs get wiped quickly. Please just > copy and paste the error message here. If you do not mind, may I suggest delaying the review of this CL as this is not really necessary for M45 branchpoint. That way, we can focus on the rest of the CLs which are necessary for LoFi experiment (M45). Thanks. 
 mmenke@chromium.org changed reviewers: - mmenke@chromium.org 
 Patchset #19 (id:540001) has been deleted 
 pauljensen@: ptal. Lot of rebasing since you last had a look. https://codereview.chromium.org/1144163008/diff/460001/net/base/network_quali... File net/base/network_quality.h (right): https://codereview.chromium.org/1144163008/diff/460001/net/base/network_quali... net/base/network_quality.h:23: On 2015/06/23 11:52:10, pauljensen wrote: > remove new line Done. https://codereview.chromium.org/1144163008/diff/460001/net/base/network_quali... File net/base/network_quality_estimator.h (right): https://codereview.chromium.org/1144163008/diff/460001/net/base/network_quali... net/base/network_quality_estimator.h:66: NetworkID(const NetworkID& other) : type(other.type), id(other.id) {} On 2015/06/23 11:52:10, pauljensen wrote: > On 2015/06/22 20:28:26, tbansal1 wrote: > > On 2015/06/22 18:39:53, pauljensen wrote: > > > does this need explicit? > > > > don't think so. From: > > > http://google-styleguide.googlecode.com/svn/trunk/cppguide.html#Explicit_Cons... > > > > "Copy and move constructors are exceptions: they should not be explicit" > > Then please fix CachedNetworkQuality()'s copy constructor. I may be looking it wrong but that's not a copy constructor. CachedNetworkQuality has a constructor that takes NetworkQuality as an argument. https://codereview.chromium.org/1144163008/diff/460001/net/base/network_quali... net/base/network_quality_estimator.h:224: size_t GetKbpsObservationBufferSizeForTests() const; On 2015/06/23 11:52:10, pauljensen wrote: > On 2015/06/22 20:28:26, tbansal1 wrote: > > On 2015/06/22 18:39:53, pauljensen wrote: > > > Can you get rid of this too? > > > > Can you please explain how I can get rid of them. > > using estimator.kbps_observations_.Size() in nqe_unittest.cc does not work on > > Windows. It gives > > linking error (it does work on all other platforms): > > > http://build.chromium.org/p/tryserver.chromium.win/builders/win_chromium_comp... > > I fixed the linking error by > > > https://codereview.chromium.org/1164713004/diff2/380001:400001/net/base/netwo... > > I cannot see the build logs. The build logs get wiped quickly. Please just > copy and paste the error message here. Fixed in a separate CL. Adding NET_EXPORT_PRIVATE macro fixed the linking. 
 https://codereview.chromium.org/1144163008/diff/560001/net/base/network_quali... File net/base/network_quality_estimator.cc (right): https://codereview.chromium.org/1144163008/diff/560001/net/base/network_quali... net/base/network_quality_estimator.cc:120: const size_t NetworkQualityEstimator::kMaximumNetworkQualityCacheSize = 10; how about initializing this in the header like the other constants there? https://codereview.chromium.org/1144163008/diff/560001/net/base/network_quali... net/base/network_quality_estimator.cc:122: const size_t NetworkQualityEstimator::kMaximumObservationsBufferSize = 300; ditto https://codereview.chromium.org/1144163008/diff/560001/net/base/network_quali... net/base/network_quality_estimator.cc:642: #endif #if ... ... break; #else break; #endif -> #if ... ... #endif break; https://codereview.chromium.org/1144163008/diff/560001/net/base/network_quali... net/base/network_quality_estimator.cc:651: #endif ditto https://codereview.chromium.org/1144163008/diff/560001/net/base/network_quali... net/base/network_quality_estimator.cc:654: } break; 
 ptal. thanks. https://codereview.chromium.org/1144163008/diff/560001/net/base/network_quali... File net/base/network_quality_estimator.cc (right): https://codereview.chromium.org/1144163008/diff/560001/net/base/network_quali... net/base/network_quality_estimator.cc:120: const size_t NetworkQualityEstimator::kMaximumNetworkQualityCacheSize = 10; On 2015/07/14 11:59:03, pauljensen wrote: > how about initializing this in the header like the other constants there? I get linking error: ../../net/base/network_quality_estimator.cc:692: error: undefined reference to 'net::NetworkQualityEstimator::kMaximumNetworkQualityCacheSize' I believe it is because it is size_t. Changing it to int fixes the error. https://codereview.chromium.org/1144163008/diff/560001/net/base/network_quali... net/base/network_quality_estimator.cc:122: const size_t NetworkQualityEstimator::kMaximumObservationsBufferSize = 300; On 2015/07/14 11:59:03, pauljensen wrote: > ditto See reply above. https://codereview.chromium.org/1144163008/diff/560001/net/base/network_quali... net/base/network_quality_estimator.cc:642: #endif On 2015/07/14 11:59:03, pauljensen wrote: > #if ... > ... > break; > #else > break; > #endif > -> > #if ... > ... > #endif > break; Done. https://codereview.chromium.org/1144163008/diff/560001/net/base/network_quali... net/base/network_quality_estimator.cc:651: #endif On 2015/07/14 11:59:02, pauljensen wrote: > ditto Done. https://codereview.chromium.org/1144163008/diff/560001/net/base/network_quali... net/base/network_quality_estimator.cc:654: } On 2015/07/14 11:59:03, pauljensen wrote: > break; Done. 
 https://codereview.chromium.org/1144163008/diff/560001/net/base/network_quali... File net/base/network_quality_estimator.cc (right): https://codereview.chromium.org/1144163008/diff/560001/net/base/network_quali... net/base/network_quality_estimator.cc:120: const size_t NetworkQualityEstimator::kMaximumNetworkQualityCacheSize = 10; On 2015/07/14 19:51:48, tbansal1 wrote: > On 2015/07/14 11:59:03, pauljensen wrote: > > how about initializing this in the header like the other constants there? > > I get linking error: > ../../net/base/network_quality_estimator.cc:692: error: undefined reference to > 'net::NetworkQualityEstimator::kMaximumNetworkQualityCacheSize' > > I believe it is because it is size_t. Changing it to int fixes the error. Can you track this down further? Use objdump or nm to figure out if the definition is present or if the symbol names don't match or what is going on here. Is it related to NET_EXPORT_PRIVATE? There are litterally hundreds of instances of this elsewhere in Chrome: https://code.google.com/p/chromium/codesearch#search/&q=%22static%20const%20s... 
 On 2015/07/14 20:19:59, pauljensen wrote: > https://codereview.chromium.org/1144163008/diff/560001/net/base/network_quali... > File net/base/network_quality_estimator.cc (right): > > https://codereview.chromium.org/1144163008/diff/560001/net/base/network_quali... > net/base/network_quality_estimator.cc:120: const size_t > NetworkQualityEstimator::kMaximumNetworkQualityCacheSize = 10; > On 2015/07/14 19:51:48, tbansal1 wrote: > > On 2015/07/14 11:59:03, pauljensen wrote: > > > how about initializing this in the header like the other constants there? > > > > I get linking error: > > ../../net/base/network_quality_estimator.cc:692: error: undefined reference to > > 'net::NetworkQualityEstimator::kMaximumNetworkQualityCacheSize' > > > > I believe it is because it is size_t. Changing it to int fixes the error. > > Can you track this down further? Use objdump or nm to figure out if the > definition is present or if the symbol names don't match or what is going on > here. Is it related to NET_EXPORT_PRIVATE? > There are litterally hundreds of instances of this elsewhere in Chrome: > https://code.google.com/p/chromium/codesearch#search/&q=%22static%20const%20s... The linking error only comes when the static const is used in DCHECK macros. It seems typecasting is one way of fixing it: https://code.google.com/p/chromium/codesearch#chromium/src/gpu/command_buffer... I just used static_cast to fix this (ptal). Not sure why but I did not see the definition in the .o file. 
 On 2015/07/14 21:26:20, tbansal1 wrote: > On 2015/07/14 20:19:59, pauljensen wrote: > > > https://codereview.chromium.org/1144163008/diff/560001/net/base/network_quali... > > File net/base/network_quality_estimator.cc (right): > > > > > https://codereview.chromium.org/1144163008/diff/560001/net/base/network_quali... > > net/base/network_quality_estimator.cc:120: const size_t > > NetworkQualityEstimator::kMaximumNetworkQualityCacheSize = 10; > > On 2015/07/14 19:51:48, tbansal1 wrote: > > > On 2015/07/14 11:59:03, pauljensen wrote: > > > > how about initializing this in the header like the other constants there? > > > > > > I get linking error: > > > ../../net/base/network_quality_estimator.cc:692: error: undefined reference > to > > > 'net::NetworkQualityEstimator::kMaximumNetworkQualityCacheSize' > > > > > > I believe it is because it is size_t. Changing it to int fixes the error. > > > > Can you track this down further? Use objdump or nm to figure out if the > > definition is present or if the symbol names don't match or what is going on > > here. Is it related to NET_EXPORT_PRIVATE? > > There are litterally hundreds of instances of this elsewhere in Chrome: > > > https://code.google.com/p/chromium/codesearch#search/&q=%22static%20const%20s... > > The linking error only comes when the static const is used in DCHECK macros. > It seems typecasting is one way of fixing it: > https://code.google.com/p/chromium/codesearch#chromium/src/gpu/command_buffer... > > I just used static_cast to fix this (ptal). Not sure why but I did not see the > definition in the .o file. Can you track this down further? Use objdump or nm to figure out if the definition is present or if the symbol names don't match or what is going on here. I see 5 instances of this work-around now. I'd rather we knew the source of this problem rather than proliferate a work-around. At a minimum if we're going to accept the work-around we should file a new bug about this marked with component Build-Toolchain so the infra folks can investigate. 
 I think this is about ready. This is probably my last set of comments. https://codereview.chromium.org/1144163008/diff/600001/net/base/network_quali... File net/base/network_quality_estimator.cc (right): https://codereview.chromium.org/1144163008/diff/600001/net/base/network_quali... net/base/network_quality_estimator.cc:454: "RTT.Percentile" + std::string(percentile_stringified) + ".", std::string(percentile_stringified)->IntToString(kPercentiles[i]) https://codereview.chromium.org/1144163008/diff/600001/net/base/network_quali... net/base/network_quality_estimator.cc:517: static_cast<size_t>(kMaximumObservationsBufferSize)); Why is this static_cast done on lines 517 and 525 but not 523? https://codereview.chromium.org/1144163008/diff/600001/net/base/network_quali... net/base/network_quality_estimator.cc:633: network_id.id = "Ethernet"; Strikes me as a bit odd that we match Ethernet out of the cache but not other unknown networks. Matching based on router MAC would seem nice (for Ethernet or WiFi) but that could get complicated. https://codereview.chromium.org/1144163008/diff/600001/net/base/network_quali... net/base/network_quality_estimator.cc:665: CachedNetworkQualities::iterator it = const_iterator? https://codereview.chromium.org/1144163008/diff/600001/net/base/network_quali... net/base/network_quality_estimator.cc:671: NetworkQuality network_quality( why not network_quality(it->second->network_quality())? https://codereview.chromium.org/1144163008/diff/600001/net/base/network_quali... net/base/network_quality_estimator.cc:708: for (CachedNetworkQualities::iterator it = const_iterator? https://codereview.chromium.org/1144163008/diff/600001/net/base/network_quali... File net/base/network_quality_estimator.h (right): https://codereview.chromium.org/1144163008/diff/600001/net/base/network_quali... net/base/network_quality_estimator.h:115: // against local HTTP server and allows the responses smaller than nit: "against local HTTP server and a"->". A" https://codereview.chromium.org/1144163008/diff/600001/net/base/network_quali... File net/base/network_quality_estimator_unittest.cc (right): https://codereview.chromium.org/1144163008/diff/600001/net/base/network_quali... net/base/network_quality_estimator_unittest.cc:488: // No new entry should be added for (2G, "test1") since it already exists test1->test-1 https://codereview.chromium.org/1144163008/diff/600001/net/base/network_quali... net/base/network_quality_estimator_unittest.cc:505: // Reading quality of (3G, "test2") should return false. test2->test-2 https://codereview.chromium.org/1144163008/diff/600001/net/base/network_quali... net/base/network_quality_estimator_unittest.cc:537: network_name); network_name->IntToString(i) https://codereview.chromium.org/1144163008/diff/600001/net/base/network_quali... net/base/network_quality_estimator_unittest.cc:563: NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, network_name); network_name->IntToString(i) https://codereview.chromium.org/1144163008/diff/600001/net/base/network_quali... net/base/network_quality_estimator_unittest.cc:567: EXPECT_EQ(expect_present_in_cache, found) << i << "\n" << network_count; can we elaborate on these "i << "\n" << network_count" strings or remove them? 
 PTAL. Filed Filed https://code.google.com/p/chromium/issues/detail?id=510498 for the linking error. The code looks much cleaner now without sprintf. Thanks. https://codereview.chromium.org/1144163008/diff/600001/net/base/network_quali... File net/base/network_quality_estimator.cc (right): https://codereview.chromium.org/1144163008/diff/600001/net/base/network_quali... net/base/network_quality_estimator.cc:454: "RTT.Percentile" + std::string(percentile_stringified) + ".", On 2015/07/15 15:12:45, pauljensen wrote: > std::string(percentile_stringified)->IntToString(kPercentiles[i]) Done. https://codereview.chromium.org/1144163008/diff/600001/net/base/network_quali... net/base/network_quality_estimator.cc:517: static_cast<size_t>(kMaximumObservationsBufferSize)); On 2015/07/15 15:12:45, pauljensen wrote: > Why is this static_cast done on lines 517 and 525 but not 523? Removed that line, it was giving linking error. https://codereview.chromium.org/1144163008/diff/600001/net/base/network_quali... net/base/network_quality_estimator.cc:633: network_id.id = "Ethernet"; On 2015/07/15 15:12:45, pauljensen wrote: > Strikes me as a bit odd that we match Ethernet out of the cache but not other > unknown networks. Matching based on router MAC would seem nice (for Ethernet or > WiFi) but that could get complicated. I am okay with removing Ethernet. MAC or IP based matching can be complicated. Are these values already exposed somewhere in Chromium? https://codereview.chromium.org/1144163008/diff/600001/net/base/network_quali... net/base/network_quality_estimator.cc:665: CachedNetworkQualities::iterator it = On 2015/07/15 15:12:45, pauljensen wrote: > const_iterator? Done. https://codereview.chromium.org/1144163008/diff/600001/net/base/network_quali... net/base/network_quality_estimator.cc:671: NetworkQuality network_quality( On 2015/07/15 15:12:45, pauljensen wrote: > why not network_quality(it->second->network_quality())? Done. https://codereview.chromium.org/1144163008/diff/600001/net/base/network_quali... net/base/network_quality_estimator.cc:708: for (CachedNetworkQualities::iterator it = On 2015/07/15 15:12:45, pauljensen wrote: > const_iterator? Done. https://codereview.chromium.org/1144163008/diff/600001/net/base/network_quali... File net/base/network_quality_estimator.h (right): https://codereview.chromium.org/1144163008/diff/600001/net/base/network_quali... net/base/network_quality_estimator.h:115: // against local HTTP server and allows the responses smaller than On 2015/07/15 15:12:45, pauljensen wrote: > nit: "against local HTTP server and a"->". A" Done. https://codereview.chromium.org/1144163008/diff/600001/net/base/network_quali... File net/base/network_quality_estimator_unittest.cc (right): https://codereview.chromium.org/1144163008/diff/600001/net/base/network_quali... net/base/network_quality_estimator_unittest.cc:488: // No new entry should be added for (2G, "test1") since it already exists On 2015/07/15 15:12:45, pauljensen wrote: > test1->test-1 Done. https://codereview.chromium.org/1144163008/diff/600001/net/base/network_quali... net/base/network_quality_estimator_unittest.cc:505: // Reading quality of (3G, "test2") should return false. On 2015/07/15 15:12:45, pauljensen wrote: > test2->test-2 Done. https://codereview.chromium.org/1144163008/diff/600001/net/base/network_quali... net/base/network_quality_estimator_unittest.cc:537: network_name); On 2015/07/15 15:12:45, pauljensen wrote: > network_name->IntToString(i) Done. https://codereview.chromium.org/1144163008/diff/600001/net/base/network_quali... net/base/network_quality_estimator_unittest.cc:563: NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, network_name); On 2015/07/15 15:12:46, pauljensen wrote: > network_name->IntToString(i) Done. https://codereview.chromium.org/1144163008/diff/600001/net/base/network_quali... net/base/network_quality_estimator_unittest.cc:567: EXPECT_EQ(expect_present_in_cache, found) << i << "\n" << network_count; On 2015/07/15 15:12:46, pauljensen wrote: > can we elaborate on these "i << "\n" << network_count" strings or remove them? Done. 
 lgtm if "Ethernet" is removed https://codereview.chromium.org/1144163008/diff/600001/net/base/network_quali... File net/base/network_quality_estimator.cc (right): https://codereview.chromium.org/1144163008/diff/600001/net/base/network_quali... net/base/network_quality_estimator.cc:633: network_id.id = "Ethernet"; On 2015/07/15 17:33:47, tbansal1 wrote: > On 2015/07/15 15:12:45, pauljensen wrote: > > Strikes me as a bit odd that we match Ethernet out of the cache but not other > > unknown networks. Matching based on router MAC would seem nice (for Ethernet > or > > WiFi) but that could get complicated. > > I am okay with removing Ethernet. MAC or IP based matching can be complicated. > Are these values already exposed somewhere in Chromium? I don't think matching via IPs is a good idea (it's going to be 192.168.1.1 in a lot of cases that shouldn't match up). I don't know of a place where we expose the MAC address of the router. How about we remove "Ethernet" then? 
 https://codereview.chromium.org/1144163008/diff/600001/net/base/network_quali... File net/base/network_quality_estimator.cc (right): https://codereview.chromium.org/1144163008/diff/600001/net/base/network_quali... net/base/network_quality_estimator.cc:633: network_id.id = "Ethernet"; On 2015/07/15 17:44:05, pauljensen wrote: > On 2015/07/15 17:33:47, tbansal1 wrote: > > On 2015/07/15 15:12:45, pauljensen wrote: > > > Strikes me as a bit odd that we match Ethernet out of the cache but not > other > > > unknown networks. Matching based on router MAC would seem nice (for > Ethernet > > or > > > WiFi) but that could get complicated. > > > > I am okay with removing Ethernet. MAC or IP based matching can be complicated. > > Are these values already exposed somewhere in Chromium? > > I don't think matching via IPs is a good idea (it's going to be 192.168.1.1 in a > lot of cases that shouldn't match up). I don't know of a place where we expose > the MAC address of the router. > How about we remove "Ethernet" then? Done. 
 The CQ bit was checked by tbansal@chromium.org 
 The patchset sent to the CQ was uploaded after l-g-t-m from bengr@chromium.org, pauljensen@chromium.org Link to the patchset: https://codereview.chromium.org/1144163008/#ps640001 (title: "Removed Ethernet") 
 CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/1144163008/640001 
 The CQ bit was unchecked by commit-bot@chromium.org 
 Try jobs failed on following builders: mac_chromium_compile_dbg_ng on tryserver.chromium.mac (JOB_FAILED, http://build.chromium.org/p/tryserver.chromium.mac/builders/mac_chromium_comp...) 
 The CQ bit was checked by tbansal@chromium.org 
 The patchset sent to the CQ was uploaded after l-g-t-m from pauljensen@chromium.org, bengr@chromium.org Link to the patchset: https://codereview.chromium.org/1144163008/#ps660001 (title: "Change const_iterator to iterator to make MacOS compiler happy") 
 CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/1144163008/660001 
 The CQ bit was unchecked by commit-bot@chromium.org 
 Try jobs failed on following builders: mac_chromium_compile_dbg_ng on tryserver.chromium.mac (JOB_FAILED, http://build.chromium.org/p/tryserver.chromium.mac/builders/mac_chromium_comp...) 
 The CQ bit was checked by tbansal@chromium.org 
 The patchset sent to the CQ was uploaded after l-g-t-m from pauljensen@chromium.org, bengr@chromium.org Link to the patchset: https://codereview.chromium.org/1144163008/#ps680001 (title: "Add copy constructor") 
 CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/1144163008/680001 
 The CQ bit was unchecked by commit-bot@chromium.org 
 Try jobs failed on following builders: mac_chromium_compile_dbg_ng on tryserver.chromium.mac (JOB_FAILED, http://build.chromium.org/p/tryserver.chromium.mac/builders/mac_chromium_comp...) mac_chromium_rel_ng on tryserver.chromium.mac (JOB_FAILED, http://build.chromium.org/p/tryserver.chromium.mac/builders/mac_chromium_rel_...) 
 The CQ bit was checked by tbansal@chromium.org 
 The patchset sent to the CQ was uploaded after l-g-t-m from pauljensen@chromium.org, bengr@chromium.org Link to the patchset: https://codereview.chromium.org/1144163008/#ps700001 (title: "Not use scoped_ptr") 
 CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/1144163008/700001 
 The CQ bit was unchecked by commit-bot@chromium.org 
 Try jobs failed on following builders: linux_chromium_asan_rel_ng on tryserver.chromium.linux (JOB_FAILED, http://build.chromium.org/p/tryserver.chromium.linux/builders/linux_chromium_...) linux_chromium_chromeos_compile_dbg_ng on tryserver.chromium.linux (JOB_FAILED, http://build.chromium.org/p/tryserver.chromium.linux/builders/linux_chromium_...) (exceeded global retry quota) 
 The CQ bit was checked by tbansal@chromium.org 
 CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/1144163008/700001 
 
            
              
                Message was sent while issue was closed.
              
            
             Committed patchset #26 (id:700001) 
 
            
              
                Message was sent while issue was closed.
              
            
             Patchset 26 (id:??) landed as https://crrev.com/75540a59248efeb382e515971b762c17592a6ada Cr-Commit-Position: refs/heads/master@{#338923} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
