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

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 ~HistoryNode(); 62 ~HistoryNode();
63 63
64 HistoryNode* AddChild(const blink::WebHistoryItem& item, int64_t frame_id); 64 HistoryNode* AddChild(const blink::WebHistoryItem& item);
65 HistoryNode* AddChild(); 65 HistoryNode* AddChild();
66 HistoryNode* CloneAndReplace(HistoryEntry* new_entry, 66 HistoryNode* CloneAndReplace(const base::WeakPtr<HistoryEntry>& new_entry,
67 const blink::WebHistoryItem& new_item, 67 const blink::WebHistoryItem& new_item,
68 bool clone_children_of_target, 68 bool clone_children_of_target,
69 RenderFrameImpl* target_frame, 69 RenderFrameImpl* target_frame,
70 RenderFrameImpl* current_frame); 70 RenderFrameImpl* current_frame);
71 blink::WebHistoryItem& item() { return item_; } 71 blink::WebHistoryItem& item() { return item_; }
72 void set_item(const blink::WebHistoryItem& item); 72 void set_item(const blink::WebHistoryItem& item);
73 std::vector<HistoryNode*>& children() const { return children_->get(); } 73 std::vector<HistoryNode*>& children() const { return children_->get(); }
74 void RemoveChildren(); 74 void RemoveChildren();
75 75
76 private: 76 private:
77 HistoryEntry* entry_; 77 // When a HistoryEntry is destroyed, it takes all its HistoryNodes with it.
78 // Use a WeakPtr to ensure that HistoryNodes don't try to illegally access
79 // a dying HistoryEntry, or do unnecessary work when the whole entry is
80 // being destroyed.
81 base::WeakPtr<HistoryEntry> entry_;
78 scoped_ptr<ScopedVector<HistoryNode> > children_; 82 scoped_ptr<ScopedVector<HistoryNode> > children_;
79 blink::WebHistoryItem item_; 83 blink::WebHistoryItem item_;
84 std::vector<std::string> unique_names_;
Charlie Reis 2015/05/18 22:48:00 Let's add a comment about why a single HistoryNode
Nate Chapin 2015/05/28 21:31:50 Done.
80 }; 85 };
81 86
82 HistoryEntry(const blink::WebHistoryItem& root, int64_t frame_id); 87 HistoryEntry(const blink::WebHistoryItem& root);
83 HistoryEntry(); 88 HistoryEntry();
84 ~HistoryEntry(); 89 ~HistoryEntry();
85 90
86 HistoryEntry* CloneAndReplace(const blink::WebHistoryItem& newItem, 91 HistoryEntry* CloneAndReplace(const blink::WebHistoryItem& newItem,
87 bool clone_children_of_target, 92 bool clone_children_of_target,
88 RenderFrameImpl* target_frame, 93 RenderFrameImpl* target_frame,
89 RenderViewImpl* render_view); 94 RenderViewImpl* render_view);
90 95
91 HistoryNode* GetHistoryNodeForFrame(RenderFrameImpl* frame); 96 HistoryNode* GetHistoryNodeForFrame(RenderFrameImpl* frame);
92 blink::WebHistoryItem GetItemForFrame(RenderFrameImpl* frame); 97 blink::WebHistoryItem GetItemForFrame(RenderFrameImpl* frame);
93 const blink::WebHistoryItem& root() const { return root_->item(); } 98 const blink::WebHistoryItem& root() const { return root_->item(); }
94 HistoryNode* root_history_node() const { return root_.get(); } 99 HistoryNode* root_history_node() const { return root_.get(); }
95 100
96 private: 101 private:
97
98 scoped_ptr<HistoryNode> root_; 102 scoped_ptr<HistoryNode> root_;
99 103
100 typedef base::hash_map<uint64_t, HistoryNode*> FramesToItems;
101 FramesToItems frames_to_items_;
102
103 typedef base::hash_map<std::string, HistoryNode*> UniqueNamesToItems; 104 typedef base::hash_map<std::string, HistoryNode*> UniqueNamesToItems;
104 UniqueNamesToItems unique_names_to_items_; 105 UniqueNamesToItems unique_names_to_items_;
106
107 base::WeakPtrFactory<HistoryEntry> weak_ptr_factory_;
105 }; 108 };
106 109
107 } // namespace content 110 } // namespace content
108 111
109 #endif // CONTENT_RENDERER_HISTORY_ENTRY_H_ 112 #endif // CONTENT_RENDERER_HISTORY_ENTRY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698