OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/net/nqe/ui_network_quality_estimator_service.h" | 5 #include "chrome/browser/net/nqe/ui_network_quality_estimator_service.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
9 #include "chrome/browser/io_thread.h" | 9 #include "chrome/browser/io_thread.h" |
10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 service_, type)); | 57 service_, type)); |
58 } | 58 } |
59 | 59 |
60 private: | 60 private: |
61 base::WeakPtr<UINetworkQualityEstimatorService> service_; | 61 base::WeakPtr<UINetworkQualityEstimatorService> service_; |
62 net::NetworkQualityEstimator* network_quality_estimator_; | 62 net::NetworkQualityEstimator* network_quality_estimator_; |
63 | 63 |
64 DISALLOW_COPY_AND_ASSIGN(IONetworkQualityObserver); | 64 DISALLOW_COPY_AND_ASSIGN(IONetworkQualityObserver); |
65 }; | 65 }; |
66 | 66 |
67 UINetworkQualityEstimatorService::UINetworkQualityEstimatorService( | 67 UINetworkQualityEstimatorService::UINetworkQualityEstimatorService() |
68 Profile* profile) | |
69 : type_(net::NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_UNKNOWN), | 68 : type_(net::NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_UNKNOWN), |
70 io_observer_(nullptr), | 69 io_observer_(nullptr), |
71 weak_factory_(this) { | 70 weak_factory_(this) { |
72 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 71 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 72 // If this is running in a context without an IOThread, don't try to create |
| 73 // the IO object. |
| 74 if (!g_browser_process->io_thread()) |
| 75 return; |
73 io_observer_ = new IONetworkQualityObserver(weak_factory_.GetWeakPtr()); | 76 io_observer_ = new IONetworkQualityObserver(weak_factory_.GetWeakPtr()); |
74 content::BrowserThread::PostTask( | 77 content::BrowserThread::PostTask( |
75 content::BrowserThread::IO, FROM_HERE, | 78 content::BrowserThread::IO, FROM_HERE, |
76 base::Bind(&IONetworkQualityObserver::InitializeOnIOThread, | 79 base::Bind(&IONetworkQualityObserver::InitializeOnIOThread, |
77 base::Unretained(io_observer_), | 80 base::Unretained(io_observer_), |
78 g_browser_process->io_thread())); | 81 g_browser_process->io_thread())); |
79 } | 82 } |
80 | 83 |
81 UINetworkQualityEstimatorService::~UINetworkQualityEstimatorService() { | 84 UINetworkQualityEstimatorService::~UINetworkQualityEstimatorService() { |
82 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 85 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
83 } | 86 } |
84 | 87 |
85 void UINetworkQualityEstimatorService::Shutdown() { | 88 void UINetworkQualityEstimatorService::Shutdown() { |
86 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 89 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
87 weak_factory_.InvalidateWeakPtrs(); | 90 weak_factory_.InvalidateWeakPtrs(); |
88 } | 91 } |
89 | 92 |
90 void UINetworkQualityEstimatorService::EffectiveConnectionTypeChanged( | 93 void UINetworkQualityEstimatorService::EffectiveConnectionTypeChanged( |
91 net::NetworkQualityEstimator::EffectiveConnectionType type) { | 94 net::NetworkQualityEstimator::EffectiveConnectionType type) { |
92 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 95 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
93 type_ = type; | 96 type_ = type; |
94 } | 97 } |
95 | 98 |
96 net::NetworkQualityEstimator::EffectiveConnectionType | 99 net::NetworkQualityEstimator::EffectiveConnectionType |
97 UINetworkQualityEstimatorService::GetEffectiveConnectionType() const { | 100 UINetworkQualityEstimatorService::GetEffectiveConnectionType() const { |
98 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 101 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
99 return type_; | 102 return type_; |
100 } | 103 } |
OLD | NEW |