network_profile_bubble.h revision 2a99a7e74a7f215066514fe81d2bfa6639d9eddd
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef CHROME_BROWSER_UI_NETWORK_PROFILE_BUBBLE_H_
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define CHROME_BROWSER_UI_NETWORK_PROFILE_BUBBLE_H_
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/basictypes.h"
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Browser;
112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class PrefRegistrySyncable;
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Profile;
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace base {
152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class FilePath;
162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This class will try to detect if the profile is on a network share and if
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// this is the case notify the user with an info bubble.
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class NetworkProfileBubble {
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  enum MetricNetworkedProfileCheck {
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   // Check was suppressed by command line flag.
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   METRIC_CHECK_SUPPRESSED,
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   // WTSQuerySessionInformation call failed.
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   METRIC_CHECK_FAILED,
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   // File access in profile dir failed.
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   METRIC_CHECK_IO_FAILED,
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   // Profile on a network share detected.
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   METRIC_PROFILE_ON_NETWORK,
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   // Profile not on a network share detected.
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   METRIC_PROFILE_NOT_ON_NETWORK,
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   // Check was suppressed because of remote session.
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   METRIC_REMOTE_SESSION,
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   // User has clicked learn more on the notification bubble.
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   METRIC_LEARN_MORE_CLICKED,
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   // User has clicked OK on the notification bubble.
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   METRIC_ACKNOWLEDGED,
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   METRIC_NETWORKED_PROFILE_CHECK_SIZE  // Must be the last.
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns true if the check for network located profile should be done. This
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // test is only performed up to |kMaxWarnings| times in a row and then
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // repeated after a period of silence that lasts |kSilenceDurationDays| days.
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool ShouldCheckNetworkProfile(Profile* profile);
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Verifies that the profile folder is not located on a network share, and if
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // it is shows the warning bubble to the user.
532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  static void CheckNetworkProfile(const base::FilePath& profile_folder);
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Shows the notification bubble using the provided |browser|.
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static void ShowNotification(Browser* browser);
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static void SetNotificationShown(bool shown);
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Register the pref that controls whether the bubble should be shown anymore.
612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  static void RegisterUserPrefs(PrefRegistrySyncable* registry);
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Helper function wrapping the UMA_HISTOGRAM_ENUMERATION macro.
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static void RecordUmaEvent(MetricNetworkedProfileCheck event);
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // This function creates the notification bubble, attaches it to the
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |anchor| View and then shows it to the user.
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static void NotifyNetworkProfileDetected();
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Set to true once the notification check has been performed to avoid showing
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the notification more than once per browser run.
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // This flag is not thread-safe and should only be accessed on the UI thread!
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool notification_shown_;
755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DISALLOW_IMPLICIT_CONSTRUCTORS(NetworkProfileBubble);
775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // CHROME_BROWSER_UI_NETWORK_PROFILE_BUBBLE_H_
80