| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "content/browser/background_sync/background_sync_network_observer.h" | 5 #include "content/browser/background_sync/background_sync_network_observer.h" |
| 6 | 6 |
| 7 #include "base/location.h" |
| 8 #include "base/single_thread_task_runner.h" |
| 9 #include "base/thread_task_runner_handle.h" |
| 7 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
| 8 | 11 |
| 9 namespace content { | 12 namespace content { |
| 10 | 13 |
| 11 BackgroundSyncNetworkObserver::BackgroundSyncNetworkObserver( | 14 BackgroundSyncNetworkObserver::BackgroundSyncNetworkObserver( |
| 12 const base::Closure& network_changed_callback) | 15 const base::Closure& network_changed_callback) |
| 13 : connection_type_(net::NetworkChangeNotifier::GetConnectionType()), | 16 : connection_type_(net::NetworkChangeNotifier::GetConnectionType()), |
| 14 network_changed_callback_(network_changed_callback) { | 17 network_changed_callback_(network_changed_callback) { |
| 15 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 18 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 16 | 19 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 40 return connection_type_ != net::NetworkChangeNotifier::CONNECTION_NONE; | 43 return connection_type_ != net::NetworkChangeNotifier::CONNECTION_NONE; |
| 41 } | 44 } |
| 42 | 45 |
| 43 NOTREACHED(); | 46 NOTREACHED(); |
| 44 return false; | 47 return false; |
| 45 } | 48 } |
| 46 | 49 |
| 47 void BackgroundSyncNetworkObserver::NotifyNetworkChanged() { | 50 void BackgroundSyncNetworkObserver::NotifyNetworkChanged() { |
| 48 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 51 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 49 | 52 |
| 50 base::MessageLoop::current()->PostTask(FROM_HERE, network_changed_callback_); | 53 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
| 54 network_changed_callback_); |
| 51 } | 55 } |
| 52 | 56 |
| 53 void BackgroundSyncNetworkObserver::OnNetworkChanged( | 57 void BackgroundSyncNetworkObserver::OnNetworkChanged( |
| 54 net::NetworkChangeNotifier::ConnectionType connection_type) { | 58 net::NetworkChangeNotifier::ConnectionType connection_type) { |
| 55 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 59 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 56 | 60 |
| 57 if (connection_type == connection_type_) | 61 if (connection_type == connection_type_) |
| 58 return; | 62 return; |
| 59 | 63 |
| 60 connection_type_ = connection_type; | 64 connection_type_ = connection_type; |
| 61 NotifyNetworkChanged(); | 65 NotifyNetworkChanged(); |
| 62 } | 66 } |
| 63 | 67 |
| 64 } // namespace content | 68 } // namespace content |
| OLD | NEW |