OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/component_updater/component_patcher.h" | 5 #include "chrome/browser/component_updater/component_patcher.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 ? static_cast<base::ListValue*>(root.release()) | 37 ? static_cast<base::ListValue*>(root.release()) |
38 : NULL; | 38 : NULL; |
39 } | 39 } |
40 | 40 |
41 } // namespace | 41 } // namespace |
42 | 42 |
43 ComponentPatcher::ComponentPatcher( | 43 ComponentPatcher::ComponentPatcher( |
44 const base::FilePath& input_dir, | 44 const base::FilePath& input_dir, |
45 const base::FilePath& unpack_dir, | 45 const base::FilePath& unpack_dir, |
46 ComponentInstaller* installer, | 46 ComponentInstaller* installer, |
47 bool in_process, | 47 DeltaUpdateOpFactory* delta_update_op_factory, |
48 scoped_refptr<base::SequencedTaskRunner> task_runner) | 48 scoped_refptr<base::SequencedTaskRunner> task_runner) |
49 : input_dir_(input_dir), | 49 : input_dir_(input_dir), |
50 unpack_dir_(unpack_dir), | 50 unpack_dir_(unpack_dir), |
51 installer_(installer), | 51 installer_(installer), |
52 in_process_(in_process), | 52 delta_update_op_factory_(delta_update_op_factory), |
53 task_runner_(task_runner) { | 53 task_runner_(task_runner) { |
54 } | 54 } |
55 | 55 |
56 ComponentPatcher::~ComponentPatcher() { | 56 ComponentPatcher::~ComponentPatcher() { |
57 } | 57 } |
58 | 58 |
59 void ComponentPatcher::Start(const ComponentUnpacker::Callback& callback) { | 59 void ComponentPatcher::Start(const ComponentUnpacker::Callback& callback) { |
60 callback_ = callback; | 60 callback_ = callback; |
61 task_runner_->PostTask(FROM_HERE, | 61 task_runner_->PostTask(FROM_HERE, |
62 base::Bind(&ComponentPatcher::StartPatching, | 62 base::Bind(&ComponentPatcher::StartPatching, |
(...skipping 14 matching lines...) Expand all Loading... |
77 if (next_command_ == commands_->end()) { | 77 if (next_command_ == commands_->end()) { |
78 DonePatching(ComponentUnpacker::kNone, 0); | 78 DonePatching(ComponentUnpacker::kNone, 0); |
79 return; | 79 return; |
80 } | 80 } |
81 if (!(*next_command_)->IsType(base::Value::TYPE_DICTIONARY)) { | 81 if (!(*next_command_)->IsType(base::Value::TYPE_DICTIONARY)) { |
82 DonePatching(ComponentUnpacker::kDeltaBadCommands, 0); | 82 DonePatching(ComponentUnpacker::kDeltaBadCommands, 0); |
83 return; | 83 return; |
84 } | 84 } |
85 const base::DictionaryValue* command_args = | 85 const base::DictionaryValue* command_args = |
86 static_cast<base::DictionaryValue*>(*next_command_); | 86 static_cast<base::DictionaryValue*>(*next_command_); |
87 current_operation_ = CreateDeltaUpdateOp(*command_args); | 87 |
| 88 std::string operation; |
| 89 if (command_args->GetString(kOp, &operation)) { |
| 90 current_operation_ = |
| 91 delta_update_op_factory_->CreateDeltaUpdateOp(operation); |
| 92 } |
| 93 |
88 if (!current_operation_) { | 94 if (!current_operation_) { |
89 DonePatching(ComponentUnpacker::kDeltaUnsupportedCommand, 0); | 95 DonePatching(ComponentUnpacker::kDeltaUnsupportedCommand, 0); |
90 return; | 96 return; |
91 } | 97 } |
92 current_operation_->Run(command_args, | 98 current_operation_->Run(command_args, |
93 input_dir_, | 99 input_dir_, |
94 unpack_dir_, | 100 unpack_dir_, |
95 installer_, | 101 installer_, |
96 in_process_, | |
97 base::Bind(&ComponentPatcher::DonePatchingFile, | 102 base::Bind(&ComponentPatcher::DonePatchingFile, |
98 scoped_refptr<ComponentPatcher>(this)), | 103 scoped_refptr<ComponentPatcher>(this)), |
99 task_runner_); | 104 task_runner_); |
100 } | 105 } |
101 | 106 |
102 void ComponentPatcher::DonePatchingFile(ComponentUnpacker::Error error, | 107 void ComponentPatcher::DonePatchingFile(ComponentUnpacker::Error error, |
103 int extended_error) { | 108 int extended_error) { |
104 if (error != ComponentUnpacker::kNone) { | 109 if (error != ComponentUnpacker::kNone) { |
105 DonePatching(error, extended_error); | 110 DonePatching(error, extended_error); |
106 } else { | 111 } else { |
107 ++next_command_; | 112 ++next_command_; |
108 PatchNextFile(); | 113 PatchNextFile(); |
109 } | 114 } |
110 } | 115 } |
111 | 116 |
112 void ComponentPatcher::DonePatching(ComponentUnpacker::Error error, | 117 void ComponentPatcher::DonePatching(ComponentUnpacker::Error error, |
113 int extended_error) { | 118 int extended_error) { |
114 current_operation_ = NULL; | 119 current_operation_ = NULL; |
115 task_runner_->PostTask(FROM_HERE, | 120 task_runner_->PostTask(FROM_HERE, |
116 base::Bind(callback_, error, extended_error)); | 121 base::Bind(callback_, error, extended_error)); |
117 callback_.Reset(); | 122 callback_.Reset(); |
118 } | 123 } |
119 | 124 |
120 } // namespace component_updater | 125 } // namespace component_updater |
OLD | NEW |