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

Side by Side Diff: content/renderer/history_entry.h

Issue 1138543002: Better remove HistoryNodes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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 /* 5 /*
6 * Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. 6 * Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. 7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved.
8 * (http://www.torchmobile.com/) 8 * (http://www.torchmobile.com/)
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
(...skipping 20 matching lines...) Expand all
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */ 33 */
34 34
35 #ifndef CONTENT_RENDERER_HISTORY_ENTRY_H_ 35 #ifndef CONTENT_RENDERER_HISTORY_ENTRY_H_
36 #define CONTENT_RENDERER_HISTORY_ENTRY_H_ 36 #define CONTENT_RENDERER_HISTORY_ENTRY_H_
37 37
38 #include "base/containers/hash_tables.h" 38 #include "base/containers/hash_tables.h"
39 #include "base/memory/scoped_ptr.h" 39 #include "base/memory/scoped_ptr.h"
40 #include "base/memory/scoped_vector.h" 40 #include "base/memory/scoped_vector.h"
41 #include "base/memory/weak_ptr.h"
41 #include "content/common/content_export.h" 42 #include "content/common/content_export.h"
42 #include "third_party/WebKit/public/platform/WebURLRequest.h" 43 #include "third_party/WebKit/public/platform/WebURLRequest.h"
43 #include "third_party/WebKit/public/web/WebHistoryItem.h" 44 #include "third_party/WebKit/public/web/WebHistoryItem.h"
44 45
45 namespace blink { 46 namespace blink {
46 class WebFrame; 47 class WebFrame;
47 } 48 }
48 49
49 namespace content { 50 namespace content {
50 class RenderFrameImpl; 51 class RenderFrameImpl;
51 class RenderViewImpl; 52 class RenderViewImpl;
52 53
53 const int kInvalidFrameRoutingID = -1; 54 const int kInvalidFrameRoutingID = -1;
54 55
55 class CONTENT_EXPORT HistoryEntry { 56 class CONTENT_EXPORT HistoryEntry {
56 public: 57 public:
57 class HistoryNode { 58 class HistoryNode {
58 public: 59 public:
59 HistoryNode(HistoryEntry* entry, 60 HistoryNode(const base::WeakPtr<HistoryEntry>& entry,
60 const blink::WebHistoryItem& item, 61 const blink::WebHistoryItem& item,
61 int64_t frame_id); 62 int64_t frame_id);
62 ~HistoryNode(); 63 ~HistoryNode();
63 64
64 HistoryNode* AddChild(const blink::WebHistoryItem& item, int64_t frame_id); 65 HistoryNode* AddChild(const blink::WebHistoryItem& item, int64_t frame_id);
65 HistoryNode* AddChild(); 66 HistoryNode* AddChild();
66 HistoryNode* CloneAndReplace(HistoryEntry* new_entry, 67 HistoryNode* CloneAndReplace(const base::WeakPtr<HistoryEntry>& new_entry,
67 const blink::WebHistoryItem& new_item, 68 const blink::WebHistoryItem& new_item,
68 bool clone_children_of_target, 69 bool clone_children_of_target,
69 RenderFrameImpl* target_frame, 70 RenderFrameImpl* target_frame,
70 RenderFrameImpl* current_frame); 71 RenderFrameImpl* current_frame);
71 blink::WebHistoryItem& item() { return item_; } 72 blink::WebHistoryItem& item() { return item_; }
72 void set_item(const blink::WebHistoryItem& item); 73 void set_item(const blink::WebHistoryItem& item);
73 std::vector<HistoryNode*>& children() const { return children_->get(); } 74 std::vector<HistoryNode*>& children() const { return children_->get(); }
74 void RemoveChildren(); 75 void RemoveChildren();
75 76
76 private: 77 private:
77 HistoryEntry* entry_; 78 base::WeakPtr<HistoryEntry> entry_;
Nate Chapin 2015/05/13 19:15:55 When a HistoryEntry is destroyed, it takes all its
Charlie Reis 2015/05/13 21:33:37 Ack. Please make this a comment in the code itsel
Nate Chapin 2015/05/13 23:23:21 Done.
78 scoped_ptr<ScopedVector<HistoryNode> > children_; 79 scoped_ptr<ScopedVector<HistoryNode> > children_;
79 blink::WebHistoryItem item_; 80 blink::WebHistoryItem item_;
81 std::vector<std::string> unique_names_;
82 std::vector<uint64_t> frame_ids_;
Charlie Reis 2015/05/13 21:33:37 Why is there a list of these per HistoryNode? His
Nate Chapin 2015/05/13 23:23:21 I had a DCHECK in set_item() to verifying that the
Charlie Reis 2015/05/13 23:40:15 That would help me immensely, since I'm blocked on
80 }; 83 };
81 84
82 HistoryEntry(const blink::WebHistoryItem& root, int64_t frame_id); 85 HistoryEntry(const blink::WebHistoryItem& root, int64_t frame_id);
83 HistoryEntry(); 86 HistoryEntry();
84 ~HistoryEntry(); 87 ~HistoryEntry();
85 88
86 HistoryEntry* CloneAndReplace(const blink::WebHistoryItem& newItem, 89 HistoryEntry* CloneAndReplace(const blink::WebHistoryItem& newItem,
87 bool clone_children_of_target, 90 bool clone_children_of_target,
88 RenderFrameImpl* target_frame, 91 RenderFrameImpl* target_frame,
89 RenderViewImpl* render_view); 92 RenderViewImpl* render_view);
90 93
91 HistoryNode* GetHistoryNodeForFrame(RenderFrameImpl* frame); 94 HistoryNode* GetHistoryNodeForFrame(RenderFrameImpl* frame);
92 blink::WebHistoryItem GetItemForFrame(RenderFrameImpl* frame); 95 blink::WebHistoryItem GetItemForFrame(RenderFrameImpl* frame);
93 const blink::WebHistoryItem& root() const { return root_->item(); } 96 const blink::WebHistoryItem& root() const { return root_->item(); }
94 HistoryNode* root_history_node() const { return root_.get(); } 97 HistoryNode* root_history_node() const { return root_.get(); }
95 98
96 private: 99 private:
97
98 scoped_ptr<HistoryNode> root_; 100 scoped_ptr<HistoryNode> root_;
99 101
100 typedef base::hash_map<uint64_t, HistoryNode*> FramesToItems; 102 typedef base::hash_map<uint64_t, HistoryNode*> FramesToItems;
101 FramesToItems frames_to_items_; 103 FramesToItems frames_to_items_;
102 104
103 typedef base::hash_map<std::string, HistoryNode*> UniqueNamesToItems; 105 typedef base::hash_map<std::string, HistoryNode*> UniqueNamesToItems;
104 UniqueNamesToItems unique_names_to_items_; 106 UniqueNamesToItems unique_names_to_items_;
107
108 base::WeakPtrFactory<HistoryEntry> weak_ptr_factory_;
105 }; 109 };
106 110
107 } // namespace content 111 } // namespace content
108 112
109 #endif // CONTENT_RENDERER_HISTORY_ENTRY_H_ 113 #endif // CONTENT_RENDERER_HISTORY_ENTRY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698