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..668660273f232a12d0e2784b23ea96ec150dc5f7 |
--- /dev/null |
+++ b/components/download/internal/model.h |
@@ -0,0 +1,88 @@ |
+// 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 update or remove operation failed for |guid|. At this |
+ // point there is no guarantee that the underlying Store and this Model are |
+ // in sync. |
+ virtual void OnStoreUpdateFailed(DownloadClient client, |
+ const std::string& guid) = 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; |
+ }; |
+ |
+ 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. |
+ virtual void Add(const Entry& entry) = 0; |
+ |
+ // Updates |entry| in this Model and attempts to write |entry| to the Store. |
+ // Will call Client::OnStoreUpdateFailed() if the write fails. |
Peter Beverloo
2017/05/10 12:44:45
There's cases when a client might want to wait for
David Trainor- moved to gerrit
2017/05/15 15:59:51
Yeah I went back and forth on exposing those conce
|
+ 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. Will call Client::OnStoreUpdateFailed() |
+ // if the removal fails. |
+ virtual void Remove(const std::string& guid) = 0; |
+ |
+ // Retrieves an Entry identified by |guid| or |nullptr| if no entry exists. |
+ virtual Entry* Get(const std::string& guid) = 0; |
+ |
+ // Returns a temporary list of Entry objects that this Model stores. Note |
+ // that the Entry* list entries may not be valid if any modifications to this |
+ // Store are made while holding on to the returned list! |
+ virtual EntryList PeekEntries() = 0; |
Peter Beverloo
2017/05/10 12:44:45
Here and for Get() - document that the Entry*(s) s
David Trainor- moved to gerrit
2017/05/15 15:59:51
Done.
|
+}; |
+ |
+} // namespace download |
+ |
+#endif // COMPONENTS_DOWNLOAD_INTERNAL_MODEL_H_ |