Chromium Code Reviews| Index: components/download/internal/model_impl.h |
| diff --git a/components/download/internal/model_impl.h b/components/download/internal/model_impl.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..47667485f22d158d0b006df914a341c5b233bea3 |
| --- /dev/null |
| +++ b/components/download/internal/model_impl.h |
| @@ -0,0 +1,73 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef COMPONENTS_DOWNLOAD_INTERNAL_MODEL_IMPL_H_ |
| +#define COMPONENTS_DOWNLOAD_INTERNAL_MODEL_IMPL_H_ |
| + |
| +#include <map> |
| +#include <string> |
| +#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!
|
| + |
| +#include "base/macros.h" |
| +#include "base/memory/weak_ptr.h" |
| +#include "components/download/internal/model.h" |
| +#include "components/download/internal/store.h" |
| +#include "components/download/public/clients.h" |
| + |
| +namespace download { |
| + |
| +struct Entry; |
| + |
| +// The internal implementation of Model. |
| +class ModelImpl : public Model { |
| + public: |
| + ModelImpl(Client* client, std::unique_ptr<Store> store); |
| + ~ModelImpl() override; |
| + |
| + // DownloadModel implementation. |
| + void Initialize() override; |
| + void Destroy() override; |
| + void Add(const Entry& entry) override; |
| + void Update(const Entry& entry) override; |
| + void Remove(const std::string& guid) override; |
| + Entry* Get(const std::string& guid) override; |
| + EntryList PeekEntries() override; |
| + |
| + private: |
| + using OwnedEntryPair = std::pair<std::string, std::unique_ptr<Entry>>; |
| + using OwnedEntryMap = std::map<std::string, std::unique_ptr<Entry>>; |
| + |
| + void OnInitializedFinished(bool success, |
| + std::unique_ptr<std::vector<Entry>> entries); |
| + void OnDestroyFinished(bool success); |
| + void OnAddFinished(DownloadClient client, |
| + const std::string& guid, |
| + bool success); |
| + void OnUpdateFinished(DownloadClient client, |
| + const std::string& guid, |
| + bool success); |
| + void OnRemoveFinished(DownloadClient client, |
| + const std::string& guid, |
| + bool success); |
| + |
| + // The external Model::Client reference that will receive all interesting |
| + // Model notifications. |
| + Client* const client_; |
| + |
| + // The backing Store that is responsible for saving and loading the |
| + // persisted entries. |
| + std::unique_ptr<Store> store_; |
| + |
| + // A map of [guid] -> [std::unique_ptr<Entry>]. Effectively the cache of the |
| + // entries saved in Store. |
| + OwnedEntryMap entries_; |
| + |
| + base::WeakPtrFactory<ModelImpl> weak_ptr_factory_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ModelImpl); |
| +}; |
| + |
| +} // namespace download |
| + |
| +#endif // COMPONENTS_DOWNLOAD_INTERNAL_MODEL_IMPL_H_ |