1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_bridge.h" 6 7 #include "chrome/browser/bookmarks/bookmark_model.h" 8 #include "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h" 9 10 BookmarkBarBridge::BookmarkBarBridge(BookmarkBarController* controller, 11 BookmarkModel* model) 12 : controller_(controller), 13 model_(model), 14 batch_mode_(false) { 15 model_->AddObserver(this); 16 17 // Bookmark loading is async; it may may not have happened yet. 18 // We will be notified when that happens with the AddObserver() call. 19 if (model->IsLoaded()) 20 Loaded(model); 21 } 22 23 BookmarkBarBridge::~BookmarkBarBridge() { 24 model_->RemoveObserver(this); 25 } 26 27 void BookmarkBarBridge::Loaded(BookmarkModel* model) { 28 [controller_ loaded:model]; 29 } 30 31 void BookmarkBarBridge::BookmarkModelBeingDeleted(BookmarkModel* model) { 32 [controller_ beingDeleted:model]; 33 } 34 35 void BookmarkBarBridge::BookmarkNodeMoved(BookmarkModel* model, 36 const BookmarkNode* old_parent, 37 int old_index, 38 const BookmarkNode* new_parent, 39 int new_index) { 40 [controller_ nodeMoved:model 41 oldParent:old_parent oldIndex:old_index 42 newParent:new_parent newIndex:new_index]; 43 } 44 45 void BookmarkBarBridge::BookmarkNodeAdded(BookmarkModel* model, 46 const BookmarkNode* parent, 47 int index) { 48 if (!batch_mode_) { 49 [controller_ nodeAdded:model parent:parent index:index]; 50 } 51 } 52 53 void BookmarkBarBridge::BookmarkNodeRemoved(BookmarkModel* model, 54 const BookmarkNode* parent, 55 int old_index, 56 const BookmarkNode* node) { 57 [controller_ nodeRemoved:model parent:parent index:old_index]; 58 } 59 60 void BookmarkBarBridge::BookmarkNodeChanged(BookmarkModel* model, 61 const BookmarkNode* node) { 62 [controller_ nodeChanged:model node:node]; 63 } 64 65 void BookmarkBarBridge::BookmarkNodeFaviconLoaded(BookmarkModel* model, 66 const BookmarkNode* node) { 67 [controller_ nodeFaviconLoaded:model node:node]; 68 } 69 70 void BookmarkBarBridge::BookmarkNodeChildrenReordered( 71 BookmarkModel* model, const BookmarkNode* node) { 72 [controller_ nodeChildrenReordered:model node:node]; 73 } 74 75 void BookmarkBarBridge::BookmarkImportBeginning(BookmarkModel* model) { 76 batch_mode_ = true; 77 } 78 79 void BookmarkBarBridge::BookmarkImportEnding(BookmarkModel* model) { 80 batch_mode_ = false; 81 [controller_ loaded:model]; 82 } 83