• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2012 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.
4 
5 #ifndef CHROME_BROWSER_UI_NETWORK_PROFILE_BUBBLE_H_
6 #define CHROME_BROWSER_UI_NETWORK_PROFILE_BUBBLE_H_
7 
8 #include "base/basictypes.h"
9 
10 class Browser;
11 class Profile;
12 
13 namespace base {
14 class FilePath;
15 }
16 
17 namespace user_prefs {
18 class PrefRegistrySyncable;
19 }
20 
21 // This class will try to detect if the profile is on a network share and if
22 // this is the case notify the user with an info bubble.
23 class NetworkProfileBubble {
24  public:
25   enum MetricNetworkedProfileCheck {
26    // Check was suppressed by command line flag.
27    METRIC_CHECK_SUPPRESSED,
28    // WTSQuerySessionInformation call failed.
29    METRIC_CHECK_FAILED,
30    // File access in profile dir failed.
31    METRIC_CHECK_IO_FAILED,
32 
33    // Profile on a network share detected.
34    METRIC_PROFILE_ON_NETWORK,
35    // Profile not on a network share detected.
36    METRIC_PROFILE_NOT_ON_NETWORK,
37 
38    // Check was suppressed because of remote session.
39    METRIC_REMOTE_SESSION,
40 
41    // User has clicked learn more on the notification bubble.
42    METRIC_LEARN_MORE_CLICKED,
43    // User has clicked OK on the notification bubble.
44    METRIC_ACKNOWLEDGED,
45 
46    METRIC_NETWORKED_PROFILE_CHECK_SIZE  // Must be the last.
47   };
48 
49   // Returns true if the check for network located profile should be done. This
50   // test is only performed up to |kMaxWarnings| times in a row and then
51   // repeated after a period of silence that lasts |kSilenceDurationDays| days.
52   static bool ShouldCheckNetworkProfile(Profile* profile);
53 
54   // Verifies that the profile folder is not located on a network share, and if
55   // it is shows the warning bubble to the user.
56   static void CheckNetworkProfile(const base::FilePath& profile_folder);
57 
58   // Shows the notification bubble using the provided |browser|.
59   static void ShowNotification(Browser* browser);
60 
61   static void SetNotificationShown(bool shown);
62 
63   // Register the pref that controls whether the bubble should be shown anymore.
64   static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
65 
66   // Helper function wrapping the UMA_HISTOGRAM_ENUMERATION macro.
67   static void RecordUmaEvent(MetricNetworkedProfileCheck event);
68 
69  private:
70   // This function creates the notification bubble, attaches it to the
71   // |anchor| View and then shows it to the user.
72   static void NotifyNetworkProfileDetected();
73 
74   // Set to true once the notification check has been performed to avoid showing
75   // the notification more than once per browser run.
76   // This flag is not thread-safe and should only be accessed on the UI thread!
77   static bool notification_shown_;
78 
79   DISALLOW_IMPLICIT_CONSTRUCTORS(NetworkProfileBubble);
80 };
81 
82 #endif  // CHROME_BROWSER_UI_NETWORK_PROFILE_BUBBLE_H_
83