blob: 00227d5d7aee8732300895ce754b57af32e004a3 (
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
// Copyright (c) 2011 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_UPGRADE_DETECTOR_H_
#define CHROME_BROWSER_UPGRADE_DETECTOR_H_
#pragma once
#include "base/timer.h"
#include "ui/gfx/image.h"
template <typename T> struct DefaultSingletonTraits;
class PrefService;
///////////////////////////////////////////////////////////////////////////////
// UpgradeDetector
//
// This class is a singleton class that monitors when an upgrade happens in the
// background. We basically ask Omaha what it thinks the latest version is and
// if our version is lower we send out a notification upon:
// a) Detecting an upgrade and...
// b) When we think the user should be notified about the upgrade.
// The latter happens much later, since we don't want to be too annoying.
//
class UpgradeDetector {
public:
// The Homeland Security Upgrade Advisory System.
enum UpgradeNotificationAnnoyanceLevel {
UPGRADE_ANNOYANCE_NONE = 0, // What? Me worry?
UPGRADE_ANNOYANCE_LOW, // Green.
UPGRADE_ANNOYANCE_ELEVATED, // Yellow.
UPGRADE_ANNOYANCE_HIGH, // Red.
UPGRADE_ANNOYANCE_SEVERE, // Orange.
};
// The two types of icons we know about.
enum UpgradeNotificationIconType {
UPGRADE_ICON_TYPE_BADGE = 0, // For overlay badging of the wrench menu.
UPGRADE_ICON_TYPE_MENU_ICON, // For showing in the wrench menu.
};
// Returns the singleton instance.
static UpgradeDetector* GetInstance();
~UpgradeDetector();
static void RegisterPrefs(PrefService* prefs);
bool notify_upgrade() { return notify_upgrade_; }
// Retrieves the right icon ID based on the degree of severity (see
// UpgradeNotificationAnnoyanceLevel, each level has an an accompanying icon
// to go with it). |type| determines which class of icons the caller wants,
// either an icon appropriate for badging the wrench menu or one to display
// within the wrench menu.
int GetIconResourceID(UpgradeNotificationIconType type);
private:
friend struct DefaultSingletonTraits<UpgradeDetector>;
UpgradeDetector();
// Launches a task on the file thread to check if we have the latest version.
void CheckForUpgrade();
// Sends out a notification and starts a one shot timer to wait until
// notifying the user.
void UpgradeDetected();
// The function that sends out a notification (after a certain time has
// elapsed) that lets the rest of the UI know we should start notifying the
// user that a new version is available.
void NotifyOnUpgrade();
// We periodically check to see if Chrome has been upgraded.
base::RepeatingTimer<UpgradeDetector> detect_upgrade_timer_;
// After we detect an upgrade we start a recurring timer to see if enough time
// has passed and we should start notifying the user.
base::RepeatingTimer<UpgradeDetector> upgrade_notification_timer_;
// We use this factory to create callback tasks for UpgradeDetected. We pass
// the task to the actual upgrade detection code, which is in
// DetectUpgradeTask.
ScopedRunnableMethodFactory<UpgradeDetector> method_factory_;
// When the upgrade was detected.
base::Time upgrade_detected_time_;
// True if this build is a dev or canary channel build.
bool is_unstable_channel_;
// The stage at which the annoyance level for upgrade notifications is at.
UpgradeNotificationAnnoyanceLevel upgrade_notification_stage_;
// Whether we have waited long enough after detecting an upgrade (to see
// is we should start nagging about upgrading).
bool notify_upgrade_;
DISALLOW_COPY_AND_ASSIGN(UpgradeDetector);
};
#endif // CHROME_BROWSER_UPGRADE_DETECTOR_H_
|