real_updater_provider.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. //
  2. // Copyright (C) 2014 The Android Open Source Project
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. //
  16. #ifndef UPDATE_ENGINE_UPDATE_MANAGER_REAL_UPDATER_PROVIDER_H_
  17. #define UPDATE_ENGINE_UPDATE_MANAGER_REAL_UPDATER_PROVIDER_H_
  18. #include <memory>
  19. #include <string>
  20. #include "update_engine/system_state.h"
  21. #include "update_engine/update_manager/generic_variables.h"
  22. #include "update_engine/update_manager/updater_provider.h"
  23. namespace chromeos_update_manager {
  24. // A concrete UpdaterProvider implementation using local (in-process) bindings.
  25. class RealUpdaterProvider : public UpdaterProvider {
  26. public:
  27. // We assume that any other object handle we get from the system state is
  28. // "volatile", and so must be re-acquired whenever access is needed; this
  29. // guarantees that parts of the system state can be mocked out at any time
  30. // during testing. We further assume that, by the time Init() is called, the
  31. // system state object is fully populated and usable.
  32. explicit RealUpdaterProvider(
  33. chromeos_update_engine::SystemState* system_state);
  34. // Initializes the provider and returns whether it succeeded.
  35. bool Init() { return true; }
  36. Variable<base::Time>* var_updater_started_time() override {
  37. return &var_updater_started_time_;
  38. }
  39. Variable<base::Time>* var_last_checked_time() override {
  40. return var_last_checked_time_.get();
  41. }
  42. Variable<base::Time>* var_update_completed_time() override {
  43. return var_update_completed_time_.get();
  44. }
  45. Variable<double>* var_progress() override { return var_progress_.get(); }
  46. Variable<Stage>* var_stage() override { return var_stage_.get(); }
  47. Variable<std::string>* var_new_version() override {
  48. return var_new_version_.get();
  49. }
  50. Variable<uint64_t>* var_payload_size() override {
  51. return var_payload_size_.get();
  52. }
  53. Variable<std::string>* var_curr_channel() override {
  54. return var_curr_channel_.get();
  55. }
  56. Variable<std::string>* var_new_channel() override {
  57. return var_new_channel_.get();
  58. }
  59. Variable<bool>* var_p2p_enabled() override { return var_p2p_enabled_.get(); }
  60. Variable<bool>* var_cellular_enabled() override {
  61. return var_cellular_enabled_.get();
  62. }
  63. Variable<unsigned int>* var_consecutive_failed_update_checks() override {
  64. return var_consecutive_failed_update_checks_.get();
  65. }
  66. Variable<unsigned int>* var_server_dictated_poll_interval() override {
  67. return var_server_dictated_poll_interval_.get();
  68. }
  69. Variable<UpdateRequestStatus>* var_forced_update_requested() override {
  70. return var_forced_update_requested_.get();
  71. }
  72. Variable<UpdateRestrictions>* var_update_restrictions() override {
  73. return var_update_restrictions_.get();
  74. }
  75. private:
  76. // A pointer to the update engine's system state aggregator.
  77. chromeos_update_engine::SystemState* system_state_;
  78. // Variable implementations.
  79. ConstCopyVariable<base::Time> var_updater_started_time_;
  80. std::unique_ptr<Variable<base::Time>> var_last_checked_time_;
  81. std::unique_ptr<Variable<base::Time>> var_update_completed_time_;
  82. std::unique_ptr<Variable<double>> var_progress_;
  83. std::unique_ptr<Variable<Stage>> var_stage_;
  84. std::unique_ptr<Variable<std::string>> var_new_version_;
  85. std::unique_ptr<Variable<uint64_t>> var_payload_size_;
  86. std::unique_ptr<Variable<std::string>> var_curr_channel_;
  87. std::unique_ptr<Variable<std::string>> var_new_channel_;
  88. std::unique_ptr<Variable<bool>> var_p2p_enabled_;
  89. std::unique_ptr<Variable<bool>> var_cellular_enabled_;
  90. std::unique_ptr<Variable<unsigned int>> var_consecutive_failed_update_checks_;
  91. std::unique_ptr<Variable<unsigned int>> var_server_dictated_poll_interval_;
  92. std::unique_ptr<Variable<UpdateRequestStatus>> var_forced_update_requested_;
  93. std::unique_ptr<Variable<UpdateRestrictions>> var_update_restrictions_;
  94. DISALLOW_COPY_AND_ASSIGN(RealUpdaterProvider);
  95. };
  96. } // namespace chromeos_update_manager
  97. #endif // UPDATE_ENGINE_UPDATE_MANAGER_REAL_UPDATER_PROVIDER_H_