Home | History | Annotate | Download | only in webui
      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.
      4 
      5 #ifndef CHROME_BROWSER_UI_WEBUI_COOKIES_TREE_MODEL_UTIL_H_
      6 #define CHROME_BROWSER_UI_WEBUI_COOKIES_TREE_MODEL_UTIL_H_
      7 
      8 #include <map>
      9 #include <string>
     10 
     11 #include "base/basictypes.h"
     12 #include "base/id_map.h"
     13 
     14 class CookieTreeNode;
     15 
     16 namespace base {
     17 class DictionaryValue;
     18 class ListValue;
     19 }
     20 
     21 class CookiesTreeModelUtil {
     22  public:
     23   CookiesTreeModelUtil();
     24   ~CookiesTreeModelUtil();
     25 
     26   // Finds or creates an ID for given |node| and returns it as string.
     27   std::string GetTreeNodeId(const CookieTreeNode* node);
     28 
     29   // Append the children nodes of |parent| in specified range to |nodes| list.
     30   void GetChildNodeList(const CookieTreeNode* parent,
     31                         int start,
     32                         int count,
     33                         base::ListValue* nodes);
     34 
     35   // Gets tree node from |path| under |root|. |path| is comma separated list of
     36   // ids. |id_map| translates ids into object pointers. Return NULL if |path|
     37   // is not valid.
     38   const CookieTreeNode* GetTreeNodeFromPath(const CookieTreeNode* root,
     39                                             const std::string& path);
     40 
     41  private:
     42   typedef IDMap<const CookieTreeNode> CookiesTreeNodeIdMap;
     43   typedef std::map<const CookieTreeNode*, int32> CookieTreeNodeMap;
     44 
     45   // Populate given |dict| with cookie tree node properties. |id_map| maps
     46   // a CookieTreeNode to an ID and creates a new ID if |node| is not in the
     47   // maps. Returns false if the |node| does not need to be shown.
     48   bool GetCookieTreeNodeDictionary(const CookieTreeNode& node,
     49                                    base::DictionaryValue* dict);
     50 
     51   // IDMap to create unique ID and look up the object for an ID.
     52   CookiesTreeNodeIdMap id_map_;
     53 
     54   // Reverse look up map to find the ID for a node.
     55   CookieTreeNodeMap node_map_;
     56 
     57   DISALLOW_COPY_AND_ASSIGN(CookiesTreeModelUtil);
     58 };
     59 
     60 #endif  // CHROME_BROWSER_UI_WEBUI_COOKIES_TREE_MODEL_UTIL_H_
     61