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 update or remove operation failed for |guid|. At this | |
41 // point there is no guarantee that the underlying Store and this Model are | |
42 // in sync. | |
43 virtual void OnStoreUpdateFailed(DownloadClient client, | |
44 const std::string& guid) = 0; | |
45 | |
46 // Called when an Entry addition is complete. |success| determines whether | |
47 // or not the entry has been successfully persisted to the Store. | |
48 virtual void OnItemAdded(bool success, | |
49 DownloadClient client, | |
50 const std::string& guid) = 0; | |
51 }; | |
52 | |
53 using EntryList = std::vector<Entry*>; | |
54 | |
55 virtual ~Model() = default; | |
56 | |
57 // Initializes the Model. Client::OnInitialized() will be called in response. | |
58 // The Model can be used after that call. | |
59 virtual void Initialize() = 0; | |
60 | |
61 // Destroys the Model. Client::OnDestroyed() will be called in response. | |
62 virtual void Destroy() = 0; | |
63 | |
64 // Adds |entry| to this Model and attempts to write |entry| to the Store. | |
65 // Client::OnItemAdded() will be called in response. | |
66 virtual void Add(const Entry& entry) = 0; | |
67 | |
68 // Updates |entry| in this Model and attempts to write |entry| to the Store. | |
69 // 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
| |
70 virtual void Update(const Entry& entry) = 0; | |
71 | |
72 // Removes the Entry specified by |guid| from this Model and attempts to | |
73 // remove that entry from the Store. Will call Client::OnStoreUpdateFailed() | |
74 // if the removal fails. | |
75 virtual void Remove(const std::string& guid) = 0; | |
76 | |
77 // Retrieves an Entry identified by |guid| or |nullptr| if no entry exists. | |
78 virtual Entry* Get(const std::string& guid) = 0; | |
79 | |
80 // Returns a temporary list of Entry objects that this Model stores. Note | |
81 // that the Entry* list entries may not be valid if any modifications to this | |
82 // Store are made while holding on to the returned list! | |
83 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.
| |
84 }; | |
85 | |
86 } // namespace download | |
87 | |
88 #endif // COMPONENTS_DOWNLOAD_INTERNAL_MODEL_H_ | |
OLD | NEW |