OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/web_resource/resource_request_allowed_notifier.h" | 5 #include "chrome/browser/web_resource/resource_request_allowed_notifier.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "chrome/common/chrome_switches.h" | 8 #include "chrome/common/chrome_switches.h" |
9 | 9 |
10 ResourceRequestAllowedNotifier::ResourceRequestAllowedNotifier() | 10 ResourceRequestAllowedNotifier::ResourceRequestAllowedNotifier() |
(...skipping 27 matching lines...) Expand all Loading... |
38 | 38 |
39 bool ResourceRequestAllowedNotifier::ResourceRequestsAllowed() { | 39 bool ResourceRequestAllowedNotifier::ResourceRequestsAllowed() { |
40 if (CommandLine::ForCurrentProcess()->HasSwitch( | 40 if (CommandLine::ForCurrentProcess()->HasSwitch( |
41 switches::kDisableBackgroundNetworking)) { | 41 switches::kDisableBackgroundNetworking)) { |
42 return false; | 42 return false; |
43 } | 43 } |
44 | 44 |
45 // The observer requested permission. Return the current criteria state and | 45 // The observer requested permission. Return the current criteria state and |
46 // set a flag to remind this class to notify the observer once the criteria | 46 // set a flag to remind this class to notify the observer once the criteria |
47 // is met. | 47 // is met. |
48 observer_requested_permission_ = true; | 48 observer_requested_permission_ = waiting_for_user_to_accept_eula_ || |
49 return !waiting_for_user_to_accept_eula_ && !waiting_for_network_; | 49 waiting_for_network_; |
| 50 return !observer_requested_permission_; |
50 } | 51 } |
51 | 52 |
52 void ResourceRequestAllowedNotifier::SetWaitingForNetworkForTesting( | 53 void ResourceRequestAllowedNotifier::SetWaitingForNetworkForTesting( |
53 bool waiting) { | 54 bool waiting) { |
54 waiting_for_network_ = waiting; | 55 waiting_for_network_ = waiting; |
55 } | 56 } |
56 | 57 |
57 void ResourceRequestAllowedNotifier::SetWaitingForEulaForTesting( | 58 void ResourceRequestAllowedNotifier::SetWaitingForEulaForTesting( |
58 bool waiting) { | 59 bool waiting) { |
59 waiting_for_user_to_accept_eula_ = waiting; | 60 waiting_for_user_to_accept_eula_ = waiting; |
60 } | 61 } |
61 | 62 |
| 63 void ResourceRequestAllowedNotifier::SetObserverRequestedForTesting( |
| 64 bool requested) { |
| 65 observer_requested_permission_ = requested; |
| 66 } |
| 67 |
62 void ResourceRequestAllowedNotifier::MaybeNotifyObserver() { | 68 void ResourceRequestAllowedNotifier::MaybeNotifyObserver() { |
63 // Need to ensure that all criteria are met before notifying observers. | 69 // Need to ensure that all criteria are met before notifying observers. |
64 if (observer_requested_permission_ && ResourceRequestsAllowed()) { | 70 if (observer_requested_permission_ && ResourceRequestsAllowed()) { |
65 DVLOG(1) << "Notifying observer of state change."; | 71 DVLOG(1) << "Notifying observer of state change."; |
66 observer_->OnResourceRequestsAllowed(); | 72 observer_->OnResourceRequestsAllowed(); |
67 // Reset this so the observer is not informed again unless they check | 73 // Reset this so the observer is not informed again unless they check |
68 // ResourceRequestsAllowed again. | 74 // ResourceRequestsAllowed again. |
69 observer_requested_permission_ = false; | 75 observer_requested_permission_ = false; |
70 } | 76 } |
71 } | 77 } |
(...skipping 17 matching lines...) Expand all Loading... |
89 // network to reconnect, and new network state is actually available. This | 95 // network to reconnect, and new network state is actually available. This |
90 // prevents the notifier from notifying the observer if the notifier was never | 96 // prevents the notifier from notifying the observer if the notifier was never |
91 // waiting on the network, or if the network changes from one online state | 97 // waiting on the network, or if the network changes from one online state |
92 // to another (for example, Wifi to 3G, or Wifi to Wifi, if the network were | 98 // to another (for example, Wifi to 3G, or Wifi to Wifi, if the network were |
93 // flaky). | 99 // flaky). |
94 if (waiting_for_network_ && | 100 if (waiting_for_network_ && |
95 type != net::NetworkChangeNotifier::CONNECTION_NONE) { | 101 type != net::NetworkChangeNotifier::CONNECTION_NONE) { |
96 waiting_for_network_ = false; | 102 waiting_for_network_ = false; |
97 DVLOG(1) << "Network came back online."; | 103 DVLOG(1) << "Network came back online."; |
98 MaybeNotifyObserver(); | 104 MaybeNotifyObserver(); |
| 105 } else if (!waiting_for_network_ && |
| 106 type == net::NetworkChangeNotifier::CONNECTION_NONE) { |
| 107 waiting_for_network_ = true; |
| 108 DVLOG(1) << "Network went offline."; |
99 } | 109 } |
100 } | 110 } |
OLD | NEW |