Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / chromeos / net / network_portal_notification_controller.h
bloba4992b075eb391e6a7454496abba6a60ad911a76
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_CHROMEOS_NET_NETWORK_PORTAL_NOTIFICATION_CONTROLLER_H_
6 #define CHROME_BROWSER_CHROMEOS_NET_NETWORK_PORTAL_NOTIFICATION_CONTROLLER_H_
8 #include <string>
10 #include "base/macros.h"
11 #include "base/memory/weak_ptr.h"
12 #include "chromeos/network/portal_detector/network_portal_detector.h"
13 #include "ui/message_center/notification.h"
15 namespace extensions {
17 class Extension;
18 class NetworkingConfigService;
20 } // namespace extensions
22 namespace chromeos {
24 class NetworkState;
25 class NetworkPortalWebDialog;
27 class NetworkPortalNotificationController {
28 public:
29 // The values of these metrics are being used for UMA gathering, so it is
30 // important that they don't change between releases.
31 enum NotificationMetric {
32 NOTIFICATION_METRIC_DISPLAYED = 0,
34 // This value is no longer used by is still kept here just for
35 // unify with histograms.xml.
36 NOTIFICATION_METRIC_ERROR = 1,
38 NOTIFICATION_METRIC_COUNT = 2
41 enum UserActionMetric {
42 USER_ACTION_METRIC_CLICKED,
43 USER_ACTION_METRIC_CLOSED,
44 USER_ACTION_METRIC_IGNORED,
45 USER_ACTION_METRIC_COUNT
48 static const int kUseExtensionButtonIndex;
49 static const int kOpenPortalButtonIndex;
51 static const char kNotificationId[];
53 static const char kNotificationMetric[];
54 static const char kUserActionMetric[];
56 NetworkPortalNotificationController();
57 ~NetworkPortalNotificationController();
59 // |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
61 // a finished authentication).
62 // |retry_detection_callback| will not be called after this controller is
63 // destroyed.
64 void set_retry_detection_callback(
65 const base::Closure& retry_detection_callback) {
66 retry_detection_callback_ = retry_detection_callback;
69 void DefaultNetworkChanged(const NetworkState* network);
71 void OnPortalDetectionCompleted(
72 const NetworkState* network,
73 const NetworkPortalDetector::CaptivePortalState& state);
75 // Creates NetworkPortalWebDialog.
76 void ShowDialog();
78 // Destroys NetworkPortalWebDialog.
79 void CloseDialog();
81 // NULLifies reference to the active dialog.
82 void OnDialogDestroyed(const NetworkPortalWebDialog* dialog);
84 // Called if an extension has successfully finished authentication to the
85 // previously detected captive portal.
86 void OnExtensionFinishedAuthentication();
88 // Ignores "No network" errors in browser tests.
89 void SetIgnoreNoNetworkForTesting();
91 // Browser tests should be able to verify that NetworkPortalWebDialog is
92 // shown.
93 const NetworkPortalWebDialog* GetDialogForTesting() const;
95 private:
96 // 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
98 // browser.
99 scoped_ptr<message_center::Notification>
100 CreateDefaultCaptivePortalNotification(const NetworkState* network);
102 // Creates an advanced captive portal notification informing the user that a
103 // captive portal has been detected and an extension has registered to perform
104 // captive portal authentication for that network. Gives the user the choice
105 // to either authenticate using that extension or open the captive portal
106 // login page in the browser.
107 scoped_ptr<message_center::Notification>
108 CreateCaptivePortalNotificationForExtension(
109 const NetworkState* network,
110 extensions::NetworkingConfigService* networking_config_service,
111 const extensions::Extension* extension);
113 // Constructs a notification to inform the user that a captive portal has been
114 // detected.
115 scoped_ptr<message_center::Notification> GetNotification(
116 const NetworkState* network,
117 const NetworkPortalDetector::CaptivePortalState& state);
119 // Last network path for which notification was displayed.
120 std::string last_network_path_;
122 // Currently displayed authorization dialog, or NULL if none.
123 NetworkPortalWebDialog* dialog_;
125 // Do not close Portal Login dialog on "No network" error in browser tests.
126 bool ignore_no_network_for_testing_;
128 // This is called if the controller learns about a potential change of the
129 // captive portal.
130 base::Closure retry_detection_callback_;
132 base::WeakPtrFactory<NetworkPortalNotificationController> weak_factory_;
134 DISALLOW_COPY_AND_ASSIGN(NetworkPortalNotificationController);
137 } // namespace chromeos
139 #endif // CHROME_BROWSER_CHROMEOS_NET_NETWORK_PORTAL_NOTIFICATION_CONTROLLER_H_