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