update_client_internal.h 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // Copyright 2015 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. #ifndef COMPONENTS_UPDATE_CLIENT_UPDATE_CLIENT_INTERNAL_H_
  5. #define COMPONENTS_UPDATE_CLIENT_UPDATE_CLIENT_INTERNAL_H_
  6. #include <memory>
  7. #include <set>
  8. #include <string>
  9. #include <vector>
  10. #include "base/callback_forward.h"
  11. #include "base/containers/circular_deque.h"
  12. #include "base/memory/ref_counted.h"
  13. #include "base/observer_list.h"
  14. #include "base/threading/thread_checker.h"
  15. #include "components/update_client/crx_downloader.h"
  16. #include "components/update_client/update_checker.h"
  17. #include "components/update_client/update_client.h"
  18. namespace update_client {
  19. class Configurator;
  20. class PingManager;
  21. class Task;
  22. class UpdateEngine;
  23. enum class Error;
  24. class UpdateClientImpl : public UpdateClient {
  25. public:
  26. UpdateClientImpl(scoped_refptr<Configurator> config,
  27. scoped_refptr<PingManager> ping_manager,
  28. UpdateChecker::Factory update_checker_factory);
  29. UpdateClientImpl(const UpdateClientImpl&) = delete;
  30. UpdateClientImpl& operator=(const UpdateClientImpl&) = delete;
  31. // Overrides for UpdateClient.
  32. void AddObserver(Observer* observer) override;
  33. void RemoveObserver(Observer* observer) override;
  34. base::RepeatingClosure Install(
  35. const std::string& id,
  36. CrxDataCallback crx_data_callback,
  37. CrxStateChangeCallback crx_state_change_callback,
  38. Callback callback) override;
  39. void Update(const std::vector<std::string>& ids,
  40. CrxDataCallback crx_data_callback,
  41. CrxStateChangeCallback crx_state_change_callback,
  42. bool is_foreground,
  43. Callback callback) override;
  44. bool GetCrxUpdateState(const std::string& id,
  45. CrxUpdateItem* update_item) const override;
  46. bool IsUpdating(const std::string& id) const override;
  47. void Stop() override;
  48. void SendUninstallPing(const CrxComponent& crx_component,
  49. int reason,
  50. Callback callback) override;
  51. private:
  52. ~UpdateClientImpl() override;
  53. void RunTask(scoped_refptr<Task> task);
  54. void OnTaskComplete(Callback callback, scoped_refptr<Task> task, Error error);
  55. void NotifyObservers(Observer::Events event, const std::string& id);
  56. base::ThreadChecker thread_checker_;
  57. // True if Stop method has been called.
  58. bool is_stopped_ = false;
  59. scoped_refptr<Configurator> config_;
  60. // Contains the tasks that are pending. In the current implementation,
  61. // only update tasks (background tasks) are queued up. These tasks are
  62. // pending while they are in this queue. They have not been picked up yet
  63. // by the update engine.
  64. base::circular_deque<scoped_refptr<Task>> task_queue_;
  65. // Contains all tasks in progress. These are the tasks that the update engine
  66. // is executing at one moment. Install tasks are run concurrently, update
  67. // tasks are always serialized, and update tasks are queued up if install
  68. // tasks are running. In addition, concurrent install tasks for the same id
  69. // are not allowed.
  70. std::set<scoped_refptr<Task>> tasks_;
  71. scoped_refptr<PingManager> ping_manager_;
  72. scoped_refptr<UpdateEngine> update_engine_;
  73. base::ObserverList<Observer>::Unchecked observer_list_;
  74. };
  75. } // namespace update_client
  76. #endif // COMPONENTS_UPDATE_CLIENT_UPDATE_CLIENT_INTERNAL_H_