Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Side by Side Diff: chrome/browser/upgrade_detector.cc

Issue 3455009: Change the frequency of update checks depending on the installed channel of chrome. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: finnur review Created 10 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/gtk/update_recommended_dialog.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/upgrade_detector.h" 5 #include "chrome/browser/upgrade_detector.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/scoped_ptr.h" 10 #include "base/scoped_ptr.h"
11 #include "base/time.h" 11 #include "base/time.h"
12 #include "base/task.h" 12 #include "base/task.h"
13 #include "base/string_number_conversions.h" 13 #include "base/string_number_conversions.h"
14 #include "base/string_util.h" 14 #include "base/string_util.h"
15 #include "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
16 #include "chrome/browser/chrome_thread.h" 16 #include "chrome/browser/chrome_thread.h"
17 #include "chrome/browser/platform_util.h"
17 #include "chrome/browser/prefs/pref_service.h" 18 #include "chrome/browser/prefs/pref_service.h"
18 #include "chrome/common/chrome_switches.h" 19 #include "chrome/common/chrome_switches.h"
19 #include "chrome/common/chrome_version_info.h" 20 #include "chrome/common/chrome_version_info.h"
20 #include "chrome/common/notification_service.h" 21 #include "chrome/common/notification_service.h"
21 #include "chrome/common/notification_type.h" 22 #include "chrome/common/notification_type.h"
22 #include "chrome/common/pref_names.h" 23 #include "chrome/common/pref_names.h"
23 #include "chrome/installer/util/browser_distribution.h" 24 #include "chrome/installer/util/browser_distribution.h"
24 25
25 #if defined(OS_WIN) 26 #if defined(OS_WIN)
26 #include "chrome/installer/util/install_util.h" 27 #include "chrome/installer/util/install_util.h"
27 #elif defined(OS_MACOSX) 28 #elif defined(OS_MACOSX)
28 #include "chrome/browser/cocoa/keystone_glue.h" 29 #include "chrome/browser/cocoa/keystone_glue.h"
29 #elif defined(OS_POSIX) 30 #elif defined(OS_POSIX)
30 #include "base/process_util.h" 31 #include "base/process_util.h"
31 #include "chrome/installer/util/version.h" 32 #include "chrome/installer/util/version.h"
32 #endif 33 #endif
33 34
34 namespace { 35 namespace {
35 36
36 // How often to check for an upgrade. 37 // How often to check for an upgrade.
37 // TODO(finnur): Once we have a good way of determining which branch the user 38 int GetCheckForUpgradeEveryMs() {
38 // is on at runtime we should check more frequently for the dev branch. 39 // Check for a value passed via the command line.
39 const int kCheckForUpgradeEveryMs = 24 * 60 * 60 * 1000; // Check daily. 40 int interval_ms;
41 const CommandLine& cmd_line = *CommandLine::ForCurrentProcess();
42 std::string interval =
43 cmd_line.GetSwitchValueASCII(switches::kCheckForUpdateIntervalSec);
44 if (!interval.empty() && base::StringToInt(interval, &interval_ms))
45 return interval_ms * 1000; // Command line value is in seconds.
46
47 // Otherwise check once an hour for dev channel and once a day for all other
48 // channels/builds.
49 const std::string channel = platform_util::GetVersionStringModifier();
50 int hours;
51 if (channel == "dev")
52 hours = 1;
53 else
54 hours = 24;
55
56 return hours * 60 * 60 * 1000;
57 }
40 58
41 // How long to wait before notifying the user about the upgrade. 59 // How long to wait before notifying the user about the upgrade.
42 const int kNotifyUserAfterMs = 0; 60 const int kNotifyUserAfterMs = 0;
43 61
44 // The thread to run the upgrade detection code on. We use FILE for Linux 62 // The thread to run the upgrade detection code on. We use FILE for Linux
45 // because we don't want to block the UI thread while launching a background 63 // because we don't want to block the UI thread while launching a background
46 // process and reading its output; on the Mac, checking for an upgrade 64 // process and reading its output; on the Mac, checking for an upgrade
47 // requires reading a file. 65 // requires reading a file.
48 const ChromeThread::ID kDetectUpgradeTaskID = 66 const ChromeThread::ID kDetectUpgradeTaskID =
49 #if defined(OS_POSIX) 67 #if defined(OS_POSIX)
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 : ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), 158 : ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)),
141 notify_upgrade_(false) { 159 notify_upgrade_(false) {
142 // Windows: only enable upgrade notifications for official builds. 160 // Windows: only enable upgrade notifications for official builds.
143 // Mac: only enable them if the updater (Keystone) is present. 161 // Mac: only enable them if the updater (Keystone) is present.
144 // Linux (and other POSIX): always enable regardless of branding. 162 // Linux (and other POSIX): always enable regardless of branding.
145 #if (defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD)) || defined(OS_POSIX) 163 #if (defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD)) || defined(OS_POSIX)
146 #if defined(OS_MACOSX) 164 #if defined(OS_MACOSX)
147 if (keystone_glue::KeystoneEnabled()) 165 if (keystone_glue::KeystoneEnabled())
148 #endif 166 #endif
149 { 167 {
150 int interval_ms = kCheckForUpgradeEveryMs;
151 const CommandLine& cmd_line = *CommandLine::ForCurrentProcess();
152 std::string interval =
153 cmd_line.GetSwitchValueASCII(switches::kCheckForUpdateIntervalSec);
154 if (!interval.empty() && base::StringToInt(interval, &interval_ms))
155 interval_ms *= 1000; // Command line value is in seconds.
156
157 detect_upgrade_timer_.Start( 168 detect_upgrade_timer_.Start(
158 base::TimeDelta::FromMilliseconds(interval_ms), 169 base::TimeDelta::FromMilliseconds(GetCheckForUpgradeEveryMs()),
159 this, &UpgradeDetector::CheckForUpgrade); 170 this, &UpgradeDetector::CheckForUpgrade);
160 } 171 }
161 #endif 172 #endif
162 } 173 }
163 174
164 UpgradeDetector::~UpgradeDetector() { 175 UpgradeDetector::~UpgradeDetector() {
165 } 176 }
166 177
167 void UpgradeDetector::CheckForUpgrade() { 178 void UpgradeDetector::CheckForUpgrade() {
168 method_factory_.RevokeAll(); 179 method_factory_.RevokeAll();
(...skipping 21 matching lines...) Expand all
190 } 201 }
191 202
192 void UpgradeDetector::NotifyOnUpgrade() { 203 void UpgradeDetector::NotifyOnUpgrade() {
193 notify_upgrade_ = true; 204 notify_upgrade_ = true;
194 205
195 NotificationService::current()->Notify( 206 NotificationService::current()->Notify(
196 NotificationType::UPGRADE_RECOMMENDED, 207 NotificationType::UPGRADE_RECOMMENDED,
197 Source<UpgradeDetector>(this), 208 Source<UpgradeDetector>(this),
198 NotificationService::NoDetails()); 209 NotificationService::NoDetails());
199 } 210 }
OLDNEW
« no previous file with comments | « chrome/browser/gtk/update_recommended_dialog.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698