| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef COMPONENTS_DOWNLOAD_INTERNAL_CONTROLLER_IMPL_H_ |
| 6 #define COMPONENTS_DOWNLOAD_INTERNAL_CONTROLLER_IMPL_H_ |
| 7 |
| 8 #include <map> |
| 9 #include <memory> |
| 10 |
| 11 #include "base/macros.h" |
| 12 #include "base/optional.h" |
| 13 #include "components/download/internal/controller.h" |
| 14 #include "components/download/internal/download_driver.h" |
| 15 #include "components/download/internal/model.h" |
| 16 #include "components/download/internal/startup_status.h" |
| 17 #include "components/download/public/download_params.h" |
| 18 |
| 19 namespace download { |
| 20 |
| 21 class ClientSet; |
| 22 class DownloadDriver; |
| 23 class Model; |
| 24 |
| 25 struct Configuration; |
| 26 struct SchedulingParams; |
| 27 |
| 28 // The internal Controller implementation. This class does all of the heavy |
| 29 // lifting for the DownloadService. |
| 30 class ControllerImpl : public Controller, |
| 31 public DownloadDriver::Client, |
| 32 public Model::Client { |
| 33 public: |
| 34 // |clients| is externally owned and must be guaranteed to outlive this class. |
| 35 ControllerImpl(std::unique_ptr<ClientSet> clients, |
| 36 std::unique_ptr<Configuration> config, |
| 37 std::unique_ptr<DownloadDriver> driver, |
| 38 std::unique_ptr<Model> model); |
| 39 ~ControllerImpl() override; |
| 40 |
| 41 // Controller implementation. |
| 42 void Initialize() override; |
| 43 const StartupStatus& GetStartupStatus() override; |
| 44 void StartDownload(const DownloadParams& params) override; |
| 45 void PauseDownload(const std::string& guid) override; |
| 46 void ResumeDownload(const std::string& guid) override; |
| 47 void CancelDownload(const std::string& guid) override; |
| 48 void ChangeDownloadCriteria(const std::string& guid, |
| 49 const SchedulingParams& params) override; |
| 50 DownloadClient GetOwnerOfDownload(const std::string& guid) override; |
| 51 |
| 52 private: |
| 53 // DownloadDriver::Client implementation. |
| 54 void OnDriverReady(bool success) override; |
| 55 void OnDownloadCreated(const DriverEntry& download) override; |
| 56 void OnDownloadFailed(const DriverEntry& download, int reason) override; |
| 57 void OnDownloadSucceeded(const DriverEntry& download, |
| 58 const base::FilePath& path) override; |
| 59 void OnDownloadUpdated(const DriverEntry& download) override; |
| 60 |
| 61 // Model::Client implementation. |
| 62 void OnModelReady(bool success) override; |
| 63 void OnItemAdded(bool success, |
| 64 DownloadClient client, |
| 65 const std::string& guid) override; |
| 66 void OnItemUpdated(bool success, |
| 67 DownloadClient client, |
| 68 const std::string& guid) override; |
| 69 void OnItemRemoved(bool success, |
| 70 DownloadClient client, |
| 71 const std::string& guid) override; |
| 72 |
| 73 // Checks if initialization is complete and successful. If so, completes the |
| 74 // internal state initialization. |
| 75 void AttemptToFinalizeSetup(); |
| 76 |
| 77 // Cancels and cleans upany requests that are no longer associated with a |
| 78 // Client in |clients_|. |
| 79 void CancelOrphanedRequests(); |
| 80 |
| 81 // Fixes any discrepencies in state between |model_| and |driver_|. Meant to |
| 82 // resolve state issues during startup. |
| 83 void ResolveInitialRequestStates(); |
| 84 |
| 85 // Notifies all Client in |clients_| that this controller is initialized and |
| 86 // lets them know which download requests we are aware of for their |
| 87 // DownloadClient. |
| 88 void NotifyClientsOfStartup(); |
| 89 |
| 90 // Pulls the current state of requests from |model_| and |driver_| and sets |
| 91 // the other internal states appropriately. |
| 92 void PullCurrentRequestStatus(); |
| 93 |
| 94 void HandleStartDownloadResponse(DownloadClient client, |
| 95 const std::string& guid, |
| 96 DownloadParams::StartResult result); |
| 97 void HandleStartDownloadResponse( |
| 98 DownloadClient client, |
| 99 const std::string& guid, |
| 100 DownloadParams::StartResult result, |
| 101 const DownloadParams::StartCallback& callback); |
| 102 |
| 103 std::unique_ptr<ClientSet> clients_; |
| 104 std::unique_ptr<Configuration> config_; |
| 105 |
| 106 // Owned Dependencies. |
| 107 std::unique_ptr<DownloadDriver> driver_; |
| 108 std::unique_ptr<Model> model_; |
| 109 |
| 110 // Internal state. |
| 111 StartupStatus startup_status_; |
| 112 std::map<std::string, DownloadParams::StartCallback> start_callbacks_; |
| 113 |
| 114 DISALLOW_COPY_AND_ASSIGN(ControllerImpl); |
| 115 }; |
| 116 |
| 117 } // namespace download |
| 118 |
| 119 #endif // COMPONENTS_DOWNLOAD_INTERNAL_CONTROLLER_IMPL_H_ |
| OLD | NEW |