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

Unified Diff: components/download/internal/model_impl.h

Issue 2870753003: Add a Model to the download component. (Closed)
Patch Set: Renamed test base class 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/download/internal/model.h ('k') | components/download/internal/model_impl.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..8c78501956619523935d6b5e37cab4ce2cbbd636
--- /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 <utility>
+#include <vector>
+
+#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;
+
+ // Model 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 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_
« no previous file with comments | « components/download/internal/model.h ('k') | components/download/internal/model_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698