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

Side by Side Diff: chrome/browser/bookmarks/bookmark_model.cc

Issue 155128: Converting the history::StarredEntry::Type to a type defined in BookmarkNode.... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 11 years, 5 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 | Annotate | Revision Log
OLDNEW
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 "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "base/gfx/png_decoder.h" 8 #include "base/gfx/png_decoder.h"
9 #include "base/scoped_vector.h" 9 #include "base/scoped_vector.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
(...skipping 26 matching lines...) Expand all
37 37
38 BookmarkNode::BookmarkNode(int id, const GURL& url) 38 BookmarkNode::BookmarkNode(int id, const GURL& url)
39 : url_(url){ 39 : url_(url){
40 Initialize(id); 40 Initialize(id);
41 } 41 }
42 42
43 void BookmarkNode::Initialize(int id) { 43 void BookmarkNode::Initialize(int id) {
44 id_ = id; 44 id_ = id;
45 loaded_favicon_ = false; 45 loaded_favicon_ = false;
46 favicon_load_handle_ = 0; 46 favicon_load_handle_ = 0;
47 type_ = !url_.is_empty() ? history::StarredEntry::URL : 47 type_ = !url_.is_empty() ? URL : BOOKMARK_BAR;
48 history::StarredEntry::BOOKMARK_BAR;
49 date_added_ = Time::Now(); 48 date_added_ = Time::Now();
50 } 49 }
51 50
52 void BookmarkNode::Reset(const history::StarredEntry& entry) { 51 void BookmarkNode::Reset(const history::StarredEntry& entry) {
53 DCHECK(entry.type != history::StarredEntry::URL || 52 DCHECK(entry.type != history::StarredEntry::URL || entry.url == url_);
54 entry.url == url_);
55 53
56 favicon_ = SkBitmap(); 54 favicon_ = SkBitmap();
57 type_ = entry.type; 55 switch (entry.type) {
56 case history::StarredEntry::URL:
57 type_ = BookmarkNode::URL;
58 break;
59 case history::StarredEntry::USER_GROUP:
60 type_ = BookmarkNode::FOLDER;
61 break;
62 case history::StarredEntry::BOOKMARK_BAR:
63 type_ = BookmarkNode::BOOKMARK_BAR;
64 break;
65 case history::StarredEntry::OTHER:
66 type_ = BookmarkNode::OTHER_NODE;
67 break;
68 default:
69 NOTREACHED();
70 }
58 date_added_ = entry.date_added; 71 date_added_ = entry.date_added;
59 date_group_modified_ = entry.date_group_modified; 72 date_group_modified_ = entry.date_group_modified;
60 SetTitle(entry.title); 73 SetTitle(entry.title);
61 } 74 }
62 75
63 // BookmarkModel -------------------------------------------------------------- 76 // BookmarkModel --------------------------------------------------------------
64 77
65 namespace { 78 namespace {
66 79
67 // Constant for persist IDs prefernece. 80 // Constant for persist IDs prefernece.
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 if (!loaded_ || parent == &root_ || !IsValidIndex(parent, index, true)) { 293 if (!loaded_ || parent == &root_ || !IsValidIndex(parent, index, true)) {
281 // Can't add to the root. 294 // Can't add to the root.
282 NOTREACHED(); 295 NOTREACHED();
283 return NULL; 296 return NULL;
284 } 297 }
285 298
286 BookmarkNode* new_node = new BookmarkNode(generate_next_node_id(), 299 BookmarkNode* new_node = new BookmarkNode(generate_next_node_id(),
287 GURL()); 300 GURL());
288 new_node->set_date_group_modified(Time::Now()); 301 new_node->set_date_group_modified(Time::Now());
289 new_node->SetTitle(title); 302 new_node->SetTitle(title);
290 new_node->SetType(history::StarredEntry::USER_GROUP); 303 new_node->SetType(BookmarkNode::FOLDER);
291 304
292 return AddNode(AsMutable(parent), index, new_node, false); 305 return AddNode(AsMutable(parent), index, new_node, false);
293 } 306 }
294 307
295 const BookmarkNode* BookmarkModel::AddURL(const BookmarkNode* parent, 308 const BookmarkNode* BookmarkModel::AddURL(const BookmarkNode* parent,
296 int index, 309 int index,
297 const std::wstring& title, 310 const std::wstring& title,
298 const GURL& url) { 311 const GURL& url) {
299 return AddURLWithCreationTime(parent, index, title, url, Time::Now()); 312 return AddURLWithCreationTime(parent, index, title, url, Time::Now());
300 } 313 }
(...skipping 10 matching lines...) Expand all
311 return NULL; 324 return NULL;
312 } 325 }
313 326
314 bool was_bookmarked = IsBookmarked(url); 327 bool was_bookmarked = IsBookmarked(url);
315 328
316 SetDateGroupModified(parent, creation_time); 329 SetDateGroupModified(parent, creation_time);
317 330
318 BookmarkNode* new_node = new BookmarkNode(generate_next_node_id(), url); 331 BookmarkNode* new_node = new BookmarkNode(generate_next_node_id(), url);
319 new_node->SetTitle(title); 332 new_node->SetTitle(title);
320 new_node->set_date_added(creation_time); 333 new_node->set_date_added(creation_time);
321 new_node->SetType(history::StarredEntry::URL); 334 new_node->SetType(BookmarkNode::URL);
322 335
323 { 336 {
324 // Only hold the lock for the duration of the insert. 337 // Only hold the lock for the duration of the insert.
325 AutoLock url_lock(url_lock_); 338 AutoLock url_lock(url_lock_);
326 nodes_ordered_by_url_set_.insert(new_node); 339 nodes_ordered_by_url_set_.insert(new_node);
327 } 340 }
328 341
329 return AddNode(AsMutable(parent), index, new_node, was_bookmarked); 342 return AddNode(AsMutable(parent), index, new_node, was_bookmarked);
330 } 343 }
331 344
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 BookmarkNodeFavIconLoaded(this, node)); 433 BookmarkNodeFavIconLoaded(this, node));
421 } 434 }
422 435
423 void BookmarkModel::RemoveNode(BookmarkNode* node, 436 void BookmarkModel::RemoveNode(BookmarkNode* node,
424 std::set<GURL>* removed_urls) { 437 std::set<GURL>* removed_urls) {
425 if (!loaded_ || !node || is_permanent_node(node)) { 438 if (!loaded_ || !node || is_permanent_node(node)) {
426 NOTREACHED(); 439 NOTREACHED();
427 return; 440 return;
428 } 441 }
429 442
430 if (node->GetType() == history::StarredEntry::URL) { 443 if (node->GetType() == BookmarkNode::URL) {
431 // NOTE: this is called in such a way that url_lock_ is already held. As 444 // NOTE: this is called in such a way that url_lock_ is already held. As
432 // such, this doesn't explicitly grab the lock. 445 // such, this doesn't explicitly grab the lock.
433 NodesOrderedByURLSet::iterator i = nodes_ordered_by_url_set_.find(node); 446 NodesOrderedByURLSet::iterator i = nodes_ordered_by_url_set_.find(node);
434 DCHECK(i != nodes_ordered_by_url_set_.end()); 447 DCHECK(i != nodes_ordered_by_url_set_.end());
435 // i points to the first node with the URL, advance until we find the 448 // i points to the first node with the URL, advance until we find the
436 // node we're removing. 449 // node we're removing.
437 while (*i != node) 450 while (*i != node)
438 ++i; 451 ++i;
439 nodes_ordered_by_url_set_.erase(i); 452 nodes_ordered_by_url_set_.erase(i);
440 removed_urls->insert(node->GetURL()); 453 removed_urls->insert(node->GetURL());
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 parent->Add(index, node); 564 parent->Add(index, node);
552 565
553 if (store_.get()) 566 if (store_.get())
554 store_->ScheduleSave(); 567 store_->ScheduleSave();
555 568
556 FOR_EACH_OBSERVER(BookmarkModelObserver, observers_, 569 FOR_EACH_OBSERVER(BookmarkModelObserver, observers_,
557 BookmarkNodeAdded(this, parent, index)); 570 BookmarkNodeAdded(this, parent, index));
558 571
559 index_->Add(node); 572 index_->Add(node);
560 573
561 if (node->GetType() == history::StarredEntry::URL && !was_bookmarked) { 574 if (node->GetType() == BookmarkNode::URL && !was_bookmarked) {
562 history::URLsStarredDetails details(true); 575 history::URLsStarredDetails details(true);
563 details.changed_urls.insert(node->GetURL()); 576 details.changed_urls.insert(node->GetURL());
564 NotificationService::current()->Notify( 577 NotificationService::current()->Notify(
565 NotificationType::URLS_STARRED, 578 NotificationType::URLS_STARRED,
566 Source<Profile>(profile_), 579 Source<Profile>(profile_),
567 Details<history::URLsStarredDetails>(&details)); 580 Details<history::URLsStarredDetails>(&details));
568 } 581 }
569 return node; 582 return node;
570 } 583 }
571 584
572 void BookmarkModel::BlockTillLoaded() { 585 void BookmarkModel::BlockTillLoaded() {
573 loaded_signal_.Wait(); 586 loaded_signal_.Wait();
574 } 587 }
575 588
576 const BookmarkNode* BookmarkModel::GetNodeByID(const BookmarkNode* node, 589 const BookmarkNode* BookmarkModel::GetNodeByID(const BookmarkNode* node,
577 int id) { 590 int id) {
578 if (node->id() == id) 591 if (node->id() == id)
579 return node; 592 return node;
580 593
581 for (int i = 0; i < node->GetChildCount(); ++i) { 594 for (int i = 0, child_count = node->GetChildCount(); i < child_count; ++i) {
582 const BookmarkNode* result = GetNodeByID(node->GetChild(i), id); 595 const BookmarkNode* result = GetNodeByID(node->GetChild(i), id);
583 if (result) 596 if (result)
584 return result; 597 return result;
585 } 598 }
586 return NULL; 599 return NULL;
587 } 600 }
588 601
589 bool BookmarkModel::IsValidIndex(const BookmarkNode* parent, 602 bool BookmarkModel::IsValidIndex(const BookmarkNode* parent,
590 int index, 603 int index,
591 bool allow_end) { 604 bool allow_end) {
592 return (parent && parent->is_folder() && 605 return (parent && parent->is_folder() &&
593 (index >= 0 && (index < parent->GetChildCount() || 606 (index >= 0 && (index < parent->GetChildCount() ||
594 (allow_end && index == parent->GetChildCount())))); 607 (allow_end && index == parent->GetChildCount()))));
595 } 608 }
596 609
597 void BookmarkModel::SetDateGroupModified(const BookmarkNode* parent, 610 void BookmarkModel::SetDateGroupModified(const BookmarkNode* parent,
598 const Time time) { 611 const Time time) {
599 DCHECK(parent); 612 DCHECK(parent);
600 AsMutable(parent)->set_date_group_modified(time); 613 AsMutable(parent)->set_date_group_modified(time);
601 614
602 if (store_.get()) 615 if (store_.get())
603 store_->ScheduleSave(); 616 store_->ScheduleSave();
604 } 617 }
605 618
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 DCHECK(node); 654 DCHECK(node);
642 node->set_favicon_load_handle(0); 655 node->set_favicon_load_handle(0);
643 if (know_favicon && data.get() && 656 if (know_favicon && data.get() &&
644 PNGDecoder::Decode(&data->data, &fav_icon)) { 657 PNGDecoder::Decode(&data->data, &fav_icon)) {
645 node->set_favicon(fav_icon); 658 node->set_favicon(fav_icon);
646 FavIconLoaded(node); 659 FavIconLoaded(node);
647 } 660 }
648 } 661 }
649 662
650 void BookmarkModel::LoadFavIcon(BookmarkNode* node) { 663 void BookmarkModel::LoadFavIcon(BookmarkNode* node) {
651 if (node->GetType() != history::StarredEntry::URL) 664 if (node->GetType() != BookmarkNode::URL)
652 return; 665 return;
653 666
654 DCHECK(node->GetURL().is_valid()); 667 DCHECK(node->GetURL().is_valid());
655 HistoryService* history_service = 668 HistoryService* history_service =
656 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); 669 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS);
657 if (!history_service) 670 if (!history_service)
658 return; 671 return;
659 672
660 HistoryService::Handle handle = history_service->GetFavIconForURL( 673 HistoryService::Handle handle = history_service->GetFavIconForURL(
661 node->GetURL(), &load_consumer_, 674 node->GetURL(), &load_consumer_,
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
740 if (!pref_service->IsPrefRegistered(kPrefPersistIDs)) 753 if (!pref_service->IsPrefRegistered(kPrefPersistIDs))
741 pref_service->RegisterBooleanPref(kPrefPersistIDs, false); 754 pref_service->RegisterBooleanPref(kPrefPersistIDs, false);
742 } 755 }
743 756
744 void BookmarkModel::LoadPreferences() { 757 void BookmarkModel::LoadPreferences() {
745 if (!profile_) 758 if (!profile_)
746 return; 759 return;
747 PrefService* pref_service = profile_->GetPrefs(); 760 PrefService* pref_service = profile_->GetPrefs();
748 persist_ids_ = pref_service->GetBoolean(kPrefPersistIDs); 761 persist_ids_ = pref_service->GetBoolean(kPrefPersistIDs);
749 } 762 }
OLDNEW
« no previous file with comments | « chrome/browser/bookmarks/bookmark_model.h ('k') | chrome/browser/bookmarks/bookmark_model_test_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698