summaryrefslogtreecommitdiffstats
path: root/chrome/browser/profile_resetter/profile_reset_global_error.h
blob: 6529df4955f54932aa71ed4b13c234173d258c70 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_PROFILE_RESETTER_PROFILE_RESET_GLOBAL_ERROR_H_
#define CHROME_BROWSER_PROFILE_RESETTER_PROFILE_RESET_GLOBAL_ERROR_H_

#include "base/basictypes.h"
#include "base/memory/weak_ptr.h"
#include "base/timer/elapsed_timer.h"
#include "chrome/browser/ui/global_error/global_error.h"

class AutomaticProfileResetter;
class GlobalErrorBubbleViewBase;
class Profile;

// Encapsulates UI-related functionality for the one-time profile settings reset
// prompt. The UI consists of two parts: (1.) the profile reset (pop-up) bubble,
// and (2.) a menu item in the wrench menu (provided by us being a GlobalError).
class ProfileResetGlobalError
    : public GlobalError,
      public base::SupportsWeakPtr<ProfileResetGlobalError> {
 public:
  explicit ProfileResetGlobalError(Profile* profile);
  virtual ~ProfileResetGlobalError();

  // Returns whether or not the reset prompt is supported on this platform.
  static bool IsSupportedOnPlatform();

  // Called by the bubble view when it is closed.
  void OnBubbleViewDidClose();

  // Called when the user clicks on the 'Reset' button. The user can choose to
  // send feedback containing the old settings that are now being reset, this is
  // indicated by |send_feedback|.
  void OnBubbleViewResetButtonPressed(bool send_feedback);

  // Called when the user clicks the 'No, thanks' button.
  void OnBubbleViewNoThanksButtonPressed();

  // GlobalError:
  virtual bool HasMenuItem() OVERRIDE;
  virtual int MenuItemCommandID() OVERRIDE;
  virtual base::string16 MenuItemLabel() OVERRIDE;
  virtual void ExecuteMenuItem(Browser* browser) OVERRIDE;
  virtual bool HasBubbleView() OVERRIDE;
  virtual bool HasShownBubbleView() OVERRIDE;
  virtual void ShowBubbleView(Browser* browser) OVERRIDE;
  virtual GlobalErrorBubbleViewBase* GetBubbleView() OVERRIDE;

 private:
  Profile* profile_;

  // GlobalErrorService owns us, on which AutomaticProfileResetter depends, so
  // during shutdown, it may get destroyed before we are.
  // Note: the AutomaticProfileResetter expects call-backs from us to always be
  // synchronous, so that there will be no call-backs once we are destroyed.
  base::WeakPtr<AutomaticProfileResetter> automatic_profile_resetter_;

  // Used to measure the delay before the bubble actually gets shown.
  base::ElapsedTimer timer_;

  // Whether or not we have already shown the bubble.
  bool has_shown_bubble_view_;

  // The reset bubble, if we're currently showing one.
  GlobalErrorBubbleViewBase* bubble_view_;

  DISALLOW_COPY_AND_ASSIGN(ProfileResetGlobalError);
};

#endif  // CHROME_BROWSER_PROFILE_RESETTER_PROFILE_RESET_GLOBAL_ERROR_H_