Check USB device path access when prompting users to select a device.
[chromium-blink-merge.git] / chrome / browser / chromeos / net / network_portal_notification_controller.h
blob8b0c97a55b898550042a1ec16d46cc6f5c6bab30
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 base::SupportsWeakPtr<NetworkPortalNotificationController> {
29 public:
30 // The values of these metrics are being used for UMA gathering, so it is
31 // important that they don't change between releases.
32 enum NotificationMetric {
33 NOTIFICATION_METRIC_DISPLAYED = 0,
35 // This value is no longer used by is still kept here just for
36 // unify with histograms.xml.
37 NOTIFICATION_METRIC_ERROR = 1,
39 NOTIFICATION_METRIC_COUNT = 2
42 enum UserActionMetric {
43 USER_ACTION_METRIC_CLICKED,
44 USER_ACTION_METRIC_CLOSED,
45 USER_ACTION_METRIC_IGNORED,
46 USER_ACTION_METRIC_COUNT
49 static const int kUseExtensionButtonIndex;
50 static const int kOpenPortalButtonIndex;
52 static const char kNotificationId[];
54 static const char kNotificationMetric[];
55 static const char kUserActionMetric[];
57 NetworkPortalNotificationController();
58 ~NetworkPortalNotificationController();
60 // |retry_detection_callback| will be called if the controller learns about a
61 // potential change of the captive portal (e.g. if an extension notifies about
62 // a finished authentication).
63 // |retry_detection_callback| will not be called after this controller is
64 // destroyed.
65 void set_retry_detection_callback(
66 const base::Closure& retry_detection_callback) {
67 retry_detection_callback_ = retry_detection_callback;
70 void DefaultNetworkChanged(const NetworkState* network);
72 void OnPortalDetectionCompleted(
73 const NetworkState* network,
74 const NetworkPortalDetector::CaptivePortalState& state);
76 // Creates NetworkPortalWebDialog.
77 void ShowDialog();
79 // Destroys NetworkPortalWebDialog.
80 void CloseDialog();
82 // NULLifies reference to the active dialog.
83 void OnDialogDestroyed(const NetworkPortalWebDialog* dialog);
85 // Called if an extension has successfully finished authentication to the
86 // previously detected captive portal.
87 void OnExtensionFinishedAuthentication();
89 // Ignores "No network" errors in browser tests.
90 void SetIgnoreNoNetworkForTesting();
92 // Browser tests should be able to verify that NetworkPortalWebDialog is
93 // shown.
94 const NetworkPortalWebDialog* GetDialogForTesting() const;
96 private:
97 // Creates the default notification informing the user that a captive portal
98 // has been detected. On click the captive portal login page is opened in the
99 // browser.
100 scoped_ptr<message_center::Notification>
101 CreateDefaultCaptivePortalNotification(const NetworkState* network);
103 // Creates an advanced captive portal notification informing the user that a
104 // captive portal has been detected and an extension has registered to perform
105 // captive portal authentication for that network. Gives the user the choice
106 // to either authenticate using that extension or open the captive portal
107 // login page in the browser.
108 scoped_ptr<message_center::Notification>
109 CreateCaptivePortalNotificationForExtension(
110 const NetworkState* network,
111 extensions::NetworkingConfigService* networking_config_service,
112 const extensions::Extension* extension);
114 // Constructs a notification to inform the user that a captive portal has been
115 // detected.
116 scoped_ptr<message_center::Notification> GetNotification(
117 const NetworkState* network,
118 const NetworkPortalDetector::CaptivePortalState& state);
120 // Last network path for which notification was displayed.
121 std::string last_network_path_;
123 // Currently displayed authorization dialog, or NULL if none.
124 NetworkPortalWebDialog* dialog_;
126 // Do not close Portal Login dialog on "No network" error in browser tests.
127 bool ignore_no_network_for_testing_;
129 // This is called if the controller learns about a potential change of the
130 // captive portal.
131 base::Closure retry_detection_callback_;
133 DISALLOW_COPY_AND_ASSIGN(NetworkPortalNotificationController);
136 } // namespace chromeos
138 #endif // CHROME_BROWSER_CHROMEOS_NET_NETWORK_PORTAL_NOTIFICATION_CONTROLLER_H_