Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(224)

Side by Side Diff: components/bookmarks/browser/bookmark_storage.h

Issue 2379863002: Fix object ownership in ui/base/models. (Closed)
Patch Set: fix Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_BOOKMARKS_BROWSER_BOOKMARK_STORAGE_H_ 5 #ifndef COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_STORAGE_H_
6 #define COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_STORAGE_H_ 6 #define COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_STORAGE_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
11 #include <string> 11 #include <string>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/callback_forward.h" 14 #include "base/callback_forward.h"
15 #include "base/files/file_path.h" 15 #include "base/files/file_path.h"
16 #include "base/files/important_file_writer.h" 16 #include "base/files/important_file_writer.h"
17 #include "base/macros.h" 17 #include "base/macros.h"
18 #include "base/memory/ref_counted.h" 18 #include "base/memory/ref_counted.h"
19 #include "base/memory/scoped_vector.h"
20 #include "base/memory/weak_ptr.h" 19 #include "base/memory/weak_ptr.h"
20 #include "components/bookmarks/browser/bookmark_index.h"
21 #include "components/bookmarks/browser/bookmark_node.h" 21 #include "components/bookmarks/browser/bookmark_node.h"
22 22
23 namespace base { 23 namespace base {
24 class SequencedTaskRunner; 24 class SequencedTaskRunner;
25 } 25 }
26 26
27 namespace bookmarks { 27 namespace bookmarks {
28 28
29 class BookmarkIndex;
30 class BookmarkModel; 29 class BookmarkModel;
31 30
32 // A list of BookmarkPermanentNodes that owns them. 31 // A list of BookmarkPermanentNodes that owns them.
33 typedef ScopedVector<BookmarkPermanentNode> BookmarkPermanentNodeList; 32 using BookmarkPermanentNodeList =
33 std::vector<std::unique_ptr<BookmarkPermanentNode>>;
34 34
35 // A callback that generates a BookmarkPermanentNodeList, given a max ID to 35 // A callback that generates a BookmarkPermanentNodeList, given a max ID to
36 // use. The max ID argument will be updated after any new nodes have been 36 // use. The max ID argument will be updated after any new nodes have been
37 // created and assigned IDs. 37 // created and assigned IDs.
38 typedef base::Callback<BookmarkPermanentNodeList(int64_t*)> LoadExtraCallback; 38 using LoadExtraCallback = base::Callback<BookmarkPermanentNodeList(int64_t*)>;
39 39
40 // BookmarkLoadDetails is used by BookmarkStorage when loading bookmarks. 40 // BookmarkLoadDetails is used by BookmarkStorage when loading bookmarks.
41 // BookmarkModel creates a BookmarkLoadDetails and passes it (including 41 // BookmarkModel creates a BookmarkLoadDetails and passes it (including
42 // ownership) to BookmarkStorage. BookmarkStorage loads the bookmarks (and 42 // ownership) to BookmarkStorage. BookmarkStorage loads the bookmarks (and
43 // index) in the background thread, then calls back to the BookmarkModel (on 43 // index) in the background thread, then calls back to the BookmarkModel (on
44 // the main thread) when loading is done, passing ownership back to the 44 // the main thread) when loading is done, passing ownership back to the
45 // BookmarkModel. While loading BookmarkModel does not maintain references to 45 // BookmarkModel. While loading BookmarkModel does not maintain references to
46 // the contents of the BookmarkLoadDetails, this ensures we don't have any 46 // the contents of the BookmarkLoadDetails, this ensures we don't have any
47 // threading problems. 47 // threading problems.
48 class BookmarkLoadDetails { 48 class BookmarkLoadDetails {
49 public: 49 public:
50 BookmarkLoadDetails(BookmarkPermanentNode* bb_node, 50 BookmarkLoadDetails(BookmarkPermanentNode* bb_node,
51 BookmarkPermanentNode* other_folder_node, 51 BookmarkPermanentNode* other_folder_node,
52 BookmarkPermanentNode* mobile_folder_node, 52 BookmarkPermanentNode* mobile_folder_node,
53 const LoadExtraCallback& load_extra_callback, 53 const LoadExtraCallback& load_extra_callback,
54 BookmarkIndex* index, 54 BookmarkIndex* index,
55 int64_t max_id); 55 int64_t max_id);
56 ~BookmarkLoadDetails(); 56 ~BookmarkLoadDetails();
57 57
58 void LoadExtraNodes(); 58 void LoadExtraNodes();
59 59
60 BookmarkPermanentNode* bb_node() { return bb_node_.get(); } 60 BookmarkPermanentNode* bb_node() { return bb_node_.get(); }
61 BookmarkPermanentNode* release_bb_node() { return bb_node_.release(); } 61 std::unique_ptr<BookmarkPermanentNode> owned_bb_node() {
62 return std::move(bb_node_);
63 }
62 BookmarkPermanentNode* mobile_folder_node() { 64 BookmarkPermanentNode* mobile_folder_node() {
63 return mobile_folder_node_.get(); 65 return mobile_folder_node_.get();
64 } 66 }
65 BookmarkPermanentNode* release_mobile_folder_node() { 67 std::unique_ptr<BookmarkPermanentNode> owned_mobile_folder_node() {
66 return mobile_folder_node_.release(); 68 return std::move(mobile_folder_node_);
67 } 69 }
68 BookmarkPermanentNode* other_folder_node() { 70 BookmarkPermanentNode* other_folder_node() {
69 return other_folder_node_.get(); 71 return other_folder_node_.get();
70 } 72 }
71 BookmarkPermanentNode* release_other_folder_node() { 73 std::unique_ptr<BookmarkPermanentNode> owned_other_folder_node() {
72 return other_folder_node_.release(); 74 return std::move(other_folder_node_);
73 } 75 }
74 const BookmarkPermanentNodeList& extra_nodes() { 76 const BookmarkPermanentNodeList& extra_nodes() {
75 return extra_nodes_; 77 return extra_nodes_;
76 } 78 }
77 void release_extra_nodes(std::vector<BookmarkPermanentNode*>* extra_nodes) { 79 BookmarkPermanentNodeList owned_extra_nodes() {
78 extra_nodes_.release(extra_nodes); 80 return std::move(extra_nodes_);
79 } 81 }
80 BookmarkIndex* index() { return index_.get(); } 82 BookmarkIndex* index() { return index_.get(); }
81 BookmarkIndex* release_index() { return index_.release(); } 83 std::unique_ptr<BookmarkIndex> owned_index() { return std::move(index_); }
82 84
83 const BookmarkNode::MetaInfoMap& model_meta_info_map() const { 85 const BookmarkNode::MetaInfoMap& model_meta_info_map() const {
84 return model_meta_info_map_; 86 return model_meta_info_map_;
85 } 87 }
86 void set_model_meta_info_map(const BookmarkNode::MetaInfoMap& meta_info_map) { 88 void set_model_meta_info_map(const BookmarkNode::MetaInfoMap& meta_info_map) {
87 model_meta_info_map_ = meta_info_map; 89 model_meta_info_map_ = meta_info_map;
88 } 90 }
89 91
90 int64_t model_sync_transaction_version() const { 92 int64_t model_sync_transaction_version() const {
91 return model_sync_transaction_version_; 93 return model_sync_transaction_version_;
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner_; 206 scoped_refptr<base::SequencedTaskRunner> sequenced_task_runner_;
205 207
206 base::WeakPtrFactory<BookmarkStorage> weak_factory_; 208 base::WeakPtrFactory<BookmarkStorage> weak_factory_;
207 209
208 DISALLOW_COPY_AND_ASSIGN(BookmarkStorage); 210 DISALLOW_COPY_AND_ASSIGN(BookmarkStorage);
209 }; 211 };
210 212
211 } // namespace bookmarks 213 } // namespace bookmarks
212 214
213 #endif // COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_STORAGE_H_ 215 #endif // COMPONENTS_BOOKMARKS_BROWSER_BOOKMARK_STORAGE_H_
OLDNEW
« no previous file with comments | « components/bookmarks/browser/bookmark_model_unittest.cc ('k') | components/bookmarks/browser/bookmark_storage.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698