summaryrefslogtreecommitdiff
path: root/chromium/components/download/internal/model.h
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2017-07-17 13:57:45 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2017-07-19 13:44:40 +0000
commit6ec7b8da05d21a3878bd21c691b41e675d74bb1c (patch)
treeb87f250bc19413750b9bb9cdbf2da20ef5014820 /chromium/components/download/internal/model.h
parentec02ee4181c49b61fce1c8fb99292dbb8139cc90 (diff)
downloadqtwebengine-chromium-6ec7b8da05d21a3878bd21c691b41e675d74bb1c.tar.gz
BASELINE: Update Chromium to 60.0.3112.70
Change-Id: I9911c2280a014d4632f254857876a395d4baed2d Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'chromium/components/download/internal/model.h')
-rw-r--r--chromium/components/download/internal/model.h98
1 files changed, 98 insertions, 0 deletions
diff --git a/chromium/components/download/internal/model.h b/chromium/components/download/internal/model.h
new file mode 100644
index 00000000000..ce5de88e450
--- /dev/null
+++ b/chromium/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_