| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_NTP_SNIPPETS_NTP_SNIPPETS_DATABASE_H_ | 5 #ifndef COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_DATABASE_H_ |
| 6 #define COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_DATABASE_H_ | 6 #define COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_DATABASE_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> |
| 10 #include <vector> | 11 #include <vector> |
| 11 | 12 |
| 12 #include "base/callback.h" | 13 #include "base/callback.h" |
| 13 #include "base/macros.h" | 14 #include "base/macros.h" |
| 14 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 15 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
| 16 #include "base/sequenced_task_runner.h" | 17 #include "base/sequenced_task_runner.h" |
| 17 #include "components/leveldb_proto/proto_database.h" | 18 #include "components/leveldb_proto/proto_database.h" |
| 18 #include "components/ntp_snippets/ntp_snippet.h" | 19 #include "components/ntp_snippets/ntp_snippet.h" |
| 19 | 20 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 // Loads all snippets from storage and passes them to |callback|. | 52 // Loads all snippets from storage and passes them to |callback|. |
| 52 void LoadSnippets(const SnippetsCallback& callback); | 53 void LoadSnippets(const SnippetsCallback& callback); |
| 53 | 54 |
| 54 // Adds or updates the given snippet. | 55 // Adds or updates the given snippet. |
| 55 void SaveSnippet(const NTPSnippet& snippet); | 56 void SaveSnippet(const NTPSnippet& snippet); |
| 56 // Adds or updates all the given snippets. | 57 // Adds or updates all the given snippets. |
| 57 void SaveSnippets(const NTPSnippet::PtrVector& snippets); | 58 void SaveSnippets(const NTPSnippet::PtrVector& snippets); |
| 58 | 59 |
| 59 // Deletes the snippet with the given ID, and its image. | 60 // Deletes the snippet with the given ID, and its image. |
| 60 void DeleteSnippet(const std::string& snippet_id); | 61 void DeleteSnippet(const std::string& snippet_id); |
| 61 // Deletes all the given snippets (identified by their IDs) and their images. | 62 // Deletes all the given snippets (identified by their IDs), not their images. |
| 62 void DeleteSnippets(const NTPSnippet::PtrVector& snippets); | 63 void DeleteSnippets(const NTPSnippet::PtrVector& snippets); |
| 63 | 64 |
| 64 // Loads the image data for the snippet with the given ID and passes it to | 65 // Loads the image data for the snippet with the given ID and passes it to |
| 65 // |callback|. Passes an empty string if not found. | 66 // |callback|. Passes an empty string if not found. |
| 66 void LoadImage(const std::string& snippet_id, | 67 void LoadImage(const std::string& snippet_id, |
| 67 const SnippetImageCallback& callback); | 68 const SnippetImageCallback& callback); |
| 68 | 69 |
| 69 // Adds or updates the image data for the given snippet ID. | 70 // Adds or updates the image data for the given snippet ID. |
| 70 void SaveImage(const std::string& snippet_id, const std::string& image_data); | 71 void SaveImage(const std::string& snippet_id, const std::string& image_data); |
| 71 | 72 |
| 72 // Deletes the image data for the given snippet ID. | 73 // Deletes the image data for the given snippet ID. |
| 73 void DeleteImage(const std::string& snippet_id); | 74 void DeleteImage(const std::string& snippet_id); |
| 75 // Deletes the image data for the given snippets (identified by their IDs). |
| 76 void DeleteImages(const NTPSnippet::PtrVector& snippets); |
| 74 | 77 |
| 75 private: | 78 private: |
| 76 friend class NTPSnippetsDatabaseTest; | 79 friend class NTPSnippetsDatabaseTest; |
| 77 | 80 |
| 78 using KeyEntryVector = | 81 using KeyEntryVector = |
| 79 leveldb_proto::ProtoDatabase<SnippetProto>::KeyEntryVector; | 82 leveldb_proto::ProtoDatabase<SnippetProto>::KeyEntryVector; |
| 80 | 83 |
| 81 using ImageKeyEntryVector = | 84 using ImageKeyEntryVector = |
| 82 leveldb_proto::ProtoDatabase<SnippetImageProto>::KeyEntryVector; | 85 leveldb_proto::ProtoDatabase<SnippetImageProto>::KeyEntryVector; |
| 83 | 86 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 base::Closure error_callback_; | 125 base::Closure error_callback_; |
| 123 | 126 |
| 124 base::WeakPtrFactory<NTPSnippetsDatabase> weak_ptr_factory_; | 127 base::WeakPtrFactory<NTPSnippetsDatabase> weak_ptr_factory_; |
| 125 | 128 |
| 126 DISALLOW_COPY_AND_ASSIGN(NTPSnippetsDatabase); | 129 DISALLOW_COPY_AND_ASSIGN(NTPSnippetsDatabase); |
| 127 }; | 130 }; |
| 128 | 131 |
| 129 } // namespace ntp_snippets | 132 } // namespace ntp_snippets |
| 130 | 133 |
| 131 #endif // COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_DATABASE_H_ | 134 #endif // COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_DATABASE_H_ |
| OLD | NEW |