| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/update_client/component_patcher.h" | 5 #include "components/update_client/component_patcher.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
| 12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 13 #include "base/files/file_util.h" | 13 #include "base/files/file_util.h" |
| 14 #include "base/json/json_file_value_serializer.h" | 14 #include "base/json/json_file_value_serializer.h" |
| 15 #include "base/location.h" | 15 #include "base/location.h" |
| 16 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
| 17 #include "base/values.h" | 17 #include "base/values.h" |
| 18 #include "components/update_client/component_patcher_operation.h" | 18 #include "components/update_client/component_patcher_operation.h" |
| 19 #include "components/update_client/update_client.h" |
| 19 | 20 |
| 20 namespace update_client { | 21 namespace update_client { |
| 21 | 22 |
| 22 namespace { | 23 namespace { |
| 23 | 24 |
| 24 // Deserialize the commands file (present in delta update packages). The top | 25 // Deserialize the commands file (present in delta update packages). The top |
| 25 // level must be a list. | 26 // level must be a list. |
| 26 base::ListValue* ReadCommands(const base::FilePath& unpack_path) { | 27 base::ListValue* ReadCommands(const base::FilePath& unpack_path) { |
| 27 const base::FilePath commands = | 28 const base::FilePath commands = |
| 28 unpack_path.Append(FILE_PATH_LITERAL("commands.json")); | 29 unpack_path.Append(FILE_PATH_LITERAL("commands.json")); |
| 29 if (!base::PathExists(commands)) | 30 if (!base::PathExists(commands)) |
| 30 return NULL; | 31 return NULL; |
| 31 | 32 |
| 32 JSONFileValueSerializer serializer(commands); | 33 JSONFileValueSerializer serializer(commands); |
| 33 scoped_ptr<base::Value> root(serializer.Deserialize(NULL, NULL)); | 34 scoped_ptr<base::Value> root(serializer.Deserialize(NULL, NULL)); |
| 34 | 35 |
| 35 return (root.get() && root->IsType(base::Value::TYPE_LIST)) | 36 return (root.get() && root->IsType(base::Value::TYPE_LIST)) |
| 36 ? static_cast<base::ListValue*>(root.release()) | 37 ? static_cast<base::ListValue*>(root.release()) |
| 37 : NULL; | 38 : NULL; |
| 38 } | 39 } |
| 39 | 40 |
| 40 } // namespace | 41 } // namespace |
| 41 | 42 |
| 42 ComponentPatcher::ComponentPatcher( | 43 ComponentPatcher::ComponentPatcher( |
| 43 const base::FilePath& input_dir, | 44 const base::FilePath& input_dir, |
| 44 const base::FilePath& unpack_dir, | 45 const base::FilePath& unpack_dir, |
| 45 ComponentInstaller* installer, | 46 scoped_refptr<ComponentInstaller> installer, |
| 46 scoped_refptr<OutOfProcessPatcher> out_of_process_patcher, | 47 scoped_refptr<OutOfProcessPatcher> out_of_process_patcher, |
| 47 scoped_refptr<base::SequencedTaskRunner> task_runner) | 48 scoped_refptr<base::SequencedTaskRunner> task_runner) |
| 48 : input_dir_(input_dir), | 49 : input_dir_(input_dir), |
| 49 unpack_dir_(unpack_dir), | 50 unpack_dir_(unpack_dir), |
| 50 installer_(installer), | 51 installer_(installer), |
| 51 out_of_process_patcher_(out_of_process_patcher), | 52 out_of_process_patcher_(out_of_process_patcher), |
| 52 task_runner_(task_runner) { | 53 task_runner_(task_runner) { |
| 53 } | 54 } |
| 54 | 55 |
| 55 ComponentPatcher::~ComponentPatcher() { | 56 ComponentPatcher::~ComponentPatcher() { |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 | 113 |
| 113 void ComponentPatcher::DonePatching(ComponentUnpacker::Error error, | 114 void ComponentPatcher::DonePatching(ComponentUnpacker::Error error, |
| 114 int extended_error) { | 115 int extended_error) { |
| 115 current_operation_ = NULL; | 116 current_operation_ = NULL; |
| 116 task_runner_->PostTask(FROM_HERE, | 117 task_runner_->PostTask(FROM_HERE, |
| 117 base::Bind(callback_, error, extended_error)); | 118 base::Bind(callback_, error, extended_error)); |
| 118 callback_.Reset(); | 119 callback_.Reset(); |
| 119 } | 120 } |
| 120 | 121 |
| 121 } // namespace update_client | 122 } // namespace update_client |
| OLD | NEW |