OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef CHROME_BROWSER_CHROMEOS_NET_NETWORK_PORTAL_NOTIFICATION_CONTROLLER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_NET_NETWORK_PORTAL_NOTIFICATION_CONTROLLER_H_ |
6 #define CHROME_BROWSER_CHROMEOS_NET_NETWORK_PORTAL_NOTIFICATION_CONTROLLER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_NET_NETWORK_PORTAL_NOTIFICATION_CONTROLLER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 12 #include "chromeos/network/network_state_handler_observer.h" |
12 #include "chromeos/network/portal_detector/network_portal_detector.h" | 13 #include "chromeos/network/portal_detector/network_portal_detector.h" |
13 #include "ui/message_center/notification.h" | 14 #include "ui/message_center/notification.h" |
14 | 15 |
15 namespace extensions { | 16 namespace extensions { |
16 | |
17 class Extension; | 17 class Extension; |
18 class NetworkingConfigService; | 18 class NetworkingConfigService; |
19 | 19 } |
20 } // namespace extensions | |
21 | 20 |
22 namespace chromeos { | 21 namespace chromeos { |
23 | 22 |
24 class NetworkState; | 23 class NetworkState; |
25 class NetworkPortalWebDialog; | 24 class NetworkPortalWebDialog; |
| 25 class NetworkPortalNotificationControllerTest; |
26 | 26 |
27 class NetworkPortalNotificationController { | 27 class NetworkPortalNotificationController |
| 28 : public NetworkStateHandlerObserver, |
| 29 public NetworkPortalDetector::Observer { |
28 public: | 30 public: |
29 // The values of these metrics are being used for UMA gathering, so it is | 31 // The values of these metrics are being used for UMA gathering, so it is |
30 // important that they don't change between releases. | 32 // important that they don't change between releases. |
31 enum NotificationMetric { | 33 enum NotificationMetric { |
32 NOTIFICATION_METRIC_DISPLAYED = 0, | 34 NOTIFICATION_METRIC_DISPLAYED = 0, |
33 | 35 |
34 // This value is no longer used by is still kept here just for | 36 // This value is no longer used by is still kept here just for |
35 // unify with histograms.xml. | 37 // unify with histograms.xml. |
36 NOTIFICATION_METRIC_ERROR = 1, | 38 NOTIFICATION_METRIC_ERROR = 1, |
37 | 39 |
38 NOTIFICATION_METRIC_COUNT = 2 | 40 NOTIFICATION_METRIC_COUNT = 2 |
39 }; | 41 }; |
40 | 42 |
41 enum UserActionMetric { | 43 enum UserActionMetric { |
42 USER_ACTION_METRIC_CLICKED, | 44 USER_ACTION_METRIC_CLICKED, |
43 USER_ACTION_METRIC_CLOSED, | 45 USER_ACTION_METRIC_CLOSED, |
44 USER_ACTION_METRIC_IGNORED, | 46 USER_ACTION_METRIC_IGNORED, |
45 USER_ACTION_METRIC_COUNT | 47 USER_ACTION_METRIC_COUNT |
46 }; | 48 }; |
47 | 49 |
48 static const int kUseExtensionButtonIndex; | 50 static const int kUseExtensionButtonIndex; |
49 static const int kOpenPortalButtonIndex; | 51 static const int kOpenPortalButtonIndex; |
50 | 52 |
51 static const char kNotificationId[]; | 53 static const char kNotificationId[]; |
52 | 54 |
53 static const char kNotificationMetric[]; | 55 static const char kNotificationMetric[]; |
54 static const char kUserActionMetric[]; | 56 static const char kUserActionMetric[]; |
55 | 57 |
56 NetworkPortalNotificationController(); | 58 explicit NetworkPortalNotificationController( |
57 ~NetworkPortalNotificationController(); | 59 NetworkPortalDetector* network_portal_dectector); |
| 60 ~NetworkPortalNotificationController() override; |
58 | 61 |
59 // |retry_detection_callback| will be called if the controller learns about a | 62 // |retry_detection_callback| will be called if the controller learns about a |
60 // potential change of the captive portal (e.g. if an extension notifies about | 63 // potential change of the captive portal (e.g. if an extension notifies about |
61 // a finished authentication). | 64 // a finished authentication). |
62 // |retry_detection_callback| will not be called after this controller is | 65 // |retry_detection_callback| will not be called after this controller is |
63 // destroyed. | 66 // destroyed. |
64 void set_retry_detection_callback( | 67 void set_retry_detection_callback( |
65 const base::Closure& retry_detection_callback) { | 68 const base::Closure& retry_detection_callback) { |
66 retry_detection_callback_ = retry_detection_callback; | 69 retry_detection_callback_ = retry_detection_callback; |
67 } | 70 } |
68 | 71 |
69 void DefaultNetworkChanged(const NetworkState* network); | |
70 | |
71 void OnPortalDetectionCompleted( | |
72 const NetworkState* network, | |
73 const NetworkPortalDetector::CaptivePortalState& state); | |
74 | |
75 // Creates NetworkPortalWebDialog. | 72 // Creates NetworkPortalWebDialog. |
76 void ShowDialog(); | 73 void ShowDialog(); |
77 | 74 |
78 // Destroys NetworkPortalWebDialog. | 75 // Destroys NetworkPortalWebDialog. |
79 void CloseDialog(); | 76 void CloseDialog(); |
80 | 77 |
81 // NULLifies reference to the active dialog. | 78 // NULLifies reference to the active dialog. |
82 void OnDialogDestroyed(const NetworkPortalWebDialog* dialog); | 79 void OnDialogDestroyed(const NetworkPortalWebDialog* dialog); |
83 | 80 |
84 // Called if an extension has successfully finished authentication to the | 81 // Called if an extension has successfully finished authentication to the |
85 // previously detected captive portal. | 82 // previously detected captive portal. |
86 void OnExtensionFinishedAuthentication(); | 83 void OnExtensionFinishedAuthentication(); |
87 | 84 |
88 // Ignores "No network" errors in browser tests. | 85 // Ignores "No network" errors in browser tests. |
89 void SetIgnoreNoNetworkForTesting(); | 86 void SetIgnoreNoNetworkForTesting(); |
90 | 87 |
91 // Browser tests should be able to verify that NetworkPortalWebDialog is | 88 // Browser tests should be able to verify that NetworkPortalWebDialog is |
92 // shown. | 89 // shown. |
93 const NetworkPortalWebDialog* GetDialogForTesting() const; | 90 const NetworkPortalWebDialog* GetDialogForTesting() const; |
94 | 91 |
95 private: | 92 private: |
| 93 friend NetworkPortalNotificationControllerTest; |
| 94 |
96 // Creates the default notification informing the user that a captive portal | 95 // Creates the default notification informing the user that a captive portal |
97 // has been detected. On click the captive portal login page is opened in the | 96 // has been detected. On click the captive portal login page is opened in the |
98 // browser. | 97 // browser. |
99 scoped_ptr<message_center::Notification> | 98 scoped_ptr<message_center::Notification> |
100 CreateDefaultCaptivePortalNotification(const NetworkState* network); | 99 CreateDefaultCaptivePortalNotification(const NetworkState* network); |
101 | 100 |
102 // Creates an advanced captive portal notification informing the user that a | 101 // Creates an advanced captive portal notification informing the user that a |
103 // captive portal has been detected and an extension has registered to perform | 102 // captive portal has been detected and an extension has registered to perform |
104 // captive portal authentication for that network. Gives the user the choice | 103 // captive portal authentication for that network. Gives the user the choice |
105 // to either authenticate using that extension or open the captive portal | 104 // to either authenticate using that extension or open the captive portal |
106 // login page in the browser. | 105 // login page in the browser. |
107 scoped_ptr<message_center::Notification> | 106 scoped_ptr<message_center::Notification> |
108 CreateCaptivePortalNotificationForExtension( | 107 CreateCaptivePortalNotificationForExtension( |
109 const NetworkState* network, | 108 const NetworkState* network, |
110 extensions::NetworkingConfigService* networking_config_service, | 109 extensions::NetworkingConfigService* networking_config_service, |
111 const extensions::Extension* extension); | 110 const extensions::Extension* extension); |
112 | 111 |
113 // Constructs a notification to inform the user that a captive portal has been | 112 // Constructs a notification to inform the user that a captive portal has been |
114 // detected. | 113 // detected. |
115 scoped_ptr<message_center::Notification> GetNotification( | 114 scoped_ptr<message_center::Notification> GetNotification( |
116 const NetworkState* network, | 115 const NetworkState* network, |
117 const NetworkPortalDetector::CaptivePortalState& state); | 116 const NetworkPortalDetector::CaptivePortalState& state); |
118 | 117 |
| 118 // NetworkStateHandlerObserver: |
| 119 void DefaultNetworkChanged(const NetworkState* network) override; |
| 120 |
| 121 // NetworkPortalDetector::Observer: |
| 122 void OnPortalDetectionCompleted( |
| 123 const NetworkState* network, |
| 124 const NetworkPortalDetector::CaptivePortalState& state) override; |
| 125 |
119 // Last network path for which notification was displayed. | 126 // Last network path for which notification was displayed. |
120 std::string last_network_path_; | 127 std::string last_network_path_; |
121 | 128 |
| 129 // Backpointer to owner. |
| 130 NetworkPortalDetector* network_portal_detector_ = nullptr; |
| 131 |
122 // Currently displayed authorization dialog, or NULL if none. | 132 // Currently displayed authorization dialog, or NULL if none. |
123 NetworkPortalWebDialog* dialog_; | 133 NetworkPortalWebDialog* dialog_ = nullptr; |
124 | 134 |
125 // Do not close Portal Login dialog on "No network" error in browser tests. | 135 // Do not close Portal Login dialog on "No network" error in browser tests. |
126 bool ignore_no_network_for_testing_; | 136 bool ignore_no_network_for_testing_ = false; |
127 | 137 |
128 // This is called if the controller learns about a potential change of the | 138 // This is called if the controller learns about a potential change of the |
129 // captive portal. | 139 // captive portal. |
130 base::Closure retry_detection_callback_; | 140 base::Closure retry_detection_callback_; |
131 | 141 |
132 base::WeakPtrFactory<NetworkPortalNotificationController> weak_factory_; | 142 base::WeakPtrFactory<NetworkPortalNotificationController> weak_factory_; |
133 | 143 |
134 DISALLOW_COPY_AND_ASSIGN(NetworkPortalNotificationController); | 144 DISALLOW_COPY_AND_ASSIGN(NetworkPortalNotificationController); |
135 }; | 145 }; |
136 | 146 |
137 } // namespace chromeos | 147 } // namespace chromeos |
138 | 148 |
139 #endif // CHROME_BROWSER_CHROMEOS_NET_NETWORK_PORTAL_NOTIFICATION_CONTROLLER_H_ | 149 #endif // CHROME_BROWSER_CHROMEOS_NET_NETWORK_PORTAL_NOTIFICATION_CONTROLLER_H_ |
OLD | NEW |