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 14 matching lines...) Expand all Loading... |
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 OnInitialized(bool success) = 0; |
34 | 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 | 35 // Called when an Entry addition is complete. |success| determines whether |
41 // or not the entry has been successfully persisted to the Store. | 36 // or not the entry has been successfully persisted to the Store. |
42 virtual void OnItemAdded(bool success, | 37 virtual void OnItemAdded(bool success, |
43 DownloadClient client, | 38 DownloadClient client, |
44 const std::string& guid) = 0; | 39 const std::string& guid) = 0; |
45 | 40 |
46 // Called when an Entry update is complete. |success| determines whether or | 41 // Called when an Entry update is complete. |success| determines whether or |
47 // not the update has been successfully persisted to the Store. | 42 // not the update has been successfully persisted to the Store. |
48 virtual void OnItemUpdated(bool success, | 43 virtual void OnItemUpdated(bool success, |
49 DownloadClient client, | 44 DownloadClient client, |
50 const std::string& guid) = 0; | 45 const std::string& guid) = 0; |
51 | 46 |
52 // Called when an Entry removal is complete. |success| determines whether | 47 // Called when an Entry removal is complete. |success| determines whether |
53 // or not the entry has been successfully removed from the Store. | 48 // or not the entry has been successfully removed from the Store. |
54 virtual void OnItemRemoved(bool success, | 49 virtual void OnItemRemoved(bool success, |
55 DownloadClient client, | 50 DownloadClient client, |
56 const std::string& guid) = 0; | 51 const std::string& guid) = 0; |
57 }; | 52 }; |
58 | 53 |
59 using EntryList = std::vector<Entry*>; | 54 using EntryList = std::vector<Entry*>; |
60 | 55 |
61 virtual ~Model() = default; | 56 virtual ~Model() = default; |
62 | 57 |
63 // Initializes the Model. Client::OnInitialized() will be called in response. | 58 // Initializes the Model. Client::OnInitialized() will be called in response. |
64 // The Model can be used after that call. | 59 // The Model can be used after that call. |
65 virtual void Initialize() = 0; | 60 virtual void Initialize() = 0; |
66 | 61 |
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. | 62 // Adds |entry| to this Model and attempts to write |entry| to the Store. |
71 // Client::OnItemAdded() will be called in response asynchronously. | 63 // Client::OnItemAdded() will be called in response asynchronously. |
72 virtual void Add(const Entry& entry) = 0; | 64 virtual void Add(const Entry& entry) = 0; |
73 | 65 |
74 // 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. |
75 // Client::OnItemUpdated() will be called in response asynchronously. | 67 // Client::OnItemUpdated() will be called in response asynchronously. |
76 virtual void Update(const Entry& entry) = 0; | 68 virtual void Update(const Entry& entry) = 0; |
77 | 69 |
78 // 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 |
79 // remove that entry from the Store. Client::OnItemRemoved() will be called | 71 // remove that entry from the Store. Client::OnItemRemoved() will be called |
80 // in response asynchronously. | 72 // in response asynchronously. |
81 virtual void Remove(const std::string& guid) = 0; | 73 virtual void Remove(const std::string& guid) = 0; |
82 | 74 |
83 // Retrieves an Entry identified by |guid| or |nullptr| if no entry exists. | 75 // 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 | 76 // 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 | 77 // NOT stored. The underlying data may get updated or removed by any other |
86 // modifications to this model. | 78 // modifications to this model. |
87 virtual Entry* Get(const std::string& guid) = 0; | 79 virtual Entry* Get(const std::string& guid) = 0; |
88 | 80 |
89 // Returns a temporary list of Entry objects that this Model stores. | 81 // Returns a temporary list of Entry objects that this Model stores. |
90 // 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 |
91 // 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 |
92 // by any other modifications to this model. | 84 // by any other modifications to this model. |
93 virtual EntryList PeekEntries() = 0; | 85 virtual EntryList PeekEntries() = 0; |
94 }; | 86 }; |
95 | 87 |
96 } // namespace download | 88 } // namespace download |
97 | 89 |
98 #endif // COMPONENTS_DOWNLOAD_INTERNAL_MODEL_H_ | 90 #endif // COMPONENTS_DOWNLOAD_INTERNAL_MODEL_H_ |
OLD | NEW |