OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_UI_WEBUI_COOKIES_TREE_MODEL_ADAPTER_H_ |
| 6 #define CHROME_BROWSER_UI_WEBUI_COOKIES_TREE_MODEL_ADAPTER_H_ |
| 7 #pragma once |
| 8 |
| 9 #include "chrome/browser/cookies_tree_model.h" |
| 10 |
| 11 class ListValue; |
| 12 class WebUI; |
| 13 |
| 14 // CookiesTreeModelAdapter binds a CookiesTreeModel with a JS tree. It observes |
| 15 // tree model changes and forwards them to JS tree. It also provides a |
| 16 // a callback for JS tree to load children of a specific node. |
| 17 class CookiesTreeModelAdapter : public CookiesTreeModel::Observer { |
| 18 public: |
| 19 CookiesTreeModelAdapter(); |
| 20 virtual ~CookiesTreeModelAdapter(); |
| 21 |
| 22 // Initializes with given WebUI. |
| 23 void Init(WebUI* web_ui); |
| 24 |
| 25 // Sets up the bindings between js tree and |model|. |
| 26 // Note that this class does not take ownership of the model. |
| 27 void Bind(const std::string& tree_id, CookiesTreeModel* model); |
| 28 |
| 29 private: |
| 30 // CookiesTreeModel::Observer implementation. |
| 31 virtual void TreeNodesAdded(ui::TreeModel* model, |
| 32 ui::TreeModelNode* parent, |
| 33 int start, |
| 34 int count); |
| 35 virtual void TreeNodesRemoved(ui::TreeModel* model, |
| 36 ui::TreeModelNode* parent, |
| 37 int start, |
| 38 int count); |
| 39 virtual void TreeNodeChanged(ui::TreeModel* model, ui::TreeModelNode* node) {} |
| 40 virtual void TreeModelBeginBatch(CookiesTreeModel* model); |
| 41 virtual void TreeModelEndBatch(CookiesTreeModel* model); |
| 42 |
| 43 // JS callback that gets the tree node using the tree path info in |args| and |
| 44 // call SendChildren to pass back children nodes data to WebUI. |
| 45 void LoadChildren(const ListValue* args); |
| 46 |
| 47 // Get children nodes data and pass it to 'CookiesTree.loadChildren' to |
| 48 // update the WebUI. |
| 49 void SendChildren(CookieTreeNode* parent); |
| 50 |
| 51 // Hosting WebUI of the js tree. |
| 52 WebUI* web_ui_; |
| 53 |
| 54 // Id of JS tree that is managed by this handler. |
| 55 std::string tree_id_; |
| 56 |
| 57 // The Cookies Tree model. Note that we are not owning the model. |
| 58 CookiesTreeModel* model_; |
| 59 |
| 60 // Flag to indicate whether there is a batch update in progress. |
| 61 bool batch_update_; |
| 62 |
| 63 DISALLOW_COPY_AND_ASSIGN(CookiesTreeModelAdapter); |
| 64 }; |
| 65 |
| 66 #endif // CHROME_BROWSER_UI_WEBUI_COOKIES_TREE_MODEL_ADAPTER_H_ |
OLD | NEW |