OLD | NEW |
| (Empty) |
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 #include "chrome/browser/ui/startup/obsolete_os_prompt.h" | |
6 | |
7 #include "base/time.h" | |
8 #include "chrome/browser/browser_process.h" | |
9 #include "chrome/browser/infobars/infobar_tab_helper.h" | |
10 #include "chrome/browser/prefs/pref_service.h" | |
11 #include "chrome/browser/ui/browser.h" | |
12 #include "chrome/browser/ui/browser_tabstrip.h" | |
13 #include "chrome/browser/ui/cocoa/obsolete_os.h" | |
14 #include "chrome/browser/ui/startup/obsolete_os_info_bar.h" | |
15 #include "chrome/browser/ui/tab_contents/tab_contents.h" | |
16 #include "chrome/common/pref_names.h" | |
17 #include "chrome/common/url_constants.h" | |
18 | |
19 namespace chrome { | |
20 | |
21 void RegisterObsoleteOSInfobarPrefs(PrefService* local_state) { | |
22 local_state->RegisterDoublePref( | |
23 prefs::kMacLeopardObsoleteInfobarLastShown, | |
24 0, | |
25 PrefService::UNSYNCABLE_PREF); | |
26 } | |
27 | |
28 void ShowObsoleteOSPrompt(Browser* browser) { | |
29 if (!IsOSObsoleteOrNearlySo()) | |
30 return; | |
31 | |
32 PrefService* local_state = g_browser_process->local_state(); | |
33 if (!local_state) | |
34 return; | |
35 | |
36 // Only show the infobar if the user has not been shown it for more than a | |
37 // week. | |
38 base::Time time_now(base::Time::Now()); | |
39 if (local_state->HasPrefPath(prefs::kMacLeopardObsoleteInfobarLastShown)) { | |
40 double time_double = | |
41 local_state->GetDouble(prefs::kMacLeopardObsoleteInfobarLastShown); | |
42 base::Time last_shown(base::Time::FromDoubleT(time_double)); | |
43 | |
44 base::TimeDelta a_week(base::TimeDelta::FromDays(7)); | |
45 if (last_shown >= time_now - a_week) | |
46 return; | |
47 } | |
48 | |
49 TabContents* tab = chrome::GetActiveTabContents(browser); | |
50 if (!tab) | |
51 return; | |
52 tab->infobar_tab_helper()->AddInfoBar( | |
53 new ObsoleteOSInfoBar( | |
54 tab->infobar_tab_helper(), | |
55 LocalizedObsoleteOSString(), | |
56 GURL(chrome::kMacLeopardObsoleteURL))); | |
57 | |
58 local_state->SetDouble(prefs::kMacLeopardObsoleteInfobarLastShown, | |
59 time_now.ToDoubleT()); | |
60 } | |
61 | |
62 } // namespace chrome | |
OLD | NEW |