OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "chrome/browser/bookmarks/bookmark_model.h" | 5 #include "chrome/browser/bookmarks/bookmark_model.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <functional> | 8 #include <functional> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 11 matching lines...) Expand all Loading... | |
22 #include "grit/generated_resources.h" | 22 #include "grit/generated_resources.h" |
23 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
24 #include "ui/base/l10n/l10n_util_collator.h" | 24 #include "ui/base/l10n/l10n_util_collator.h" |
25 #include "ui/gfx/codec/png_codec.h" | 25 #include "ui/gfx/codec/png_codec.h" |
26 | 26 |
27 using base::Time; | 27 using base::Time; |
28 | 28 |
29 namespace { | 29 namespace { |
30 | 30 |
31 // Helper to get a mutable bookmark node. | 31 // Helper to get a mutable bookmark node. |
32 static BookmarkNode* AsMutable(const BookmarkNode* node) { | 32 BookmarkNode* AsMutable(const BookmarkNode* node) { |
33 return const_cast<BookmarkNode*>(node); | 33 return const_cast<BookmarkNode*>(node); |
34 } | 34 } |
35 | 35 |
36 } // namespace | 36 } // namespace |
37 | 37 |
38 // BookmarkNode --------------------------------------------------------------- | 38 // BookmarkNode --------------------------------------------------------------- |
39 | 39 |
40 BookmarkNode::BookmarkNode(const GURL& url) | 40 BookmarkNode::BookmarkNode(const GURL& url) |
41 : url_(url) { | 41 : url_(url) { |
42 Initialize(0); | 42 Initialize(0); |
43 } | 43 } |
44 | 44 |
45 BookmarkNode::BookmarkNode(int64 id, const GURL& url) | 45 BookmarkNode::BookmarkNode(int64 id, const GURL& url) |
46 : url_(url) { | 46 : url_(url) { |
47 Initialize(id); | 47 Initialize(id); |
48 } | 48 } |
49 | 49 |
50 BookmarkNode::~BookmarkNode() { | 50 BookmarkNode::~BookmarkNode() { |
51 } | 51 } |
52 | 52 |
53 void BookmarkNode::Initialize(int64 id) { | |
54 id_ = id; | |
55 loaded_favicon_ = false; | |
56 favicon_load_handle_ = 0; | |
57 type_ = !url_.is_empty() ? URL : BOOKMARK_BAR; | |
58 date_added_ = Time::Now(); | |
59 } | |
60 | |
61 void BookmarkNode::InvalidateFavicon() { | 53 void BookmarkNode::InvalidateFavicon() { |
62 loaded_favicon_ = false; | |
63 favicon_ = SkBitmap(); | 54 favicon_ = SkBitmap(); |
55 is_favicon_loaded_ = false; | |
64 } | 56 } |
65 | 57 |
66 bool BookmarkNode::IsVisible() const { | 58 bool BookmarkNode::IsVisible() const { |
67 // The synced bookmark folder is invisible if the flag isn't set and there are | 59 // The synced bookmark folder is invisible if the flag isn't set and there are |
68 // no bookmarks under it. | 60 // no bookmarks under it. |
69 if (type_ != BookmarkNode::SYNCED || | 61 if (type_ != BookmarkNode::SYNCED || |
70 CommandLine::ForCurrentProcess()->HasSwitch( | 62 CommandLine::ForCurrentProcess()->HasSwitch( |
71 switches::kEnableSyncedBookmarksFolder) || !empty()) { | 63 switches::kEnableSyncedBookmarksFolder) || !empty()) { |
72 return true; | 64 return true; |
73 } | 65 } |
74 return false; | 66 return false; |
75 } | 67 } |
76 | 68 |
69 void BookmarkNode::Initialize(int64 id) { | |
70 id_ = id; | |
71 type_ = !url_.is_empty() ? URL : BOOKMARK_BAR; | |
tfarina
2011/07/07 17:03:29
So, instead of BOOKMARK_BAR shouldn't this be FOLD
sky
2011/07/07 22:26:36
Yes, I believe everyone sets the type, so that sho
tfarina
2011/07/07 23:08:59
Done.
| |
72 date_added_ = Time::Now(); | |
73 is_favicon_loaded_ = false; | |
74 favicon_load_handle_ = 0; | |
75 } | |
76 | |
77 // BookmarkModel -------------------------------------------------------------- | 77 // BookmarkModel -------------------------------------------------------------- |
78 | 78 |
79 namespace { | 79 namespace { |
80 | 80 |
81 // Comparator used when sorting bookmarks. Folders are sorted first, then | 81 // Comparator used when sorting bookmarks. Folders are sorted first, then |
82 // bookmarks. | 82 // bookmarks. |
83 class SortComparator : public std::binary_function<const BookmarkNode*, | 83 class SortComparator : public std::binary_function<const BookmarkNode*, |
84 const BookmarkNode*, | 84 const BookmarkNode*, |
85 bool> { | 85 bool> { |
86 public: | 86 public: |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
227 bookmark_utils::CloneBookmarkNode(this, elements, new_parent, index); | 227 bookmark_utils::CloneBookmarkNode(this, elements, new_parent, index); |
228 | 228 |
229 if (store_.get()) | 229 if (store_.get()) |
230 store_->ScheduleSave(); | 230 store_->ScheduleSave(); |
231 } | 231 } |
232 | 232 |
233 const SkBitmap& BookmarkModel::GetFavicon(const BookmarkNode* node) { | 233 const SkBitmap& BookmarkModel::GetFavicon(const BookmarkNode* node) { |
234 DCHECK(node); | 234 DCHECK(node); |
235 if (!node->is_favicon_loaded()) { | 235 if (!node->is_favicon_loaded()) { |
236 BookmarkNode* mutable_node = AsMutable(node); | 236 BookmarkNode* mutable_node = AsMutable(node); |
237 mutable_node->set_favicon_loaded(true); | 237 mutable_node->set_is_favicon_loaded(true); |
tfarina
2011/07/07 17:03:29
Should we remove the friend relationship with Book
sky
2011/07/07 22:26:36
If the friend is not needed it, remove it.
| |
238 LoadFavicon(mutable_node); | 238 LoadFavicon(mutable_node); |
239 } | 239 } |
240 return node->favicon(); | 240 return node->favicon(); |
241 } | 241 } |
242 | 242 |
243 void BookmarkModel::SetTitle(const BookmarkNode* node, const string16& title) { | 243 void BookmarkModel::SetTitle(const BookmarkNode* node, const string16& title) { |
244 if (!node) { | 244 if (!node) { |
245 NOTREACHED(); | 245 NOTREACHED(); |
246 return; | 246 return; |
247 } | 247 } |
(...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
805 file_changed_ = true; | 805 file_changed_ = true; |
806 } | 806 } |
807 | 807 |
808 BookmarkLoadDetails* BookmarkModel::CreateLoadDetails() { | 808 BookmarkLoadDetails* BookmarkModel::CreateLoadDetails() { |
809 BookmarkNode* bb_node = CreatePermanentNode(BookmarkNode::BOOKMARK_BAR); | 809 BookmarkNode* bb_node = CreatePermanentNode(BookmarkNode::BOOKMARK_BAR); |
810 BookmarkNode* other_node = CreatePermanentNode(BookmarkNode::OTHER_NODE); | 810 BookmarkNode* other_node = CreatePermanentNode(BookmarkNode::OTHER_NODE); |
811 BookmarkNode* synced_node = CreatePermanentNode(BookmarkNode::SYNCED); | 811 BookmarkNode* synced_node = CreatePermanentNode(BookmarkNode::SYNCED); |
812 return new BookmarkLoadDetails(bb_node, other_node, synced_node, | 812 return new BookmarkLoadDetails(bb_node, other_node, synced_node, |
813 new BookmarkIndex(profile()), next_node_id_); | 813 new BookmarkIndex(profile()), next_node_id_); |
814 } | 814 } |
OLD | NEW |