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

Unified Diff: chrome/installer/gcapi/gcapi.cc

Issue 8508060: Add functionality to the GCAPI to detect when Chrome was last run. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: chrome/installer/gcapi/gcapi.cc
===================================================================
--- chrome/installer/gcapi/gcapi.cc (revision 108839)
+++ chrome/installer/gcapi/gcapi.cc (working copy)
@@ -2,20 +2,34 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+// NOTE: This code is a legacy utility API for partners to checking whether
grt (UTC plus 2) 2011/11/11 17:01:01 checking -> check
robertshield 2011/11/12 05:25:38 Done.
+// Chrome can be installed and launched. Recent updates are being made
+// to add new functionality. These updates use code from Chromium, the old
+// coded against the win32 api directly. If you have an itch to shave a
+// yak, feel free to re-write the old code too.
+
#include "chrome/installer/gcapi/gcapi.h"
#include <atlbase.h>
#include <atlcom.h>
-#include <windows.h>
#include <sddl.h>
#define STRSAFE_NO_DEPRECATE
#include <strsafe.h>
#include <tlhelp32.h>
+#include <windows.h>
#include <cstdlib>
+#include <limits>
+#include <string>
-#include "google_update_idl.h"
+#include "base/basictypes.h"
+#include "base/string_number_conversions.h"
+#include "base/time.h"
+#include "base/win/registry.h"
+#include "chrome/installer/util/google_update_constants.h"
+#include "google_update_idl.h" // NOLINT
+
namespace {
const wchar_t kChromeRegClientsKey[] =
@@ -70,11 +84,14 @@
if (!::VerQueryValue(file_version_info, info_name,
reinterpret_cast<LPVOID *>(&data), reinterpret_cast<UINT *>(&data_len)))
return false;
- if (data_len <= 0 || data_len >= out_len)
+ if (data_len <= 0 || data_len >= (out_len / sizeof(wchar_t)))
return false;
memset(buffer, 0, out_len);
- ::StringCchCopyN(buffer, out_len, (const wchar_t*)data, data_len);
+ ::StringCchCopyN(buffer,
+ (out_len / sizeof(wchar_t)),
+ reinterpret_cast<const wchar_t*>(data),
+ data_len);
return true;
}
@@ -140,9 +157,9 @@
// Helper function to read a value from registry. Returns true if value
// is read successfully and stored in parameter value. Returns false otherwise.
-bool ReadValueFromRegistry(HKEY root_key, const wchar_t *sub_key,
- const wchar_t *value_name, wchar_t *value,
- size_t *size) {
+bool ReadValueFromRegistry(HKEY root_key, const wchar_t* sub_key,
+ const wchar_t* value_name, wchar_t* value,
+ size_t* size) {
HKEY key;
if ((::RegOpenKeyEx(root_key, sub_key, NULL,
KEY_READ, &key) == ERROR_SUCCESS) &&
@@ -164,7 +181,7 @@
enum WindowsVersion {
VERSION_BELOW_XP_SP2,
- VERSION_XP_SP2_UP_TO_VISTA, // "but not including"
+ VERSION_XP_SP2_UP_TO_VISTA, // "but not including"
VERSION_VISTA_OR_HIGHER,
};
WindowsVersion GetWindowsVersion() {
@@ -285,7 +302,7 @@
#pragma comment(linker, "/EXPORT:GoogleChromeCompatibilityCheck=_GoogleChromeCompatibilityCheck@8,PRIVATE")
DLLEXPORT BOOL __stdcall GoogleChromeCompatibilityCheck(BOOL set_flag,
- DWORD *reasons) {
+ DWORD* reasons) {
DWORD local_reasons = 0;
WindowsVersion windows_version = GetWindowsVersion();
@@ -451,3 +468,39 @@
return (handle &&
SetWindowPos(handle, 0, x, y, width, height, SWP_NOZORDER));
}
+
+#pragma comment(linker, "/EXPORT:LaunchGoogleChromeWithDimensions=_LaunchGoogleChromeWithDimensions@24,PRIVATE")
grt (UTC plus 2) 2011/11/11 17:01:01 LaunchGoogleChromeWithDimensions -> GoogleChromeDa
robertshield 2011/11/12 05:25:38 heh, done
+DLLEXPORT int __stdcall GoogleChromeDaysSinceLastRun() {
+ using base::win::RegKey;
+ using base::Time;
+ using base::TimeDelta;
+
+ int days_since_last_run = std::numeric_limits<int>::max();
+
+ HKEY hives[] = {HKEY_LOCAL_MACHINE, HKEY_CURRENT_USER};
grt (UTC plus 2) 2011/11/11 17:01:01 Chrome doesn't even try to write to HKLM since it
robertshield 2011/11/12 05:25:38 so, as discussed modified this to assume that one
+ for (int i = 0; i < arraysize(hives); ++i) {
+ RegKey client_state(hives[i],
+ kChromeRegClientStateKey,
+ KEY_QUERY_VALUE);
+ if (client_state.Valid()) {
+ std::wstring last_run;
+ int64 last_run_value = 0;
+ if (client_state.ReadValue(google_update::kRegLastRunTimeField,
+ &last_run) == ERROR_SUCCESS &&
+ base::StringToInt64(last_run, &last_run_value)) {
+ Time last_run_time = Time::FromInternalValue(last_run_value);
+ TimeDelta difference = Time::NowFromSystemTime() - last_run_time;
+ int days_elapsed = difference.InDays();
grt (UTC plus 2) 2011/11/11 17:01:01 include <algorithm> and replace these four lines w
robertshield 2011/11/12 05:25:38 Done.
+ if (days_elapsed < days_since_last_run) {
+ days_since_last_run = days_elapsed;
+ }
+ }
+ }
+ }
+
+ if (days_since_last_run == std::numeric_limits<int>::max()) {
+ days_since_last_run = -1;
+ }
+
+ return days_since_last_run;
+}

Powered by Google App Engine
This is Rietveld 408576698