Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Side by Side Diff: components/download/internal/controller_impl.h

Issue 2895953004: Add initial Controller to DownloadService (Closed)
Patch Set: Moved stats out Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 OnModelDestroyed(bool success) override;
64 void OnItemAdded(bool success,
65 DownloadClient client,
66 const std::string& guid) override;
67 void OnItemUpdated(bool success,
68 DownloadClient client,
69 const std::string& guid) override;
70 void OnItemRemoved(bool success,
71 DownloadClient client,
72 const std::string& guid) override;
73
74 // Checks if initialization is complete and successful. If so, completes the
75 // internal state initialization.
76 void AttemptToFinalizeSetup();
77
78 // Cancels and cleans upany requests that are no longer associated with a
79 // Client in |clients_|.
80 void CancelOrphanedRequests();
81
82 // Fixes any discrepencies in state between |model_| and |driver_|. Meant to
83 // resolve state issues during startup.
84 void ResolveInitialRequestStates();
85
86 // Notifies all Client in |clients_| that this controller is initialized and
87 // lets them know which download requests we are aware of for their
88 // DownloadClient.
89 void NotifyClientsOfStartup();
90
91 // Pulls the current state of requests from |model_| and |driver_| and sets
92 // the other internal states appropriately.
93 void PullCurrentRequestStatus();
94
95 void HandleStartDownloadResponse(DownloadClient client,
96 const std::string& guid,
97 DownloadParams::StartResult result);
98 void HandleStartDownloadResponse(
99 DownloadClient client,
100 const std::string& guid,
101 DownloadParams::StartResult result,
102 const DownloadParams::StartCallback& callback);
103
104 std::unique_ptr<ClientSet> clients_;
105 std::unique_ptr<Configuration> config_;
106
107 // Owned Dependencies.
108 std::unique_ptr<DownloadDriver> driver_;
109 std::unique_ptr<Model> model_;
110
111 // Internal state.
112 StartupStatus startup_status_;
113 std::map<std::string, DownloadParams::StartCallback> start_callbacks_;
114
115 DISALLOW_COPY_AND_ASSIGN(ControllerImpl);
116 };
117
118 } // namespace download
119
120 #endif // COMPONENTS_DOWNLOAD_INTERNAL_CONTROLLER_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698