| 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 COMPONENTS_DOWNLOAD_INTERNAL_MODEL_IMPL_H_ | 5 #ifndef COMPONENTS_DOWNLOAD_INTERNAL_MODEL_IMPL_H_ |
| 6 #define COMPONENTS_DOWNLOAD_INTERNAL_MODEL_IMPL_H_ | 6 #define COMPONENTS_DOWNLOAD_INTERNAL_MODEL_IMPL_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 15 #include "components/download/internal/model.h" | 15 #include "components/download/internal/model.h" |
| 16 #include "components/download/internal/store.h" | 16 #include "components/download/internal/store.h" |
| 17 #include "components/download/public/clients.h" | 17 #include "components/download/public/clients.h" |
| 18 | 18 |
| 19 namespace download { | 19 namespace download { |
| 20 | 20 |
| 21 struct Entry; | 21 struct Entry; |
| 22 | 22 |
| 23 // The internal implementation of Model. | 23 // The internal implementation of Model. |
| 24 class ModelImpl : public Model { | 24 class ModelImpl : public Model { |
| 25 public: | 25 public: |
| 26 ModelImpl(Client* client, std::unique_ptr<Store> store); | 26 ModelImpl(std::unique_ptr<Store> store); |
| 27 ~ModelImpl() override; | 27 ~ModelImpl() override; |
| 28 | 28 |
| 29 // Model implementation. | 29 // Model implementation. |
| 30 void Initialize() override; | 30 void Initialize(Client* client) override; |
| 31 void Add(const Entry& entry) override; | 31 void Add(const Entry& entry) override; |
| 32 void Update(const Entry& entry) override; | 32 void Update(const Entry& entry) override; |
| 33 void Remove(const std::string& guid) override; | 33 void Remove(const std::string& guid) override; |
| 34 Entry* Get(const std::string& guid) override; | 34 Entry* Get(const std::string& guid) override; |
| 35 EntryList PeekEntries() override; | 35 EntryList PeekEntries() override; |
| 36 | 36 |
| 37 private: | 37 private: |
| 38 using OwnedEntryMap = std::map<std::string, std::unique_ptr<Entry>>; | 38 using OwnedEntryMap = std::map<std::string, std::unique_ptr<Entry>>; |
| 39 | 39 |
| 40 void OnInitializedFinished(bool success, | 40 void OnInitializedFinished(bool success, |
| 41 std::unique_ptr<std::vector<Entry>> entries); | 41 std::unique_ptr<std::vector<Entry>> entries); |
| 42 void OnAddFinished(DownloadClient client, | 42 void OnAddFinished(DownloadClient client, |
| 43 const std::string& guid, | 43 const std::string& guid, |
| 44 bool success); | 44 bool success); |
| 45 void OnUpdateFinished(DownloadClient client, | 45 void OnUpdateFinished(DownloadClient client, |
| 46 const std::string& guid, | 46 const std::string& guid, |
| 47 bool success); | 47 bool success); |
| 48 void OnRemoveFinished(DownloadClient client, | 48 void OnRemoveFinished(DownloadClient client, |
| 49 const std::string& guid, | 49 const std::string& guid, |
| 50 bool success); | 50 bool success); |
| 51 | 51 |
| 52 // The external Model::Client reference that will receive all interesting | 52 // The external Model::Client reference that will receive all interesting |
| 53 // Model notifications. | 53 // Model notifications. |
| 54 Client* const client_; | 54 Client* client_; |
| 55 | 55 |
| 56 // The backing Store that is responsible for saving and loading the | 56 // The backing Store that is responsible for saving and loading the |
| 57 // persisted entries. | 57 // persisted entries. |
| 58 std::unique_ptr<Store> store_; | 58 std::unique_ptr<Store> store_; |
| 59 | 59 |
| 60 // A map of [guid] -> [std::unique_ptr<Entry>]. Effectively the cache of the | 60 // A map of [guid] -> [std::unique_ptr<Entry>]. Effectively the cache of the |
| 61 // entries saved in Store. | 61 // entries saved in Store. |
| 62 OwnedEntryMap entries_; | 62 OwnedEntryMap entries_; |
| 63 | 63 |
| 64 base::WeakPtrFactory<ModelImpl> weak_ptr_factory_; | 64 base::WeakPtrFactory<ModelImpl> weak_ptr_factory_; |
| 65 | 65 |
| 66 DISALLOW_COPY_AND_ASSIGN(ModelImpl); | 66 DISALLOW_COPY_AND_ASSIGN(ModelImpl); |
| 67 }; | 67 }; |
| 68 | 68 |
| 69 } // namespace download | 69 } // namespace download |
| 70 | 70 |
| 71 #endif // COMPONENTS_DOWNLOAD_INTERNAL_MODEL_IMPL_H_ | 71 #endif // COMPONENTS_DOWNLOAD_INTERNAL_MODEL_IMPL_H_ |
| OLD | NEW |