Update "did run" from the browser process after renderer creation.
This fixes a regression in which active use of the browser stopped being
recorded as such.
BUG=432544
Review URL: https://codereview.chromium.org/719153003
Cr-Commit-Position: refs/heads/master@{#304061}
diff --git a/chrome/browser/BUILD.gn b/chrome/browser/BUILD.gn
index 4726644..4310ebbc 100644
--- a/chrome/browser/BUILD.gn
+++ b/chrome/browser/BUILD.gn
@@ -552,6 +552,12 @@
if (is_win) {
sources += rebase_path(gypi_values.chrome_browser_win_sources,
".", "//chrome")
+ if (!is_chrome_branded) {
+ sources -= [
+ "google/did_run_updater_win.cc",
+ "google/did_run_updater_win.h",
+ ]
+ }
public_deps += [
"//ui/views",
"//ui/views/controls/webview",
diff --git a/chrome/browser/chrome_browser_main_win.cc b/chrome/browser/chrome_browser_main_win.cc
index aa39454..7ab56c55 100644
--- a/chrome/browser/chrome_browser_main_win.cc
+++ b/chrome/browser/chrome_browser_main_win.cc
@@ -59,6 +59,10 @@
#include "ui/gfx/switches.h"
#include "ui/strings/grit/app_locale_settings.h"
+#if defined(GOOGLE_CHROME_BUILD)
+#include "chrome/browser/google/did_run_updater_win.h"
+#endif
+
namespace {
typedef HRESULT (STDAPICALLTYPE* RegisterApplicationRestartProc)(
@@ -262,6 +266,10 @@
// TODO(erikwright): Remove this and the implementation of the experiment by
// September 2014.
InitializeDisableTerminateOnHeapCorruptionExperiment();
+
+#if defined(GOOGLE_CHROME_BUILD)
+ did_run_updater_.reset(new DidRunUpdater);
+#endif
}
// static
diff --git a/chrome/browser/chrome_browser_main_win.h b/chrome/browser/chrome_browser_main_win.h
index 573c1e14..3b3ea04d 100644
--- a/chrome/browser/chrome_browser_main_win.h
+++ b/chrome/browser/chrome_browser_main_win.h
@@ -9,6 +9,8 @@
#include "chrome/browser/chrome_browser_main.h"
+class DidRunUpdater;
+
namespace base {
class CommandLine;
}
@@ -63,6 +65,10 @@
static void SetupInstallerUtilStrings();
private:
+#if defined(GOOGLE_CHROME_BUILD)
+ scoped_ptr<DidRunUpdater> did_run_updater_;
+#endif
+
DISALLOW_COPY_AND_ASSIGN(ChromeBrowserMainPartsWin);
};
diff --git a/chrome/browser/google/did_run_updater_win.cc b/chrome/browser/google/did_run_updater_win.cc
new file mode 100644
index 0000000..b409fd0
--- /dev/null
+++ b/chrome/browser/google/did_run_updater_win.cc
@@ -0,0 +1,33 @@
+// Copyright 2014 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.
+
+#include "chrome/browser/google/did_run_updater_win.h"
+
+#include "base/base_paths.h"
+#include "base/files/file_path.h"
+#include "base/path_service.h"
+#include "chrome/installer/util/google_update_settings.h"
+#include "chrome/installer/util/install_util.h"
+#include "content/public/browser/notification_details.h"
+#include "content/public/browser/notification_service.h"
+#include "content/public/browser/notification_source.h"
+#include "content/public/browser/notification_types.h"
+
+DidRunUpdater::DidRunUpdater() : system_level_(false) {
+ base::FilePath exe_path;
+ if (PathService::Get(base::FILE_EXE, &exe_path))
+ system_level_ = !InstallUtil::IsPerUserInstall(exe_path.value().c_str());
+
+ registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CREATED,
+ content::NotificationService::AllSources());
+}
+
+DidRunUpdater::~DidRunUpdater() {
+}
+
+void DidRunUpdater::Observe(int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) {
+ GoogleUpdateSettings::UpdateDidRunState(true, system_level_);
+}
diff --git a/chrome/browser/google/did_run_updater_win.h b/chrome/browser/google/did_run_updater_win.h
new file mode 100644
index 0000000..5fb8a6eb
--- /dev/null
+++ b/chrome/browser/google/did_run_updater_win.h
@@ -0,0 +1,32 @@
+// Copyright 2014 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_GOOGLE_DID_RUN_UPDATER_WIN_H_
+#define CHROME_BROWSER_GOOGLE_DID_RUN_UPDATER_WIN_H_
+
+#include "base/macros.h"
+#include "content/public/browser/notification_observer.h"
+#include "content/public/browser/notification_registrar.h"
+
+// Updates Chrome's "did run" state periodically when the process is in use.
+// The creation of renderers is used as a proxy for "is the browser in use."
+class DidRunUpdater : public content::NotificationObserver {
+ public:
+ DidRunUpdater();
+ ~DidRunUpdater() override;
+
+ private:
+ // content::NotificationObserver:
+ void Observe(int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) override;
+
+ // True if the process is running from a system-level installation.
+ bool system_level_;
+ content::NotificationRegistrar registrar_;
+
+ DISALLOW_COPY_AND_ASSIGN(DidRunUpdater);
+};
+
+#endif // CHROME_BROWSER_GOOGLE_DID_RUN_UPDATER_WIN_H_
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index 4f7f1f5..a2856e3 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -2203,6 +2203,8 @@
'browser/first_run/try_chrome_dialog_view.cc',
'browser/first_run/try_chrome_dialog_view.h',
'browser/first_run/upgrade_util.cc',
+ 'browser/google/did_run_updater_win.cc',
+ 'browser/google/did_run_updater_win.h',
'browser/hang_monitor/hang_crash_dump_win.cc',
'browser/hang_monitor/hang_crash_dump_win.h',
'browser/hang_monitor/hung_plugin_action.cc',
@@ -3378,6 +3380,12 @@
'<(allocator_target)',
],
}],
+ ['branding!="Chrome"', {
+ 'sources!': [
+ 'browser/google/did_run_updater_win.cc',
+ 'browser/google/did_run_updater_win.h',
+ ],
+ }],
],
}, { # 'OS!="win"
'sources': [ '<@(chrome_browser_non_win_sources)' ],