Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Side by Side Diff: content/browser/background_sync/background_sync_network_observer.cc

Issue 1383663004: Reland of [Background Sync] Trigger Background Sync events when Chrome is backgrounded on Android (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Don't crash in embedded webview; check permissions before creating NCNAD Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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" 7 #include "base/location.h"
8 #include "base/single_thread_task_runner.h" 8 #include "base/single_thread_task_runner.h"
9 #include "base/thread_task_runner_handle.h" 9 #include "base/thread_task_runner_handle.h"
10 #include "content/public/browser/browser_thread.h" 10 #include "content/public/browser/browser_thread.h"
11 11
12 namespace content { 12 namespace content {
13 13
14 // static
15 bool BackgroundSyncNetworkObserver::ignore_network_change_notifier_ = false;
16
17 // static
18 void BackgroundSyncNetworkObserver::SetIgnoreNetworkChangeNotifierForTests(
19 bool ignore) {
20 ignore_network_change_notifier_ = ignore;
21 }
22
14 BackgroundSyncNetworkObserver::BackgroundSyncNetworkObserver( 23 BackgroundSyncNetworkObserver::BackgroundSyncNetworkObserver(
15 const base::Closure& network_changed_callback) 24 const base::Closure& network_changed_callback)
16 : connection_type_(net::NetworkChangeNotifier::GetConnectionType()), 25 : connection_type_(net::NetworkChangeNotifier::GetConnectionType()),
17 network_changed_callback_(network_changed_callback) { 26 network_changed_callback_(network_changed_callback) {
18 DCHECK_CURRENTLY_ON(BrowserThread::IO); 27 DCHECK_CURRENTLY_ON(BrowserThread::IO);
19 28
20 net::NetworkChangeNotifier::AddNetworkChangeObserver(this); 29 net::NetworkChangeNotifier::AddNetworkChangeObserver(this);
21 } 30 }
22 31
23 BackgroundSyncNetworkObserver::~BackgroundSyncNetworkObserver() { 32 BackgroundSyncNetworkObserver::~BackgroundSyncNetworkObserver() {
(...skipping 16 matching lines...) Expand all
40 !net::NetworkChangeNotifier::IsConnectionCellular( 49 !net::NetworkChangeNotifier::IsConnectionCellular(
41 connection_type_); 50 connection_type_);
42 case NETWORK_STATE_ONLINE: 51 case NETWORK_STATE_ONLINE:
43 return connection_type_ != net::NetworkChangeNotifier::CONNECTION_NONE; 52 return connection_type_ != net::NetworkChangeNotifier::CONNECTION_NONE;
44 } 53 }
45 54
46 NOTREACHED(); 55 NOTREACHED();
47 return false; 56 return false;
48 } 57 }
49 58
50 void BackgroundSyncNetworkObserver::NotifyNetworkChanged() {
51 DCHECK_CURRENTLY_ON(BrowserThread::IO);
52
53 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
54 network_changed_callback_);
55 }
56
57 void BackgroundSyncNetworkObserver::OnNetworkChanged( 59 void BackgroundSyncNetworkObserver::OnNetworkChanged(
58 net::NetworkChangeNotifier::ConnectionType connection_type) { 60 net::NetworkChangeNotifier::ConnectionType connection_type) {
59 DCHECK_CURRENTLY_ON(BrowserThread::IO); 61 DCHECK_CURRENTLY_ON(BrowserThread::IO);
60 62
63 if (ignore_network_change_notifier_)
64 return;
65 NotifyManagerIfNetworkChanged(connection_type);
66 }
67
68 void BackgroundSyncNetworkObserver::NotifyManagerIfNetworkChanged(
69 net::NetworkChangeNotifier::ConnectionType connection_type) {
70 DCHECK_CURRENTLY_ON(BrowserThread::IO);
61 if (connection_type == connection_type_) 71 if (connection_type == connection_type_)
62 return; 72 return;
63 73
64 connection_type_ = connection_type; 74 connection_type_ = connection_type;
65 NotifyNetworkChanged(); 75 NotifyNetworkChanged();
66 } 76 }
67 77
78 void BackgroundSyncNetworkObserver::NotifyNetworkChanged() {
79 DCHECK_CURRENTLY_ON(BrowserThread::IO);
80
81 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
82 network_changed_callback_);
83 }
84
68 } // namespace content 85 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698