Adding instrumentation to locate the source of jankiness
[chromium-blink-merge.git] / chrome / browser / ui / bookmarks / recently_used_folders_combo_model.h
blob7e61f857fe69df0ed8f610d52e8cf1747558d672
1 // Copyright (c) 2012 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.
5 #ifndef CHROME_BROWSER_UI_BOOKMARKS_RECENTLY_USED_FOLDERS_COMBO_MODEL_H_
6 #define CHROME_BROWSER_UI_BOOKMARKS_RECENTLY_USED_FOLDERS_COMBO_MODEL_H_
8 #include <vector>
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
12 #include "base/observer_list.h"
13 #include "components/bookmarks/browser/bookmark_model_observer.h"
14 #include "ui/base/models/combobox_model.h"
16 class BookmarkModel;
17 class BookmarkNode;
19 // Model for the combobox showing the list of folders to choose from. The
20 // list always contains the Bookmarks Bar, Other Bookmarks and the parent
21 // folder. The list also contains an extra item that shows the text
22 // "Choose Another Folder...".
23 class RecentlyUsedFoldersComboModel : public ui::ComboboxModel,
24 public BookmarkModelObserver {
25 public:
26 RecentlyUsedFoldersComboModel(BookmarkModel* model, const BookmarkNode* node);
27 virtual ~RecentlyUsedFoldersComboModel();
29 // Overridden from ui::ComboboxModel:
30 virtual int GetItemCount() const override;
31 virtual base::string16 GetItemAt(int index) override;
32 virtual bool IsItemSeparatorAt(int index) override;
33 virtual int GetDefaultIndex() const override;
34 virtual void AddObserver(ui::ComboboxModelObserver* observer) override;
35 virtual void RemoveObserver(ui::ComboboxModelObserver* observer) override;
37 // Overriden from BookmarkModelObserver:
38 virtual void BookmarkModelLoaded(BookmarkModel* model,
39 bool ids_reassigned) override;
40 virtual void BookmarkModelBeingDeleted(BookmarkModel* model) override;
41 virtual void BookmarkNodeMoved(BookmarkModel* model,
42 const BookmarkNode* old_parent,
43 int old_index,
44 const BookmarkNode* new_parent,
45 int new_index) override;
46 virtual void BookmarkNodeAdded(BookmarkModel* model,
47 const BookmarkNode* parent,
48 int index) override;
49 virtual void OnWillRemoveBookmarks(BookmarkModel* model,
50 const BookmarkNode* parent,
51 int old_index,
52 const BookmarkNode* node) override;
53 virtual void BookmarkNodeRemoved(BookmarkModel* model,
54 const BookmarkNode* parent,
55 int old_index,
56 const BookmarkNode* node,
57 const std::set<GURL>& removed_urls) override;
58 virtual void BookmarkNodeChanged(BookmarkModel* model,
59 const BookmarkNode* node) override;
60 virtual void BookmarkNodeFaviconChanged(BookmarkModel* model,
61 const BookmarkNode* node) override;
62 virtual void BookmarkNodeChildrenReordered(
63 BookmarkModel* model,
64 const BookmarkNode* node) override;
65 virtual void BookmarkAllUserNodesRemoved(
66 BookmarkModel* model,
67 const std::set<GURL>& removed_urls) override;
69 // If necessary this function moves |node| into the corresponding folder for
70 // the given |selected_index|.
71 void MaybeChangeParent(const BookmarkNode* node, int selected_index);
73 private:
74 // Returns the node at the specified |index|.
75 const BookmarkNode* GetNodeAt(int index);
77 // Removes |node| from |items_|. Does nothing if |node| is not in |items_|.
78 void RemoveNode(const BookmarkNode* node);
80 struct Item;
81 std::vector<Item> items_;
83 BookmarkModel* bookmark_model_;
85 // The index of the original parent folder.
86 int node_parent_index_;
88 ObserverList<ui::ComboboxModelObserver> observers_;
90 DISALLOW_COPY_AND_ASSIGN(RecentlyUsedFoldersComboModel);
93 #endif // CHROME_BROWSER_UI_BOOKMARKS_RECENTLY_USED_FOLDERS_COMBO_MODEL_H_