Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(604)

Side by Side Diff: chrome/browser/component_updater/component_patcher.cc

Issue 15908002: Differential updates for components. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Added missing const decl. Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 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 #include "chrome/browser/component_updater/component_patcher.h"
6
7 #include <string>
8 #include <vector>
9
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"
15
16 namespace {
17
18 // Deserialize the commands file (present in delta update packages). The top
19 // level must be a list.
20 base::ListValue* ReadCommands(const base::FilePath& unpack_path) {
21 const base::FilePath commands =
22 unpack_path.Append(FILE_PATH_LITERAL("commands.json"));
23 if (!file_util::PathExists(commands))
24 return NULL;
25
26 JSONFileValueSerializer serializer(commands);
27 scoped_ptr<base::Value> root(serializer.Deserialize(NULL, NULL));
28 if (!root.get())
29 return NULL;
30
31 if (!root->IsType(base::Value::TYPE_LIST))
32 return NULL;
33
34 return static_cast<base::ListValue*>(root.release());
35 }
36
37 } // namespace
38
39
40 // The patching support is not cross-platform at the moment.
41 ComponentPatcherCrossPlatform::ComponentPatcherCrossPlatform() {}
42
43 ComponentUnpacker::Error ComponentPatcherCrossPlatform::Patch(
44 PatchType patch_type,
45 const base::FilePath& input_file,
46 const base::FilePath& patch_file,
47 const base::FilePath& output_file,
48 int* error) {
49 return ComponentUnpacker::kDeltaUnsupportedCommand;
50 }
51
52
53 // Takes the contents of a differential component update in input_dir
54 // and produces the contents of a full component update in unpack_dir
55 // using input_abs_path_ files that the installer knows about.
56 ComponentUnpacker::Error DifferentialUpdatePatch(
57 const base::FilePath& input_dir,
58 const base::FilePath& unpack_dir,
59 ComponentPatcher* patcher,
60 ComponentInstaller* installer,
61 int* error) {
62 *error = 0;
63 scoped_ptr<base::ListValue> commands(ReadCommands(input_dir));
64 if (!commands.get())
65 return ComponentUnpacker::kDeltaBadCommands;
66
67 for (base::ValueVector::const_iterator command = commands->begin(),
68 end = commands->end(); command != end; command++) {
69 if (!(*command)->IsType(base::Value::TYPE_DICTIONARY))
70 return ComponentUnpacker::kDeltaBadCommands;
71 base::DictionaryValue* command_args =
72 static_cast<base::DictionaryValue*>(*command);
73 scoped_ptr<DeltaUpdateOp> operation(CreateDeltaUpdateOp(command_args));
74 if (!operation)
75 return ComponentUnpacker::kDeltaUnsupportedCommand;
76
77 ComponentUnpacker::Error result = operation->Run(
78 command_args, input_dir, unpack_dir, patcher, installer, error);
79 if (result != ComponentUnpacker::kNone)
80 return result;
81 }
82
83 return ComponentUnpacker::kNone;
84 }
85
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698