Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / component_updater / component_patcher.cc
blob1170dd5449e73dcac6b16ccbf9daca882af744ae
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.
5 #include "chrome/browser/component_updater/component_patcher.h"
7 #include <string>
8 #include <vector>
10 #include "base/file_util.h"
11 #include "base/json/json_file_value_serializer.h"
12 #include "base/values.h"
13 #include "chrome/browser/component_updater/component_patcher_operation.h"
14 #include "chrome/browser/component_updater/component_updater_service.h"
16 namespace component_updater {
18 namespace {
20 // Deserialize the commands file (present in delta update packages). The top
21 // level must be a list.
22 base::ListValue* ReadCommands(const base::FilePath& unpack_path) {
23 const base::FilePath commands =
24 unpack_path.Append(FILE_PATH_LITERAL("commands.json"));
25 if (!base::PathExists(commands))
26 return NULL;
28 JSONFileValueSerializer serializer(commands);
29 scoped_ptr<base::Value> root(serializer.Deserialize(NULL, NULL));
31 return (root.get() && root->IsType(base::Value::TYPE_LIST)) ?
32 static_cast<base::ListValue*>(root.release()) : NULL;
35 } // namespace
38 // The patching support is not cross-platform at the moment.
39 ComponentPatcherCrossPlatform::ComponentPatcherCrossPlatform() {}
41 ComponentUnpacker::Error ComponentPatcherCrossPlatform::Patch(
42 PatchType patch_type,
43 const base::FilePath& input_file,
44 const base::FilePath& patch_file,
45 const base::FilePath& output_file,
46 int* error) {
47 return ComponentUnpacker::kDeltaUnsupportedCommand;
51 // Takes the contents of a differential component update in input_dir
52 // and produces the contents of a full component update in unpack_dir
53 // using input_abs_path_ files that the installer knows about.
54 ComponentUnpacker::Error DifferentialUpdatePatch(
55 const base::FilePath& input_dir,
56 const base::FilePath& unpack_dir,
57 ComponentPatcher* patcher,
58 ComponentInstaller* installer,
59 int* error) {
60 *error = 0;
61 scoped_ptr<base::ListValue> commands(ReadCommands(input_dir));
62 if (!commands.get())
63 return ComponentUnpacker::kDeltaBadCommands;
65 for (base::ValueVector::const_iterator command = commands->begin(),
66 end = commands->end(); command != end; command++) {
67 if (!(*command)->IsType(base::Value::TYPE_DICTIONARY))
68 return ComponentUnpacker::kDeltaBadCommands;
69 base::DictionaryValue* command_args =
70 static_cast<base::DictionaryValue*>(*command);
71 scoped_ptr<DeltaUpdateOp> operation(CreateDeltaUpdateOp(command_args));
72 if (!operation)
73 return ComponentUnpacker::kDeltaUnsupportedCommand;
75 ComponentUnpacker::Error result = operation->Run(
76 command_args, input_dir, unpack_dir, patcher, installer, error);
77 if (result != ComponentUnpacker::kNone)
78 return result;
81 return ComponentUnpacker::kNone;
84 } // namespace component_updater