Chromium Code Reviews| Index: chrome/browser/upgrade_detector_impl.cc |
| diff --git a/chrome/browser/upgrade_detector_impl.cc b/chrome/browser/upgrade_detector_impl.cc |
| index f2934538ca6ecf1fe10ec032d6c30ab2a444841b..a3c0d290300f42d40eaf2051a28c1af5e26b0436 100644 |
| --- a/chrome/browser/upgrade_detector_impl.cc |
| +++ b/chrome/browser/upgrade_detector_impl.cc |
| @@ -13,6 +13,7 @@ |
| #include "base/memory/scoped_ptr.h" |
| #include "base/memory/singleton.h" |
| #include "base/path_service.h" |
| +#include "base/prefs/pref_service.h" |
| #include "base/process/launch.h" |
| #include "base/strings/string_number_conversions.h" |
| #include "base/strings/string_util.h" |
| @@ -23,10 +24,12 @@ |
| #include "chrome/browser/google/google_util.h" |
| #include "chrome/common/chrome_switches.h" |
| #include "chrome/common/chrome_version_info.h" |
| +#include "chrome/common/pref_names.h" |
| #include "content/public/browser/browser_thread.h" |
| #include "ui/base/resource/resource_bundle.h" |
| #if defined(OS_WIN) |
| +#include "base/win/win_util.h" |
| #include "chrome/installer/util/browser_distribution.h" |
| #include "chrome/installer/util/google_update_settings.h" |
| #include "chrome/installer/util/helper.h" |
| @@ -60,12 +63,18 @@ std::string CmdLineInterval() { |
| return cmd_line.GetSwitchValueASCII(switches::kCheckForUpdateIntervalSec); |
| } |
| +bool SimulatingOutdated() { |
| + const CommandLine& cmd_line = *CommandLine::ForCurrentProcess(); |
| + return cmd_line.HasSwitch(switches::kSimulateOutdated) || |
| + cmd_line.HasSwitch(switches::kSimulateOutdatedNoAU); |
| +} |
| + |
| bool IsTesting() { |
| const CommandLine& cmd_line = *CommandLine::ForCurrentProcess(); |
| return cmd_line.HasSwitch(switches::kSimulateUpgrade) || |
| cmd_line.HasSwitch(switches::kCheckForUpdateIntervalSec) || |
| cmd_line.HasSwitch(switches::kSimulateCriticalUpdate) || |
| - cmd_line.HasSwitch(switches::kSimulateOutdated); |
| + SimulatingOutdated(); |
| } |
| // How often to check for an upgrade. |
| @@ -113,15 +122,22 @@ bool IsSystemInstall() { |
| // updates are allowed. It also identifies whether we are running an unstable |
| // channel. |
| void DetectUpdatability(const base::Closure& callback_task, |
| - bool* is_unstable_channel) { |
| + bool* is_unstable_channel, |
| + bool* is_autoupdate_on) { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| base::string16 app_guid = installer::GetAppGuidForUpdates(IsSystemInstall()); |
| DCHECK(!app_guid.empty()); |
| - if (GoogleUpdateSettings::AUTOMATIC_UPDATES == |
| - GoogleUpdateSettings::GetAppUpdatePolicy(app_guid, NULL)) { |
| - CheckForUnstableChannel(callback_task, is_unstable_channel); |
| + // Don't try to turn on autoupdate when we failed previously. |
| + if (g_browser_process->local_state() && |
| + !g_browser_process->local_state()->GetBoolean( |
| + prefs::kFailedTurningOnAutoupdate)) { |
|
robertshield
2014/03/26 03:20:11
nit: indent.
Moreover, I think we should call th
MAD
2014/03/26 19:30:16
Done.
Interestingly, the initial name I had was tr
|
| + *is_autoupdate_on = GoogleUpdateSettings::AUTOMATIC_UPDATES == |
| + GoogleUpdateSettings::GetAppUpdatePolicy(app_guid, NULL); |
| } |
| + // Don't show the update bubbles to entreprise users (i.e., on a domain). |
| + if (!base::win::IsEnrolledToDomain()) |
| + CheckForUnstableChannel(callback_task, is_unstable_channel); |
| } |
| #endif // defined(OS_WIN) |
| @@ -130,7 +146,11 @@ void DetectUpdatability(const base::Closure& callback_task, |
| UpgradeDetectorImpl::UpgradeDetectorImpl() |
| : weak_factory_(this), |
| is_unstable_channel_(false), |
| + is_autoupdate_on_(true), |
| build_date_(base::GetBuildTime()) { |
| + // Start tracking network time updates. |
| + network_time_tracker_.Start(); |
| + |
| CommandLine command_line(*CommandLine::ForCurrentProcess()); |
| // The different command line switches that affect testing can't be used |
| // simultaneously, if they do, here's the precedence order, based on the order |
| @@ -139,7 +159,8 @@ UpgradeDetectorImpl::UpgradeDetectorImpl() |
| // switch from being taken into account. |
| // - kSimulateUpgrade supersedes critical or outdated upgrade switches. |
| // - kSimulateCriticalUpdate has precedence over kSimulateOutdated. |
| - // - kSimulateOutdated can work on its own, or with a specified date. |
| + // - kSimulateOutdatedNoAU has precedence over kSimulateOutdated. |
| + // - kSimulateOutdated[NoAu] can work on its own, or with a specified date. |
| if (command_line.HasSwitch(switches::kDisableBackgroundNetworking)) |
| return; |
| if (command_line.HasSwitch(switches::kSimulateUpgrade)) { |
| @@ -150,7 +171,7 @@ UpgradeDetectorImpl::UpgradeDetectorImpl() |
| UpgradeDetected(UPGRADE_AVAILABLE_CRITICAL); |
| return; |
| } |
| - if (command_line.HasSwitch(switches::kSimulateOutdated)) { |
| + if (SimulatingOutdated()) { |
| // The outdated simulation can work without a value, which means outdated |
| // now, or with a value that must be a well formed date/time string that |
| // overrides the build date. |
| @@ -158,8 +179,14 @@ UpgradeDetectorImpl::UpgradeDetectorImpl() |
| // tracking moves off of the VariationsService, the "variations-server-url" |
| // command line switch must also be specified for the service to be |
| // available on non GOOGLE_CHROME_BUILD. |
| - std::string build_date = command_line.GetSwitchValueASCII( |
| - switches::kSimulateOutdated); |
| + std::string switch_name; |
| + if (command_line.HasSwitch(switches::kSimulateOutdatedNoAU)) { |
| + is_autoupdate_on_ = false; |
| + switch_name = switches::kSimulateOutdatedNoAU; |
| + } else { |
| + switch_name = switches::kSimulateOutdated; |
| + } |
| + std::string build_date = command_line.GetSwitchValueASCII(switch_name); |
| base::Time maybe_build_time; |
| bool result = base::Time::FromString(build_date.c_str(), &maybe_build_time); |
| if (result && !maybe_build_time.is_null()) { |
| @@ -168,7 +195,9 @@ UpgradeDetectorImpl::UpgradeDetectorImpl() |
| StartTimerForUpgradeCheck(); |
| } else { |
| // Without a valid date, we simulate that we are already outdated... |
| - UpgradeDetected(UPGRADE_NEEDED_OUTDATED_INSTALL); |
| + UpgradeDetected( |
| + is_autoupdate_on_ ? UPGRADE_NEEDED_OUTDATED_INSTALL |
| + : UPGRADE_NEEDED_OUTDATED_INSTALL_NO_AU); |
| } |
| return; |
| } |
| @@ -186,13 +215,16 @@ UpgradeDetectorImpl::UpgradeDetectorImpl() |
| BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| base::Bind(&DetectUpdatability, |
| start_upgrade_check_timer_task, |
| - &is_unstable_channel_)); |
| + &is_unstable_channel_, |
| + &is_autoupdate_on_)); |
| #endif |
| #else |
| #if defined(OS_MACOSX) |
| // Only enable upgrade notifications if the updater (Keystone) is present. |
| - if (!keystone_glue::KeystoneEnabled()) |
| + if (!keystone_glue::KeystoneEnabled()) { |
| + is_autoupdate_on_ = false; |
| return; |
| + } |
| #elif defined(OS_POSIX) |
| // Always enable upgrade notifications regardless of branding. |
| #else |
| @@ -203,9 +235,6 @@ UpgradeDetectorImpl::UpgradeDetectorImpl() |
| base::Bind(&CheckForUnstableChannel, |
| start_upgrade_check_timer_task, |
| &is_unstable_channel_)); |
| - |
| - // Start tracking network time updates. |
| - network_time_tracker_.Start(); |
| #endif |
| } |
| @@ -315,12 +344,10 @@ void UpgradeDetectorImpl::CheckForUpgrade() { |
| } |
| bool UpgradeDetectorImpl::DetectOutdatedInstall() { |
| - // Only enable the outdated install check if we are running the trial for it, |
| - // unless we are simulating an outdated isntall. |
| - static bool simulate_outdated = CommandLine::ForCurrentProcess()->HasSwitch( |
| - switches::kSimulateOutdated); |
| + // Don't show the bubble if we have a brand code that is NOT organic, unless |
|
robertshield
2014/03/26 03:20:11
why is this limited to only organic brand codes?
MAD
2014/03/26 19:30:16
It was discussed around here:
https://code.google.
|
| + // an outdated build is being simulated by command line switches. |
| + static bool simulate_outdated = SimulatingOutdated(); |
| if (!simulate_outdated) { |
| - // Also don't show the bubble if we have a brand code that is NOT organic. |
| std::string brand; |
| if (google_util::GetBrand(&brand) && !google_util::IsOrganic(brand)) |
| return false; |
| @@ -331,7 +358,9 @@ bool UpgradeDetectorImpl::DetectOutdatedInstall() { |
| if (!network_time_tracker_.GetNetworkTime(base::TimeTicks::Now(), |
| &network_time, |
| &uncertainty)) { |
| - return false; |
| + // When network time has not been initialized yet, simply rely on the |
| + // machine's current time. |
| + network_time = base::Time::Now(); |
| } |
| if (network_time.is_null() || build_date_.is_null() || |
| @@ -342,7 +371,8 @@ bool UpgradeDetectorImpl::DetectOutdatedInstall() { |
| if (network_time - build_date_ > |
| base::TimeDelta::FromDays(kOutdatedBuildAgeInDays)) { |
| - UpgradeDetected(UPGRADE_NEEDED_OUTDATED_INSTALL); |
| + UpgradeDetected(is_autoupdate_on_ ? UPGRADE_NEEDED_OUTDATED_INSTALL |
| + : UPGRADE_NEEDED_OUTDATED_INSTALL_NO_AU); |
| return true; |
| } |
| // If we simlated an outdated install with a date, we don't want to keep |