| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef COMPONENTS_DOWNLOAD_INTERNAL_MODEL_H_ | 5 #ifndef COMPONENTS_DOWNLOAD_INTERNAL_MODEL_H_ |
| 6 #define COMPONENTS_DOWNLOAD_INTERNAL_MODEL_H_ | 6 #define COMPONENTS_DOWNLOAD_INTERNAL_MODEL_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 // The Client which is responsible for handling all relevant messages from the | 23 // The Client which is responsible for handling all relevant messages from the |
| 24 // model. | 24 // model. |
| 25 class Client { | 25 class Client { |
| 26 public: | 26 public: |
| 27 virtual ~Client() = default; | 27 virtual ~Client() = default; |
| 28 | 28 |
| 29 // Called asynchronously in response to a Model::Initialize call. If | 29 // Called asynchronously in response to a Model::Initialize call. If |
| 30 // |success| is |false|, initialization of the Model and/or the underlying | 30 // |success| is |false|, initialization of the Model and/or the underlying |
| 31 // Store failed. Initialization of the Model is complete after this | 31 // Store failed. Initialization of the Model is complete after this |
| 32 // callback. If |success| is true it can be accessed now. | 32 // callback. If |success| is true it can be accessed now. |
| 33 virtual void OnInitialized(bool success) = 0; | 33 virtual void OnModelReady(bool success) = 0; |
| 34 | 34 |
| 35 // Called when an Entry addition is complete. |success| determines whether | 35 // Called when an Entry addition is complete. |success| determines whether |
| 36 // or not the entry has been successfully persisted to the Store. | 36 // or not the entry has been successfully persisted to the Store. |
| 37 virtual void OnItemAdded(bool success, | 37 virtual void OnItemAdded(bool success, |
| 38 DownloadClient client, | 38 DownloadClient client, |
| 39 const std::string& guid) = 0; | 39 const std::string& guid) = 0; |
| 40 | 40 |
| 41 // Called when an Entry update is complete. |success| determines whether or | 41 // Called when an Entry update is complete. |success| determines whether or |
| 42 // not the update has been successfully persisted to the Store. | 42 // not the update has been successfully persisted to the Store. |
| 43 virtual void OnItemUpdated(bool success, | 43 virtual void OnItemUpdated(bool success, |
| 44 DownloadClient client, | 44 DownloadClient client, |
| 45 const std::string& guid) = 0; | 45 const std::string& guid) = 0; |
| 46 | 46 |
| 47 // Called when an Entry removal is complete. |success| determines whether | 47 // Called when an Entry removal is complete. |success| determines whether |
| 48 // or not the entry has been successfully removed from the Store. | 48 // or not the entry has been successfully removed from the Store. |
| 49 virtual void OnItemRemoved(bool success, | 49 virtual void OnItemRemoved(bool success, |
| 50 DownloadClient client, | 50 DownloadClient client, |
| 51 const std::string& guid) = 0; | 51 const std::string& guid) = 0; |
| 52 }; | 52 }; |
| 53 | 53 |
| 54 using EntryList = std::vector<Entry*>; | 54 using EntryList = std::vector<Entry*>; |
| 55 | 55 |
| 56 virtual ~Model() = default; | 56 virtual ~Model() = default; |
| 57 | 57 |
| 58 // Initializes the Model. Client::OnInitialized() will be called in response. | 58 // Initializes the Model. Client::OnInitialized() will be called in response. |
| 59 // The Model can be used after that call. | 59 // The Model can be used after that call. |
| 60 virtual void Initialize() = 0; | 60 virtual void Initialize(Client* client) = 0; |
| 61 | 61 |
| 62 // Adds |entry| to this Model and attempts to write |entry| to the Store. | 62 // Adds |entry| to this Model and attempts to write |entry| to the Store. |
| 63 // Client::OnItemAdded() will be called in response asynchronously. | 63 // Client::OnItemAdded() will be called in response asynchronously. |
| 64 virtual void Add(const Entry& entry) = 0; | 64 virtual void Add(const Entry& entry) = 0; |
| 65 | 65 |
| 66 // Updates |entry| in this Model and attempts to write |entry| to the Store. | 66 // Updates |entry| in this Model and attempts to write |entry| to the Store. |
| 67 // Client::OnItemUpdated() will be called in response asynchronously. | 67 // Client::OnItemUpdated() will be called in response asynchronously. |
| 68 virtual void Update(const Entry& entry) = 0; | 68 virtual void Update(const Entry& entry) = 0; |
| 69 | 69 |
| 70 // Removes the Entry specified by |guid| from this Model and attempts to | 70 // Removes the Entry specified by |guid| from this Model and attempts to |
| (...skipping 10 matching lines...) Expand all Loading... |
| 81 // Returns a temporary list of Entry objects that this Model stores. | 81 // Returns a temporary list of Entry objects that this Model stores. |
| 82 // IMPORTANT NOTE: Like Get(), the result of this method should be used | 82 // IMPORTANT NOTE: Like Get(), the result of this method should be used |
| 83 // immediately and NOT stored. The underlying data may get updated or removed | 83 // immediately and NOT stored. The underlying data may get updated or removed |
| 84 // by any other modifications to this model. | 84 // by any other modifications to this model. |
| 85 virtual EntryList PeekEntries() = 0; | 85 virtual EntryList PeekEntries() = 0; |
| 86 }; | 86 }; |
| 87 | 87 |
| 88 } // namespace download | 88 } // namespace download |
| 89 | 89 |
| 90 #endif // COMPONENTS_DOWNLOAD_INTERNAL_MODEL_H_ | 90 #endif // COMPONENTS_DOWNLOAD_INTERNAL_MODEL_H_ |
| OLD | NEW |