1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
// Copyright 2013 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/component_updater/component_patcher.h"
#include <string>
#include <vector>
#include "base/file_util.h"
#include "base/json/json_file_value_serializer.h"
#include "base/values.h"
#include "chrome/browser/component_updater/component_patcher_operation.h"
#include "chrome/browser/component_updater/component_updater_service.h"
namespace component_updater {
namespace {
// Deserialize the commands file (present in delta update packages). The top
// level must be a list.
base::ListValue* ReadCommands(const base::FilePath& unpack_path) {
const base::FilePath commands =
unpack_path.Append(FILE_PATH_LITERAL("commands.json"));
if (!base::PathExists(commands))
return NULL;
JSONFileValueSerializer serializer(commands);
scoped_ptr<base::Value> root(serializer.Deserialize(NULL, NULL));
return (root.get() && root->IsType(base::Value::TYPE_LIST)) ?
static_cast<base::ListValue*>(root.release()) : NULL;
}
} // namespace
// The patching support is not cross-platform at the moment.
ComponentPatcherCrossPlatform::ComponentPatcherCrossPlatform() {}
ComponentUnpacker::Error ComponentPatcherCrossPlatform::Patch(
PatchType patch_type,
const base::FilePath& input_file,
const base::FilePath& patch_file,
const base::FilePath& output_file,
int* error) {
return ComponentUnpacker::kDeltaUnsupportedCommand;
}
// Takes the contents of a differential component update in input_dir
// and produces the contents of a full component update in unpack_dir
// using input_abs_path_ files that the installer knows about.
void DifferentialUpdatePatch(
const base::FilePath& input_dir,
const base::FilePath& unpack_dir,
ComponentPatcher* patcher,
ComponentInstaller* installer,
base::Callback<void(ComponentUnpacker::Error, int)> callback) {
int error = 0;
scoped_ptr<base::ListValue> commands(ReadCommands(input_dir));
if (!commands.get()) {
callback.Run(ComponentUnpacker::kDeltaBadCommands, error);
return;
}
for (base::ValueVector::const_iterator command = commands->begin(),
end = commands->end(); command != end; command++) {
if (!(*command)->IsType(base::Value::TYPE_DICTIONARY)) {
callback.Run(ComponentUnpacker::kDeltaBadCommands, error);
return;
}
base::DictionaryValue* command_args =
static_cast<base::DictionaryValue*>(*command);
scoped_ptr<DeltaUpdateOp> operation(CreateDeltaUpdateOp(command_args));
if (!operation) {
callback.Run(ComponentUnpacker::kDeltaUnsupportedCommand, error);
return;
}
ComponentUnpacker::Error result = operation->Run(
command_args, input_dir, unpack_dir, patcher, installer, &error);
if (result != ComponentUnpacker::kNone) {
callback.Run(result, error);
return;
}
}
callback.Run(ComponentUnpacker::kNone, error);
}
} // namespace component_updater
|