| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 #ifndef CHROME_BROWSER_COMPONENT_UPDATER_CROS_COMPONENT_INSTALLER_H_ | 5 #ifndef CHROME_BROWSER_COMPONENT_UPDATER_CROS_COMPONENT_INSTALLER_H_ |
| 6 #define CHROME_BROWSER_COMPONENT_UPDATER_CROS_COMPONENT_INSTALLER_H_ | 6 #define CHROME_BROWSER_COMPONENT_UPDATER_CROS_COMPONENT_INSTALLER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 std::string dir_name; | 53 std::string dir_name; |
| 54 std::string name; | 54 std::string name; |
| 55 uint8_t kSha2Hash_[crypto::kSHA256Length] = {}; | 55 uint8_t kSha2Hash_[crypto::kSHA256Length] = {}; |
| 56 | 56 |
| 57 DISALLOW_COPY_AND_ASSIGN(CrOSComponentInstallerTraits); | 57 DISALLOW_COPY_AND_ASSIGN(CrOSComponentInstallerTraits); |
| 58 }; | 58 }; |
| 59 | 59 |
| 60 // This class contains functions used to register and install a component. | 60 // This class contains functions used to register and install a component. |
| 61 class CrOSComponent { | 61 class CrOSComponent { |
| 62 public: | 62 public: |
| 63 // Register and start installing a CrOS component. | 63 // Register and start installing a CrOS component. |
| 64 // |install_callback| is triggered after install finishes and returns error | 64 // |install_callback| is triggered after install finishes and returns error |
| 65 // code: update_client::Error::INVALID_ARGUMENT - component name is invalid. | 65 // code. |
| 66 // update_client::Error::NONE | 66 // |
| 67 // - successful install | 67 // example: |
| 68 // other error returns are processed by OnDemandUpdate upon install finishes. | 68 // ... |
| 69 // void PerformOperations(chromeos::DBusMethodCallStatus call_status, |
| 70 // const std::string& version){ |
| 71 // if (call_status != chromeos::DBUS_METHOD_CALL_SUCCESS) { |
| 72 // DVLOG(1) << "Call to imageloader service failed."; |
| 73 // return; |
| 74 // } |
| 75 // if (version.empty()) { |
| 76 // DVLOG(1) << "[PerformOperations] Component is not installed"; |
| 77 // return; |
| 78 // } |
| 79 // // [mounted compnent path: /run/imageloader/[component name]/[version]] |
| 80 // // |
| 81 // // [component is ready to do your work] |
| 82 // } |
| 83 // void install_callback(update_client::Error error){ |
| 84 // // switch(error){ |
| 85 // // case update_client::Error::NONE: |
| 86 // // // component is installed |
| 87 // // break; |
| 88 // // case update_client::Error::INVALID_ARGUMENT: |
| 89 // // // your install failed due of your wrong parameters. |
| 90 // // break; |
| 91 // // default: |
| 92 // // // your install failed due to system failure. |
| 93 // // break; |
| 94 // // } |
| 95 // // Even when error code other than NONE returned (your install failed), |
| 96 // // component might has already being installed previously. |
| 97 // // Plus, if you want to know current version of component. |
| 98 // chromeos::ImageLoaderClient* loader = |
| 99 // chromeos::DBusThreadManager::Get()->GetImageLoaderClient(); |
| 100 // if (loader) { |
| 101 // loader->GetComponentVersion("escpr", base::Bind(&PerformOperations)); |
| 102 // } else { |
| 103 // VLOG(0) << "Failed to get ImageLoaderClient object."; |
| 104 // } |
| 105 // } |
| 106 // ... |
| 107 // component_updater::CrOSComponent::InstallCrOSComponent( |
| 108 // name, |
| 109 // base::Bind(&install_callback)); |
| 110 // |
| 69 static bool InstallCrOSComponent( | 111 static bool InstallCrOSComponent( |
| 70 const std::string& name, | 112 const std::string& name, |
| 71 const update_client::Callback& install_callback); | 113 const update_client::Callback& install_callback); |
| 72 | 114 |
| 73 private: | 115 private: |
| 74 CrOSComponent() {} | 116 CrOSComponent() {} |
| 75 // Register a component. | 117 // Register a component. |
| 76 static void RegisterCrOSComponentInternal(ComponentUpdateService* cus, | 118 static void RegisterCrOSComponentInternal(ComponentUpdateService* cus, |
| 77 const ComponentConfig& config, | 119 const ComponentConfig& config, |
| 78 const base::Closure& callback); | 120 const base::Closure& callback); |
| 79 // A helper function to pass into RegisterCrOSComonentInternal as a callback. | 121 // A helper function to pass into RegisterCrOSComonentInternal as a callback. |
| 80 // It calls OnDemandUpdate to install the component right after being | 122 // It calls OnDemandUpdate to install the component right after being |
| 81 // registered. | 123 // registered. |
| 82 static void InstallChromeOSComponent( | 124 static void InstallChromeOSComponent( |
| 83 ComponentUpdateService* cus, | 125 ComponentUpdateService* cus, |
| 84 const std::string& id, | 126 const std::string& id, |
| 85 const update_client::Callback& install_callback); | 127 const update_client::Callback& install_callback); |
| 86 }; | 128 }; |
| 87 #endif // defined(OS_CHROMEOS) | 129 #endif // defined(OS_CHROMEOS) |
| 88 | 130 |
| 89 } // namespace component_updater | 131 } // namespace component_updater |
| 90 | 132 |
| 91 #endif // CHROME_BROWSER_COMPONENT_UPDATER_CROS_COMPONENT_INSTALLER_H_ | 133 #endif // CHROME_BROWSER_COMPONENT_UPDATER_CROS_COMPONENT_INSTALLER_H_ |
| OLD | NEW |