************************* G4 reminder *************************
These new files:
c:\MyDocs\Gears4\googleclient\gears\opensource\gears\installer\common\download_task.cc
are missing unit tests.
***************************************************************
Hello andreip,
I'd like you to do a code review. Please execute
g4 diff -c 8688674
or point your web browser to
http://mondrian/8688674
to review the following code:
Change 8688674 by [EMAIL PROTECTED] on 2008/10/22 14:56:24 *pending*
Factors out download task for use in installers on WinCE.
This is based on installers/android/zip_download_task. Long term, the
Android installer should be refactored to use this common class, but this will
require re-writing some Android-specific code.
R=andreip
[EMAIL PROTECTED]
DELTA=208 (208 added, 0 deleted, 0 changed)
OCL=8688674
Affected files ...
... //depot/googleclient/gears/opensource/gears/Makefile#193 edit
...
//depot/googleclient/gears/opensource/gears/installer/common/download_task.cc#1
add
...
//depot/googleclient/gears/opensource/gears/installer/common/download_task.h#1
add
208 delta lines: 208 added, 0 deleted, 0 changed
Also consider running:
g4 lint -c 8688674
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 8688674 by [EMAIL PROTECTED] on 2008/10/22 14:56:24 *pending*
Factors out download task for use in installers on WinCE.
This is based on installers/android/zip_download_task. Long term, the
Android installer should be refactored to use this common class, but this will
require re-writing some Android-specific code.
Affected files ...
... //depot/googleclient/gears/opensource/gears/Makefile#193 edit
...
//depot/googleclient/gears/opensource/gears/installer/common/download_task.cc#1
add
...
//depot/googleclient/gears/opensource/gears/installer/common/download_task.h#1
add
==== //depot/googleclient/gears/opensource/gears/Makefile#193 -
c:\MyDocs\Gears4/googleclient/gears/opensource/gears/Makefile ====
# action=edit type=text
--- googleclient/gears/opensource/gears/Makefile 2008-10-20
23:17:13.000000000 +0100
+++ googleclient/gears/opensource/gears/Makefile 2008-10-22
14:57:35.000000000 +0100
@@ -2325,6 +2325,19 @@
endif
#-----------------------------------------------------------------------------
+# installer/common
+
+ifeq ($(OS),wince)
+$(BROWSER)_VPATH += \
+ installer/common \
+ $(NULL)
+
+$(BROWSER)_CPPSRCS += \
+ download_task.cc \
+ $(NULL)
+endif
+
+#-----------------------------------------------------------------------------
# installer/iemobile
ifeq ($(OS),wince)
====
//depot/googleclient/gears/opensource/gears/installer/common/download_task.cc#1
-
c:\MyDocs\Gears4/googleclient/gears/opensource/gears/installer/common/download_task.cc
====
# action=add type=text
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ googleclient/gears/opensource/gears/installer/common/download_task.cc
2008-10-22 14:56:26.000000000 +0100
@@ -0,0 +1,127 @@
+// 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/download_task.h"
+
+#include "gears/base/common/file.h"
+#include "gears/blob/blob_interface.h"
+#include "gears/blob/blob_utils.h"
+
+static const int kBufferSizeBytes = 32 * 1024; // 32 Kb
+
+// static
+DownloadTask *DownloadTask::Create(const char16* url,
+ const char16* save_path,
+ ListenerInterface *listener) {
+ scoped_ptr<DownloadTask> task(new DownloadTask(url, save_path, listener));
+ assert(task.get());
+ if (!task.get() || !task->Init() || !task->Start()) {
+ return NULL;
+ }
+ return task.release();
+}
+
+void DownloadTask::StopThreadAndDelete() {
+ Abort();
+ DeleteWhenDone();
+}
+
+DownloadTask::DownloadTask(const char16* url,
+ const char16* save_path,
+ ListenerInterface *listener)
+ : AsyncTask(NULL),
+ url_(url),
+ save_path_(save_path),
+ listener_(listener) {
+ assert(listener_);
+}
+
+// AsyncTask implementation
+void DownloadTask::Run() {
+ WebCacheDB::PayloadInfo payload;
+ scoped_refptr<BlobInterface> payload_data;
+ bool was_redirected;
+ bool success = false;
+ if (AsyncTask::HttpGet(url_.c_str(),
+ true,
+ NULL,
+ NULL,
+ NULL,
+ &payload,
+ &payload_data,
+ &was_redirected,
+ NULL, // full_redirect_url
+ NULL)) { // error_msg
+ // payload_data can be empty in case of a 30x response.
+ // The update server does not redirect, so we treat this as an error.
+ if (!was_redirected &&
+ payload.PassesValidationTests(NULL) &&
+ payload_data->Length() &&
+ SaveToFile(payload_data.get())) {
+ success = true;
+ }
+ }
+ listener_->DownloadComplete();
+}
+
+bool DownloadTask::SaveToFile(BlobInterface *data) {
+ assert(data != NULL);
+ std::string16 directory;
+ if (!File::GetParentDirectory(save_path_, &directory)) {
+ LOG(("DownloadTask::SaveToFile : Failed to get parent directory."));
+ return false;
+ }
+ if (!File::RecursivelyCreateDir(directory.c_str())) {
+ LOG(("DownloadTask::SaveToFile : Could not create save directory."));
+ return false;
+ }
+
+ scoped_ptr<File> file(File::Open(save_path_.c_str(),
+ File::WRITE, File::NEVER_FAIL));
+ if (!file.get()) {
+ LOG(("DownloadTask::SaveToFile : Could not create file."));
+ return false;
+ }
+
+ scoped_array<uint8> buffer;
+ buffer.reset(new uint8[kBufferSizeBytes]);
+ int64 offset = 0;
+ int64 counter = 0;
+ do {
+ counter = data->Read(buffer.get(), offset, kBufferSizeBytes);
+ if (counter > 0) {
+ file->Write(buffer.get(), counter);
+ offset += counter;
+ }
+ } while (kBufferSizeBytes == counter);
+
+ if (counter < 0) {
+ assert(counter == -1);
+ LOG(("DownloadTask::SaveToFile : Could not save to temp directory."));
+ return false;
+ }
+
+ return true;
+}
====
//depot/googleclient/gears/opensource/gears/installer/common/download_task.h#1
-
c:\MyDocs\Gears4/googleclient/gears/opensource/gears/installer/common/download_task.h
====
# action=add type=text
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ googleclient/gears/opensource/gears/installer/common/download_task.h
2008-10-22 14:56:28.000000000 +0100
@@ -0,0 +1,68 @@
+// 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_DOWNLOAD_TASK_H__
+#define GEARS_INSTALLER_COMMON_DOWNLOAD_TASK_H__
+
+#include "gears/base/common/common.h"
+#include "gears/localserver/common/async_task.h"
+
+class BlobInterface;
+
+// A task that downloads a new version of Gears.
+class DownloadTask : public AsyncTask {
+ public:
+ friend class scoped_ptr<DownloadTask>;
+
+ class ListenerInterface {
+ public:
+ virtual void DownloadComplete() = 0;
+ };
+
+ static DownloadTask *Create(const char16 *url,
+ const char16 *save_path,
+ ListenerInterface *listener);
+ void StopThreadAndDelete();
+
+ private:
+ // Use Create and StopThreadAndDelete to create and destroy
+ DownloadTask(const char16 *url,
+ const char16 *save_path,
+ ListenerInterface *listener);
+ virtual ~DownloadTask() {}
+
+ // AsyncTask implementation
+ virtual void Run();
+
+ bool SaveToFile(BlobInterface *data);
+
+ std::string16 url_;
+ std::string16 save_path_;
+ ListenerInterface *listener_;
+
+ DISALLOW_EVIL_CONSTRUCTORS(DownloadTask);
+};
+
+#endif // GEARS_INSTALLER_COMMON_DOWNLOAD_TASK_H__