OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "base/gfx/png_decoder.h" | 7 #include "base/gfx/png_decoder.h" |
8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
9 #include "chrome/browser/bookmarks/bookmark_utils.h" | 9 #include "chrome/browser/bookmarks/bookmark_utils.h" |
10 #include "chrome/browser/bookmarks/bookmark_storage.h" | 10 #include "chrome/browser/bookmarks/bookmark_storage.h" |
11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
12 #include "chrome/browser/profile.h" | 12 #include "chrome/browser/profile.h" |
13 #include "chrome/common/l10n_util.h" | 13 #include "chrome/common/l10n_util.h" |
14 #include "chrome/common/notification_service.h" | 14 #include "chrome/common/notification_service.h" |
15 #include "chrome/common/scoped_vector.h" | 15 #include "chrome/common/scoped_vector.h" |
16 #include "grit/generated_resources.h" | 16 #include "grit/generated_resources.h" |
17 | 17 |
18 using base::Time; | 18 using base::Time; |
19 | 19 |
20 // BookmarkNode --------------------------------------------------------------- | 20 // BookmarkNode --------------------------------------------------------------- |
21 | 21 |
22 namespace { | 22 namespace { |
23 | 23 |
24 // ID for BookmarkNodes. | 24 // ID for BookmarkNodes. |
25 // Various places assume an invalid id if == 0, for that reason we start with 1. | 25 // Various places assume an invalid id if == 0, for that reason we start with 1. |
26 int next_id_ = 1; | 26 int next_id_ = 1; |
27 | 27 |
28 } | 28 } |
29 | 29 |
| 30 // static |
| 31 void BookmarkNode::SetNextId(int next_id) { |
| 32 next_id_ = next_id; |
| 33 } |
| 34 |
30 const SkBitmap& BookmarkNode::GetFavIcon() { | 35 const SkBitmap& BookmarkNode::GetFavIcon() { |
31 if (!loaded_favicon_) { | 36 if (!loaded_favicon_) { |
32 loaded_favicon_ = true; | 37 loaded_favicon_ = true; |
33 model_->LoadFavIcon(this); | 38 model_->LoadFavIcon(this); |
34 } | 39 } |
35 return favicon_; | 40 return favicon_; |
36 } | 41 } |
37 | 42 |
38 BookmarkNode::BookmarkNode(BookmarkModel* model, const GURL& url) | 43 BookmarkNode::BookmarkNode(BookmarkModel* model, const GURL& url) |
39 : model_(model), | 44 : url_(url) { |
40 id_(next_id_++), | 45 Initialize(model, 0); |
41 loaded_favicon_(false), | 46 } |
42 favicon_load_handle_(0), | 47 |
43 url_(url), | 48 BookmarkNode::BookmarkNode(BookmarkModel* model, int id, const GURL& url) |
44 type_(!url.is_empty() ? history::StarredEntry::URL : | 49 : url_(url){ |
45 history::StarredEntry::BOOKMARK_BAR), | 50 Initialize(model, id); |
46 date_added_(Time::Now()) { | 51 } |
| 52 |
| 53 void BookmarkNode::Initialize(BookmarkModel* model, int id) { |
| 54 model_ = model; |
| 55 id_ = id == 0 ? next_id_++ : id; |
| 56 loaded_favicon_ = false; |
| 57 favicon_load_handle_ = 0; |
| 58 type_ = !url_.is_empty() ? history::StarredEntry::URL : |
| 59 history::StarredEntry::BOOKMARK_BAR; |
| 60 date_added_ = Time::Now(); |
47 } | 61 } |
48 | 62 |
49 void BookmarkNode::Reset(const history::StarredEntry& entry) { | 63 void BookmarkNode::Reset(const history::StarredEntry& entry) { |
50 DCHECK(entry.type != history::StarredEntry::URL || | 64 DCHECK(entry.type != history::StarredEntry::URL || |
51 entry.url == url_); | 65 entry.url == url_); |
52 | 66 |
53 favicon_ = SkBitmap(); | 67 favicon_ = SkBitmap(); |
54 type_ = entry.type; | 68 type_ = entry.type; |
55 date_added_ = entry.date_added; | 69 date_added_ = entry.date_added; |
56 date_group_modified_ = entry.date_group_modified; | 70 date_group_modified_ = entry.date_group_modified; |
(...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
723 } | 737 } |
724 | 738 |
725 void BookmarkModel::PopulateNodesByURL(BookmarkNode* node) { | 739 void BookmarkModel::PopulateNodesByURL(BookmarkNode* node) { |
726 // NOTE: this is called with url_lock_ already held. As such, this doesn't | 740 // NOTE: this is called with url_lock_ already held. As such, this doesn't |
727 // explicitly grab the lock. | 741 // explicitly grab the lock. |
728 if (node->is_url()) | 742 if (node->is_url()) |
729 nodes_ordered_by_url_set_.insert(node); | 743 nodes_ordered_by_url_set_.insert(node); |
730 for (int i = 0; i < node->GetChildCount(); ++i) | 744 for (int i = 0; i < node->GetChildCount(); ++i) |
731 PopulateNodesByURL(node->GetChild(i)); | 745 PopulateNodesByURL(node->GetChild(i)); |
732 } | 746 } |
OLD | NEW |