Home | History | Annotate | Download | only in component_updater
      1 // Copyright 2013 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 // Component updates can be either differential updates or full updates.
      6 // Full updates come in CRX format; differential updates come in CRX-style
      7 // archives, but have a different magic number. They contain "commands.json", a
      8 // list of commands for the patcher to follow. The patcher uses these commands,
      9 // the other files in the archive, and the files from the existing installation
     10 // of the component to create the contents of a full update, which is then
     11 // installed normally.
     12 // Component updates are specified by the 'codebasediff' attribute of an
     13 // updatecheck response:
     14 //   <updatecheck codebase="http://example.com/extension_1.2.3.4.crx"
     15 //                hash="12345" size="9854" status="ok" version="1.2.3.4"
     16 //                prodversionmin="2.0.143.0"
     17 //                codebasediff="http://example.com/diff_1.2.3.4.crx"
     18 //                hashdiff="123" sizediff="101"
     19 //                fp="1.123" />
     20 // The component updater will attempt a differential update if it is available
     21 // and allowed to, and fall back to a full update if it fails.
     22 //
     23 // After installation (diff or full), the component updater records "fp", the
     24 // fingerprint of the installed files, to later identify the existing files to
     25 // the server so that a proper differential update can be provided next cycle.
     26 
     27 
     28 #ifndef CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_PATCHER_H_
     29 #define CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_PATCHER_H_
     30 
     31 #include "base/basictypes.h"
     32 #include "base/compiler_specific.h"
     33 #include "chrome/browser/component_updater/component_unpacker.h"
     34 
     35 namespace base {
     36 class FilePath;
     37 }
     38 
     39 class ComponentInstaller;
     40 
     41 // Applies a delta patch to a single file. Specifically, creates a file at
     42 // |output_file| using |input_file| patched according to the algorithm
     43 // specified by |patch_type| using |patch_file|. Sets the value of error to
     44 // the error code of the failing patch operation, if there is such a failure.
     45 class ComponentPatcher {
     46  public:
     47   // The type of a patch file.
     48   enum PatchType {
     49     kPatchTypeUnknown,
     50     kPatchTypeCourgette,
     51     kPatchTypeBsdiff,
     52   };
     53 
     54   virtual ComponentUnpacker::Error Patch(PatchType patch_type,
     55                                          const base::FilePath& input_file,
     56                                          const base::FilePath& patch_file,
     57                                          const base::FilePath& output_file,
     58                                          int* error) = 0;
     59   virtual ~ComponentPatcher() {}
     60 };
     61 
     62 class ComponentPatcherCrossPlatform : public ComponentPatcher {
     63  public:
     64   ComponentPatcherCrossPlatform();
     65   virtual ComponentUnpacker::Error Patch(PatchType patch_type,
     66                                          const base::FilePath& input_file,
     67                                          const base::FilePath& patch_file,
     68                                          const base::FilePath& output_file,
     69                                          int* error) OVERRIDE;
     70  private:
     71   DISALLOW_COPY_AND_ASSIGN(ComponentPatcherCrossPlatform);
     72 };
     73 
     74 // This function takes an unpacked differential CRX (|input_dir|) and a
     75 // component installer, and creates a new (non-differential) unpacked CRX, which
     76 // is then installed normally.
     77 // The non-differential files are written into the |unpack_dir| directory.
     78 // Sets |error| to the error code of the first failing patch operation.
     79 ComponentUnpacker::Error DifferentialUpdatePatch(
     80     const base::FilePath& input_dir,
     81     const base::FilePath& unpack_dir,
     82     ComponentPatcher* component_patcher,
     83     ComponentInstaller* installer,
     84     int* error);
     85 
     86 #endif  // CHROME_BROWSER_COMPONENT_UPDATER_COMPONENT_PATCHER_H_
     87