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

Unified Diff: components/download/internal/model.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/entry.cc ('k') | components/download/internal/model_impl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/download/internal/model.h
diff --git a/components/download/internal/model.h b/components/download/internal/model.h
new file mode 100644
index 0000000000000000000000000000000000000000..ce5de88e4500878f1f7667c461b30cfb53991144
--- /dev/null
+++ b/components/download/internal/model.h
@@ -0,0 +1,98 @@
+// 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_H_
+#define COMPONENTS_DOWNLOAD_INTERNAL_MODEL_H_
+
+#include <memory>
+#include <string>
+#include <vector>
+
+#include "components/download/public/clients.h"
+
+namespace download {
+
+struct Entry;
+class Store;
+
+// The model that contains a runtime representation of Entry entries. Any
+// updates to the model will be persisted to a backing |Store| as necessary.
+class Model {
+ public:
+ // The Client which is responsible for handling all relevant messages from the
+ // model.
+ class Client {
+ public:
+ virtual ~Client() = default;
+
+ // Called asynchronously in response to a Model::Initialize call. If
+ // |success| is |false|, initialization of the Model and/or the underlying
+ // Store failed. Initialization of the Model is complete after this
+ // callback. If |success| is true it can be accessed now.
+ virtual void OnInitialized(bool success) = 0;
+
+ // Called asynchronously in response to a Model::Destroy call. If |success|
+ // is |false|, destruction of the Model and/or the underlying Store failed.
+ // Destruction of the Model is effectively complete after this callback.
+ virtual void OnDestroyed(bool success) = 0;
+
+ // Called when an Entry addition is complete. |success| determines whether
+ // or not the entry has been successfully persisted to the Store.
+ virtual void OnItemAdded(bool success,
+ DownloadClient client,
+ const std::string& guid) = 0;
+
+ // Called when an Entry update is complete. |success| determines whether or
+ // not the update has been successfully persisted to the Store.
+ virtual void OnItemUpdated(bool success,
+ DownloadClient client,
+ const std::string& guid) = 0;
+
+ // Called when an Entry removal is complete. |success| determines whether
+ // or not the entry has been successfully removed from the Store.
+ virtual void OnItemRemoved(bool success,
+ DownloadClient client,
+ const std::string& guid) = 0;
+ };
+
+ using EntryList = std::vector<Entry*>;
+
+ virtual ~Model() = default;
+
+ // Initializes the Model. Client::OnInitialized() will be called in response.
+ // The Model can be used after that call.
+ virtual void Initialize() = 0;
+
+ // Destroys the Model. Client::OnDestroyed() will be called in response.
+ virtual void Destroy() = 0;
+
+ // Adds |entry| to this Model and attempts to write |entry| to the Store.
+ // Client::OnItemAdded() will be called in response asynchronously.
+ virtual void Add(const Entry& entry) = 0;
+
+ // Updates |entry| in this Model and attempts to write |entry| to the Store.
+ // Client::OnItemUpdated() will be called in response asynchronously.
+ virtual void Update(const Entry& entry) = 0;
+
+ // Removes the Entry specified by |guid| from this Model and attempts to
+ // remove that entry from the Store. Client::OnItemRemoved() will be called
+ // in response asynchronously.
+ virtual void Remove(const std::string& guid) = 0;
+
+ // Retrieves an Entry identified by |guid| or |nullptr| if no entry exists.
+ // IMPORTANT NOTE: The result of this method should be used immediately and
+ // NOT stored. The underlying data may get updated or removed by any other
+ // modifications to this model.
+ virtual Entry* Get(const std::string& guid) = 0;
+
+ // Returns a temporary list of Entry objects that this Model stores.
+ // IMPORTANT NOTE: Like Get(), the result of this method should be used
+ // immediately and NOT stored. The underlying data may get updated or removed
+ // by any other modifications to this model.
+ virtual EntryList PeekEntries() = 0;
+};
+
+} // namespace download
+
+#endif // COMPONENTS_DOWNLOAD_INTERNAL_MODEL_H_
« no previous file with comments | « components/download/internal/entry.cc ('k') | components/download/internal/model_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698