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

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: Remove frame sequence numbers from serialization Created 5 years, 6 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
« no previous file with comments | « content/renderer/history_controller.cc ('k') | content/renderer/history_entry.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // We need to track multiple names because the name of a frame can change
85 // over its lifetime. This allows us to clean up all of the names this node
86 // has ever known by when it is destroyed.
87 std::vector<std::string> unique_names_;
80 }; 88 };
81 89
82 HistoryEntry(const blink::WebHistoryItem& root, int64_t frame_id); 90 HistoryEntry(const blink::WebHistoryItem& root);
83 HistoryEntry(); 91 HistoryEntry();
84 ~HistoryEntry(); 92 ~HistoryEntry();
85 93
86 HistoryEntry* CloneAndReplace(const blink::WebHistoryItem& newItem, 94 HistoryEntry* CloneAndReplace(const blink::WebHistoryItem& newItem,
87 bool clone_children_of_target, 95 bool clone_children_of_target,
88 RenderFrameImpl* target_frame, 96 RenderFrameImpl* target_frame,
89 RenderViewImpl* render_view); 97 RenderViewImpl* render_view);
90 98
91 HistoryNode* GetHistoryNodeForFrame(RenderFrameImpl* frame); 99 HistoryNode* GetHistoryNodeForFrame(RenderFrameImpl* frame);
92 blink::WebHistoryItem GetItemForFrame(RenderFrameImpl* frame); 100 blink::WebHistoryItem GetItemForFrame(RenderFrameImpl* frame);
93 const blink::WebHistoryItem& root() const { return root_->item(); } 101 const blink::WebHistoryItem& root() const { return root_->item(); }
94 HistoryNode* root_history_node() const { return root_.get(); } 102 HistoryNode* root_history_node() const { return root_.get(); }
95 103
96 private: 104 private:
97
98 scoped_ptr<HistoryNode> root_; 105 scoped_ptr<HistoryNode> root_;
99 106
100 typedef base::hash_map<uint64_t, HistoryNode*> FramesToItems;
101 FramesToItems frames_to_items_;
102
103 typedef base::hash_map<std::string, HistoryNode*> UniqueNamesToItems; 107 typedef base::hash_map<std::string, HistoryNode*> UniqueNamesToItems;
104 UniqueNamesToItems unique_names_to_items_; 108 UniqueNamesToItems unique_names_to_items_;
109
110 base::WeakPtrFactory<HistoryEntry> weak_ptr_factory_;
105 }; 111 };
106 112
107 } // namespace content 113 } // namespace content
108 114
109 #endif // CONTENT_RENDERER_HISTORY_ENTRY_H_ 115 #endif // CONTENT_RENDERER_HISTORY_ENTRY_H_
OLDNEW
« no previous file with comments | « content/renderer/history_controller.cc ('k') | content/renderer/history_entry.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698