OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef COMPONENTS_DOWNLOAD_INTERNAL_MODEL_H_ |
| 6 #define COMPONENTS_DOWNLOAD_INTERNAL_MODEL_H_ |
| 7 |
| 8 #include <memory> |
| 9 #include <string> |
| 10 #include <vector> |
| 11 |
| 12 #include "components/download/public/clients.h" |
| 13 |
| 14 namespace download { |
| 15 |
| 16 struct Entry; |
| 17 class Store; |
| 18 |
| 19 // The model that contains a runtime representation of Entry entries. Any |
| 20 // updates to the model will be persisted to a backing |Store| as necessary. |
| 21 class Model { |
| 22 public: |
| 23 // The Client which is responsible for handling all relevant messages from the |
| 24 // model. |
| 25 class Client { |
| 26 public: |
| 27 virtual ~Client() = default; |
| 28 |
| 29 // Called asynchronously in response to a Model::Initialize call. If |
| 30 // |success| is |false|, initialization of the Model and/or the underlying |
| 31 // Store failed. Initialization of the Model is complete after this |
| 32 // callback. If |success| is true it can be accessed now. |
| 33 virtual void OnInitialized(bool success) = 0; |
| 34 |
| 35 // Called asynchronously in response to a Model::Destroy call. If |success| |
| 36 // is |false|, destruction of the Model and/or the underlying Store failed. |
| 37 // Destruction of the Model is effectively complete after this callback. |
| 38 virtual void OnDestroyed(bool success) = 0; |
| 39 |
| 40 // Called when an Entry addition is complete. |success| determines whether |
| 41 // or not the entry has been successfully persisted to the Store. |
| 42 virtual void OnItemAdded(bool success, |
| 43 DownloadClient client, |
| 44 const std::string& guid) = 0; |
| 45 |
| 46 // Called when an Entry update is complete. |success| determines whether or |
| 47 // not the update has been successfully persisted to the Store. |
| 48 virtual void OnItemUpdated(bool success, |
| 49 DownloadClient client, |
| 50 const std::string& guid) = 0; |
| 51 |
| 52 // Called when an Entry removal is complete. |success| determines whether |
| 53 // or not the entry has been successfully removed from the Store. |
| 54 virtual void OnItemRemoved(bool success, |
| 55 DownloadClient client, |
| 56 const std::string& guid) = 0; |
| 57 }; |
| 58 |
| 59 using EntryList = std::vector<Entry*>; |
| 60 |
| 61 virtual ~Model() = default; |
| 62 |
| 63 // Initializes the Model. Client::OnInitialized() will be called in response. |
| 64 // The Model can be used after that call. |
| 65 virtual void Initialize() = 0; |
| 66 |
| 67 // Destroys the Model. Client::OnDestroyed() will be called in response. |
| 68 virtual void Destroy() = 0; |
| 69 |
| 70 // Adds |entry| to this Model and attempts to write |entry| to the Store. |
| 71 // Client::OnItemAdded() will be called in response asynchronously. |
| 72 virtual void Add(const Entry& entry) = 0; |
| 73 |
| 74 // Updates |entry| in this Model and attempts to write |entry| to the Store. |
| 75 // Client::OnItemUpdated() will be called in response asynchronously. |
| 76 virtual void Update(const Entry& entry) = 0; |
| 77 |
| 78 // Removes the Entry specified by |guid| from this Model and attempts to |
| 79 // remove that entry from the Store. Client::OnItemRemoved() will be called |
| 80 // in response asynchronously. |
| 81 virtual void Remove(const std::string& guid) = 0; |
| 82 |
| 83 // Retrieves an Entry identified by |guid| or |nullptr| if no entry exists. |
| 84 // IMPORTANT NOTE: The result of this method should be used immediately and |
| 85 // NOT stored. The underlying data may get updated or removed by any other |
| 86 // modifications to this model. |
| 87 virtual Entry* Get(const std::string& guid) = 0; |
| 88 |
| 89 // Returns a temporary list of Entry objects that this Model stores. |
| 90 // IMPORTANT NOTE: Like Get(), the result of this method should be used |
| 91 // immediately and NOT stored. The underlying data may get updated or removed |
| 92 // by any other modifications to this model. |
| 93 virtual EntryList PeekEntries() = 0; |
| 94 }; |
| 95 |
| 96 } // namespace download |
| 97 |
| 98 #endif // COMPONENTS_DOWNLOAD_INTERNAL_MODEL_H_ |
OLD | NEW |