************************* G4 reminder *************************
These new files:
c:\MyDocs\Gears4\googleclient\gears\opensource\gears\installer\common\installer_utils.cc
are missing unit tests.
***************************************************************
Hello andreip,
I'd like you to do a code review. Please execute
g4 diff -c 8690890
or point your web browser to
http://mondrian/8690890
to review the following code:
Change 8690890 by [EMAIL PROTECTED] on 2008/10/22 18:39:52 *pending*
Modifies auto-updater for IE Mobile to manually download CAB without
the browser and to install it progrmatically, thus removing the need for user
interaction.
R=andreip
[EMAIL PROTECTED]
DELTA=141 (109 added, 18 deleted, 14 changed)
OCL=8690890
Affected files ...
... //depot/googleclient/gears/opensource/gears/Makefile#194 edit
... //depot/googleclient/gears/opensource/gears/base/ie/bho.cc#8 edit
...
//depot/googleclient/gears/opensource/gears/installer/common/installer_utils.cc#1
add
...
//depot/googleclient/gears/opensource/gears/installer/common/installer_utils.h#1
add
...
//depot/googleclient/gears/opensource/gears/installer/iemobile/cab_updater.cc#5
edit
...
//depot/googleclient/gears/opensource/gears/installer/iemobile/cab_updater.h#3
edit
141 delta lines: 109 added, 18 deleted, 14 changed
Also consider running:
g4 lint -c 8690890
which verifies that the changelist doesn't introduce new style violations.
If you can't do the review, please let me know as soon as possible. During
your review, please ensure that all new code has corresponding unit tests and
that existing unit tests are updated appropriately. Visit
http://www/eng/code_review.html for more information.
This is a semiautomated message from "g4 mail". Complaints or suggestions?
Mail [EMAIL PROTECTED]
Change 8690890 by [EMAIL PROTECTED] on 2008/10/22 18:39:52 *pending*
Modifies auto-updater for IE Mobile to manually download CAB without
the browser and to install it progrmatically, thus removing the need for user
interaction.
Affected files ...
... //depot/googleclient/gears/opensource/gears/Makefile#194 edit
... //depot/googleclient/gears/opensource/gears/base/ie/bho.cc#8 edit
...
//depot/googleclient/gears/opensource/gears/installer/common/installer_utils.cc#1
add
...
//depot/googleclient/gears/opensource/gears/installer/common/installer_utils.h#1
add
...
//depot/googleclient/gears/opensource/gears/installer/iemobile/cab_updater.cc#5
edit
...
//depot/googleclient/gears/opensource/gears/installer/iemobile/cab_updater.h#3
edit
==== //depot/googleclient/gears/opensource/gears/Makefile#194 -
c:\MyDocs\Gears4/googleclient/gears/opensource/gears/Makefile ====
# action=edit type=text
--- googleclient/gears/opensource/gears/Makefile 2008-10-22
18:36:08.000000000 +0100
+++ googleclient/gears/opensource/gears/Makefile 2008-10-22
18:50:11.000000000 +0100
@@ -2334,6 +2334,8 @@
$(BROWSER)_CPPSRCS += \
download_task.cc \
+ installer_utils.cc \
+ process_restarter.cc \
$(NULL)
endif
==== //depot/googleclient/gears/opensource/gears/base/ie/bho.cc#8 -
c:\MyDocs\Gears4/googleclient/gears/opensource/gears/base/ie/bho.cc ====
# action=edit type=xtext
--- googleclient/gears/opensource/gears/base/ie/bho.cc 2008-10-22
18:36:08.000000000 +0100
+++ googleclient/gears/opensource/gears/base/ie/bho.cc 2008-10-22
18:41:50.000000000 +0100
@@ -72,9 +72,10 @@
HttpHandler::Register();
#ifdef OS_WINCE
static CabUpdater updater;
+ updater.Start();
+
CComQIPtr<IWebBrowser2> site = pUnkSite;
ASSERT(site);
- updater.SetSiteAndStart(site);
assert(NULL == browser_window_);
site->get_HWND(reinterpret_cast<long*>(&browser_window_));
#endif
====
//depot/googleclient/gears/opensource/gears/installer/common/installer_utils.cc#1
-
c:\MyDocs\Gears4/googleclient/gears/opensource/gears/installer/common/installer_utils.cc
====
# action=add type=text
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ googleclient/gears/opensource/gears/installer/common/installer_utils.cc
2008-10-22 18:47:27.000000000 +0100
@@ -0,0 +1,43 @@
+// Copyright 2008, Google Inc.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+// 2. Redistributions in binary form must reproduce the above copyright
notice,
+// this list of conditions and the following disclaimer in the
documentation
+// and/or other materials provided with the distribution.
+// 3. Neither the name of Google Inc. nor the names of its contributors may be
+// used to endorse or promote products derived from this software without
+// specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
+// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#include "gears/installer/common/installer_utils.h"
+
+// TODO(steveblock): Move ProcessRetarter (and CabUpdater and PeriodicChecker)
+// to installer/common.
+#include "gears/installer/iemobile/process_restarter.h"
+
+static const char16 *kWceloadExe = L"\\Windows\\wceload.exe";
+
+bool InstallCab(const char16 *path) {
+ ProcessRestarter restarter(kWceloadExe, NULL);
+ std::string16 arguments;
+ arguments += L"\"";
+ arguments += path;
+ arguments += L"\"";
+ arguments += L" /noui"; // Do not show any UI
+ HRESULT result = restarter.StartTheProcess(arguments);
+ return SUCCEEDED(result);
+}
====
//depot/googleclient/gears/opensource/gears/installer/common/installer_utils.h#1
-
c:\MyDocs\Gears4/googleclient/gears/opensource/gears/installer/common/installer_utils.h
====
# action=add type=text
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ googleclient/gears/opensource/gears/installer/common/installer_utils.h
2008-10-22 18:39:58.000000000 +0100
@@ -0,0 +1,33 @@
+// Copyright 2008, Google Inc.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+// 2. Redistributions in binary form must reproduce the above copyright
notice,
+// this list of conditions and the following disclaimer in the
documentation
+// and/or other materials provided with the distribution.
+// 3. Neither the name of Google Inc. nor the names of its contributors may be
+// used to endorse or promote products derived from this software without
+// specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
+// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#ifndef GEARS_INSTALLER_COMMON_INSTALLER_UTILS_H__
+#define GEARS_INSTALLER_COMMON_INSTALLER_UTILS_H__
+
+#include "gears/base/common/string16.h"
+
+bool InstallCab(const char16 *path);
+
+#endif // GEARS_INSTALLER_COMMON_INSTALLER_UTILS_H__
====
//depot/googleclient/gears/opensource/gears/installer/iemobile/cab_updater.cc#5
-
c:\MyDocs\Gears4/googleclient/gears/opensource/gears/installer/iemobile/cab_updater.cc
====
# action=edit type=text
--- googleclient/gears/opensource/gears/installer/iemobile/cab_updater.cc
2008-10-22 18:36:08.000000000 +0100
+++ googleclient/gears/opensource/gears/installer/iemobile/cab_updater.cc
2008-10-22 18:43:43.000000000 +0100
@@ -28,6 +28,7 @@
#include "gears/base/common/string16.h"
#include "gears/base/common/thread_locals.h"
#include "gears/base/ie/bho.h"
+#include "gears/installer/common/installer_utils.h"
#include "gears/installer/iemobile/resource.h"
// TODO(andreip): When updating the Gears 'guid' field, consider switching
@@ -40,6 +41,8 @@
// The key for ThreadLocals.
const ThreadLocals::Slot kThreadLocalKey = ThreadLocals::Alloc();
+static const char16 *kTempCabPath = L"\\My Documents\\gears-wince-opt.cab";
+
// The delay before the first update.
const int32 kFirstUpdatePeriod = (1000 * 60 * 2); // 2 minutes
// The time interval between the rest of the update checks.
@@ -50,17 +53,20 @@
CabUpdater::CabUpdater()
: checker_(PeriodicChecker::CreateChecker()),
- is_showing_update_dialog_(false) {
+ is_showing_update_dialog_(false),
+ download_task_(NULL) {
}
CabUpdater::~CabUpdater() {
ASSERT(checker_);
delete checker_;
+ if (download_task_) {
+ download_task_->StopThreadAndDelete();
+ }
}
-void CabUpdater::SetSiteAndStart(IWebBrowser2* browser) {
+void CabUpdater::Start() {
ASSERT(checker_);
- browser_ = browser;
if (checker_->Init(kFirstUpdatePeriod, kUpdatePeriod, kGracePeriod,
kApplicationId, this)) {
MessageService::GetInstance()->AddObserver(this, kTopic);
@@ -73,30 +79,16 @@
void CabUpdater::OnNotify(MessageService *service,
const char16 *topic,
const NotificationData *data) {
+ assert(wcscmp(topic, kTopic) == 0);
+ assert(data == NULL);
// The user is already looking at the update dialog. Can only happen
// in rare circumstances, when an update was found, the browser is running
// but the user hasn't looked at it in the last 24 hours.
if (is_showing_update_dialog_) return;
- is_showing_update_dialog_ = true;
- // Get the event in the right format.
- const SerializableString16* update_event =
- static_cast<const SerializableString16*>(data);
- // Check if the browser is busy.
- VARIANT_BOOL is_busy;
- browser_->get_Busy(&is_busy);
- // Detect the browser state.
- READYSTATE state;
- browser_->get_ReadyState(&state);
- // Only show the update dialog if the browser isn't in the middle of a
- // download or showing some other notification to the user.
- if (!is_busy && state == READYSTATE_COMPLETE) {
- HWND browser_window = BrowserHelperObject::GetBrowserWindow();
- if (browser_window && ShowUpdateDialog(browser_window)) {
- // Convert the URL to the format expected by the browser object.
- CComBSTR url(update_event->string_.c_str());
- browser_->Navigate(url, NULL, NULL, NULL, NULL);
- }
+ if (ShowUpdateDialog()) {
+ // The cab installation process handles restarting the browser.
+ InstallCab(kTempCabPath);
}
is_showing_update_dialog_ = false;
}
@@ -119,7 +111,7 @@
MessageService::GetInstance()->RemoveObserver(updater, kTopic);
}
-bool CabUpdater::ShowUpdateDialog(HWND browser_window) {
+bool CabUpdater::ShowUpdateDialog() {
HMODULE module = GetModuleHandle(PRODUCT_SHORT_NAME);
if (!module) return false;
// Load the dialog strings
@@ -136,14 +128,26 @@
// Can't communicate with the user. Something is terribly wrong. Abort.
if (!message || !title) return false;
- return (IDYES == MessageBox(browser_window,
+ return (IDYES == MessageBox(BrowserHelperObject::GetBrowserWindow(),
message,
title,
MB_YESNO | MB_ICONQUESTION));
}
+// PeriodicChecker::ListenerInterface implementation
void CabUpdater::UpdateUrlAvailable(const std::string16 &url) {
+ // Start the download task
+ MutexLock lock(&download_task_mutex_);
+ if (download_task_ == NULL) {
+ download_task_ = DownloadTask::Create(url.c_str(), kTempCabPath, this);
+ }
+}
+
+// DownloadTask::ListenerInterface implementation
+void CabUpdater::DownloadComplete() {
// Marshall the callback to the browser thread so that we can show the
dialog.
- SerializableString16* update_event = new SerializableString16(url.c_str());
- MessageService::GetInstance()->NotifyObservers(kTopic, update_event);
+ MessageService::GetInstance()->NotifyObservers(kTopic, NULL);
+ MutexLock lock(&download_task_mutex_);
+ download_task_->StopThreadAndDelete();
+ download_task_ = NULL;
}
====
//depot/googleclient/gears/opensource/gears/installer/iemobile/cab_updater.h#3
-
c:\MyDocs\Gears4/googleclient/gears/opensource/gears/installer/iemobile/cab_updater.h
====
# action=edit type=text
--- googleclient/gears/opensource/gears/installer/iemobile/cab_updater.h
2008-10-22 18:36:08.000000000 +0100
+++ googleclient/gears/opensource/gears/installer/iemobile/cab_updater.h
2008-10-22 18:44:08.000000000 +0100
@@ -44,16 +44,18 @@
#include "gears/base/common/common.h"
#include "gears/base/common/message_service.h"
+#include "gears/installer/common/download_task.h"
#include "gears/installer/iemobile/periodic_checker.h"
class CabUpdater
: public MessageObserverInterface,
- public PeriodicChecker::ListenerInterface {
+ public PeriodicChecker::ListenerInterface,
+ public DownloadTask::ListenerInterface {
public:
CabUpdater();
virtual ~CabUpdater();
// Starts the updater.
- void SetSiteAndStart(IWebBrowser2* browser);
+ void Start();
// MessageObserverInterface
@@ -68,17 +70,23 @@
// Stop method called when the DLL unloads.
static void Stop(void* self);
// Shows the update dialog to the user.
- bool ShowUpdateDialog(HWND browser_window);
+ bool ShowUpdateDialog();
+
// PeriodicChecker::ListenerInterface implementation
virtual void UpdateUrlAvailable(const std::string16 &url);
- // We drive the browser through this IWebBrowser2 pointer. Not owned.
- IWebBrowser2* browser_;
+ // DownloadTask::ListenerInterface implementation
+ virtual void DownloadComplete();
+
// The periodic update checker. Owned.
PeriodicChecker* checker_;
// Is the update dialog showing?
bool is_showing_update_dialog_;
+ // The task to download the new CAB.
+ DownloadTask *download_task_;
+ Mutex download_task_mutex_;
+
DISALLOW_EVIL_CONSTRUCTORS(CabUpdater);
};