Home | History | Annotate | Download | only in browsing_data
      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_BROWSING_DATA_COOKIES_TREE_MODEL_H_
      6 #define CHROME_BROWSER_BROWSING_DATA_COOKIES_TREE_MODEL_H_
      7 
      8 // TODO(viettrungluu): This header file #includes far too much and has too much
      9 // inline code (which shouldn't be inline).
     10 
     11 #include <list>
     12 #include <string>
     13 #include <vector>
     14 
     15 #include "base/memory/ref_counted.h"
     16 #include "base/memory/weak_ptr.h"
     17 #include "base/observer_list.h"
     18 #include "base/strings/string16.h"
     19 #include "base/strings/utf_string_conversions.h"
     20 #include "chrome/browser/browsing_data/browsing_data_appcache_helper.h"
     21 #include "chrome/browser/browsing_data/browsing_data_database_helper.h"
     22 #include "chrome/browser/browsing_data/browsing_data_file_system_helper.h"
     23 #include "chrome/browser/browsing_data/browsing_data_indexed_db_helper.h"
     24 #include "chrome/browser/browsing_data/browsing_data_local_storage_helper.h"
     25 #include "chrome/browser/browsing_data/browsing_data_quota_helper.h"
     26 #include "chrome/browser/browsing_data/local_data_container.h"
     27 #include "chrome/common/content_settings.h"
     28 #include "chrome/common/extensions/extension_set.h"
     29 #include "net/ssl/server_bound_cert_store.h"
     30 #include "ui/base/models/tree_node_model.h"
     31 
     32 class BrowsingDataCookieHelper;
     33 class BrowsingDataServerBoundCertHelper;
     34 class CookieSettings;
     35 class CookiesTreeModel;
     36 class CookieTreeAppCacheNode;
     37 class CookieTreeAppCachesNode;
     38 class CookieTreeCookieNode;
     39 class CookieTreeCookiesNode;
     40 class CookieTreeDatabaseNode;
     41 class CookieTreeDatabasesNode;
     42 class CookieTreeFileSystemNode;
     43 class CookieTreeFileSystemsNode;
     44 class CookieTreeFlashLSONode;
     45 class CookieTreeHostNode;
     46 class CookieTreeIndexedDBNode;
     47 class CookieTreeIndexedDBsNode;
     48 class CookieTreeLocalStorageNode;
     49 class CookieTreeLocalStoragesNode;
     50 class CookieTreeQuotaNode;
     51 class CookieTreeServerBoundCertNode;
     52 class CookieTreeServerBoundCertsNode;
     53 class CookieTreeSessionStorageNode;
     54 class CookieTreeSessionStoragesNode;
     55 class ExtensionSpecialStoragePolicy;
     56 
     57 namespace net {
     58 class CanonicalCookie;
     59 }
     60 
     61 // CookieTreeNode -------------------------------------------------------------
     62 // The base node type in the Cookies, Databases, and Local Storage options
     63 // view, from which all other types are derived. Specialized from TreeNode in
     64 // that it has a notion of deleting objects stored in the profile, and being
     65 // able to have its children do the same.
     66 class CookieTreeNode : public ui::TreeNode<CookieTreeNode> {
     67  public:
     68   // Used to pull out information for the InfoView (the details display below
     69   // the tree control.)
     70   struct DetailedInfo {
     71     // NodeType corresponds to the various CookieTreeNode types.
     72     enum NodeType {
     73       TYPE_NONE,
     74       TYPE_ROOT,  // This is used for CookieTreeRootNode nodes.
     75       TYPE_HOST,  // This is used for CookieTreeHostNode nodes.
     76       TYPE_COOKIES,  // This is used for CookieTreeCookiesNode nodes.
     77       TYPE_COOKIE,  // This is used for CookieTreeCookieNode nodes.
     78       TYPE_DATABASES,  // This is used for CookieTreeDatabasesNode.
     79       TYPE_DATABASE,  // This is used for CookieTreeDatabaseNode.
     80       TYPE_LOCAL_STORAGES,  // This is used for CookieTreeLocalStoragesNode.
     81       TYPE_LOCAL_STORAGE,  // This is used for CookieTreeLocalStorageNode.
     82       TYPE_SESSION_STORAGES,  // This is used for CookieTreeSessionStoragesNode.
     83       TYPE_SESSION_STORAGE,  // This is used for CookieTreeSessionStorageNode.
     84       TYPE_APPCACHES,  // This is used for CookieTreeAppCachesNode.
     85       TYPE_APPCACHE,  // This is used for CookieTreeAppCacheNode.
     86       TYPE_INDEXED_DBS,  // This is used for CookieTreeIndexedDBsNode.
     87       TYPE_INDEXED_DB,  // This is used for CookieTreeIndexedDBNode.
     88       TYPE_FILE_SYSTEMS,  // This is used for CookieTreeFileSystemsNode.
     89       TYPE_FILE_SYSTEM,  // This is used for CookieTreeFileSystemNode.
     90       TYPE_QUOTA,  // This is used for CookieTreeQuotaNode.
     91       TYPE_SERVER_BOUND_CERTS, // Used for CookieTreeServerBoundCertsNode.
     92       TYPE_SERVER_BOUND_CERT, // Used for CookieTreeServerBoundCertNode.
     93       TYPE_FLASH_LSO,  // This is used for CookieTreeFlashLSONode.
     94     };
     95 
     96     DetailedInfo();
     97     ~DetailedInfo();
     98 
     99     DetailedInfo& Init(NodeType type);
    100     DetailedInfo& InitHost();
    101     DetailedInfo& InitCookie(const net::CanonicalCookie* cookie);
    102     DetailedInfo& InitDatabase(
    103         const BrowsingDataDatabaseHelper::DatabaseInfo* database_info);
    104     DetailedInfo& InitLocalStorage(
    105         const BrowsingDataLocalStorageHelper::LocalStorageInfo*
    106         local_storage_info);
    107     DetailedInfo& InitSessionStorage(
    108         const BrowsingDataLocalStorageHelper::LocalStorageInfo*
    109         session_storage_info);
    110     DetailedInfo& InitAppCache(const GURL& origin,
    111                                const appcache::AppCacheInfo* appcache_info);
    112     DetailedInfo& InitIndexedDB(
    113         const content::IndexedDBInfo* indexed_db_info);
    114     DetailedInfo& InitFileSystem(
    115         const BrowsingDataFileSystemHelper::FileSystemInfo* file_system_info);
    116     DetailedInfo& InitQuota(
    117         const BrowsingDataQuotaHelper::QuotaInfo* quota_info);
    118     DetailedInfo& InitServerBoundCert(
    119         const net::ServerBoundCertStore::ServerBoundCert* server_bound_cert);
    120     DetailedInfo& InitFlashLSO(const std::string& flash_lso_domain);
    121 
    122     NodeType node_type;
    123     GURL origin;
    124     const net::CanonicalCookie* cookie;
    125     const BrowsingDataDatabaseHelper::DatabaseInfo* database_info;
    126     const BrowsingDataLocalStorageHelper::LocalStorageInfo* local_storage_info;
    127     const BrowsingDataLocalStorageHelper::LocalStorageInfo*
    128         session_storage_info;
    129     const appcache::AppCacheInfo* appcache_info;
    130     const content::IndexedDBInfo* indexed_db_info;
    131     const BrowsingDataFileSystemHelper::FileSystemInfo* file_system_info;
    132     const BrowsingDataQuotaHelper::QuotaInfo* quota_info;
    133     const net::ServerBoundCertStore::ServerBoundCert* server_bound_cert;
    134     std::string flash_lso_domain;
    135   };
    136 
    137   CookieTreeNode() {}
    138   explicit CookieTreeNode(const string16& title)
    139       : ui::TreeNode<CookieTreeNode>(title) {}
    140   virtual ~CookieTreeNode() {}
    141 
    142   // Delete backend storage for this node, and any children nodes. (E.g. delete
    143   // the cookie from CookieMonster, clear the database, and so forth.)
    144   virtual void DeleteStoredObjects();
    145 
    146   // Gets a pointer back to the associated model for the tree we are in.
    147   virtual CookiesTreeModel* GetModel() const;
    148 
    149   // Returns a struct with detailed information used to populate the details
    150   // part of the view.
    151   virtual DetailedInfo GetDetailedInfo() const = 0;
    152 
    153  protected:
    154   void AddChildSortedByTitle(CookieTreeNode* new_child);
    155 
    156  private:
    157   DISALLOW_COPY_AND_ASSIGN(CookieTreeNode);
    158 };
    159 
    160 // CookieTreeRootNode ---------------------------------------------------------
    161 // The node at the root of the CookieTree that gets inserted into the view.
    162 class CookieTreeRootNode : public CookieTreeNode {
    163  public:
    164   explicit CookieTreeRootNode(CookiesTreeModel* model);
    165   virtual ~CookieTreeRootNode();
    166 
    167   CookieTreeHostNode* GetOrCreateHostNode(const GURL& url);
    168 
    169   // CookieTreeNode methods:
    170   virtual CookiesTreeModel* GetModel() const OVERRIDE;
    171   virtual DetailedInfo GetDetailedInfo() const OVERRIDE;
    172 
    173  private:
    174   CookiesTreeModel* model_;
    175 
    176   DISALLOW_COPY_AND_ASSIGN(CookieTreeRootNode);
    177 };
    178 
    179 // CookieTreeHostNode -------------------------------------------------------
    180 class CookieTreeHostNode : public CookieTreeNode {
    181  public:
    182   // Returns the host node's title to use for a given URL.
    183   static string16 TitleForUrl(const GURL& url);
    184 
    185   explicit CookieTreeHostNode(const GURL& url);
    186   virtual ~CookieTreeHostNode();
    187 
    188   // CookieTreeNode methods:
    189   virtual DetailedInfo GetDetailedInfo() const OVERRIDE;
    190 
    191   // CookieTreeHostNode methods:
    192   CookieTreeCookiesNode* GetOrCreateCookiesNode();
    193   CookieTreeDatabasesNode* GetOrCreateDatabasesNode();
    194   CookieTreeLocalStoragesNode* GetOrCreateLocalStoragesNode();
    195   CookieTreeSessionStoragesNode* GetOrCreateSessionStoragesNode();
    196   CookieTreeAppCachesNode* GetOrCreateAppCachesNode();
    197   CookieTreeIndexedDBsNode* GetOrCreateIndexedDBsNode();
    198   CookieTreeFileSystemsNode* GetOrCreateFileSystemsNode();
    199   CookieTreeServerBoundCertsNode* GetOrCreateServerBoundCertsNode();
    200   CookieTreeQuotaNode* UpdateOrCreateQuotaNode(
    201       std::list<BrowsingDataQuotaHelper::QuotaInfo>::iterator quota_info);
    202   CookieTreeFlashLSONode* GetOrCreateFlashLSONode(const std::string& domain);
    203 
    204   std::string canonicalized_host() const { return canonicalized_host_; }
    205 
    206   // Creates an content exception for this origin of type
    207   // CONTENT_SETTINGS_TYPE_COOKIES.
    208   void CreateContentException(CookieSettings* cookie_settings,
    209                               ContentSetting setting) const;
    210 
    211   // True if a content exception can be created for this origin.
    212   bool CanCreateContentException() const;
    213 
    214   const std::string GetHost() const;
    215 
    216  private:
    217   // Pointers to the cookies, databases, local and session storage and appcache
    218   // nodes.  When we build up the tree we need to quickly get a reference to
    219   // the COOKIES node to add children. Checking each child and interrogating
    220   // them to see if they are a COOKIES, APPCACHES, DATABASES etc node seems
    221   // less preferable than storing an extra pointer per origin.
    222   CookieTreeCookiesNode* cookies_child_;
    223   CookieTreeDatabasesNode* databases_child_;
    224   CookieTreeLocalStoragesNode* local_storages_child_;
    225   CookieTreeSessionStoragesNode* session_storages_child_;
    226   CookieTreeAppCachesNode* appcaches_child_;
    227   CookieTreeIndexedDBsNode* indexed_dbs_child_;
    228   CookieTreeFileSystemsNode* file_systems_child_;
    229   CookieTreeQuotaNode* quota_child_;
    230   CookieTreeServerBoundCertsNode* server_bound_certs_child_;
    231   CookieTreeFlashLSONode* flash_lso_child_;
    232 
    233   // The URL for which this node was initially created.
    234   GURL url_;
    235 
    236   std::string canonicalized_host_;
    237 
    238   DISALLOW_COPY_AND_ASSIGN(CookieTreeHostNode);
    239 };
    240 
    241 // CookieTreeCookieNode ------------------------------------------------------
    242 class CookieTreeCookieNode : public CookieTreeNode {
    243  public:
    244   friend class CookieTreeCookiesNode;
    245 
    246   // The cookie should remain valid at least as long as the
    247   // CookieTreeCookieNode is valid.
    248   explicit CookieTreeCookieNode(
    249       std::list<net::CanonicalCookie>::iterator cookie);
    250   virtual ~CookieTreeCookieNode();
    251 
    252   // CookieTreeNode methods:
    253   virtual void DeleteStoredObjects() OVERRIDE;
    254   virtual DetailedInfo GetDetailedInfo() const OVERRIDE;
    255 
    256  private:
    257   // cookie_ is expected to remain valid as long as the CookieTreeCookieNode is
    258   // valid.
    259   std::list<net::CanonicalCookie>::iterator cookie_;
    260 
    261   DISALLOW_COPY_AND_ASSIGN(CookieTreeCookieNode);
    262 };
    263 
    264 class CookieTreeCookiesNode : public CookieTreeNode {
    265  public:
    266   CookieTreeCookiesNode();
    267   virtual ~CookieTreeCookiesNode();
    268 
    269   virtual DetailedInfo GetDetailedInfo() const OVERRIDE;
    270 
    271   void AddCookieNode(CookieTreeCookieNode* child) {
    272     AddChildSortedByTitle(child);
    273   }
    274 
    275  private:
    276   DISALLOW_COPY_AND_ASSIGN(CookieTreeCookiesNode);
    277 };
    278 
    279 // CookieTreeAppCacheNode -----------------------------------------------------
    280 class CookieTreeAppCacheNode : public CookieTreeNode {
    281  public:
    282   friend class CookieTreeAppCachesNode;
    283 
    284   // appcache_info should remain valid at least as long as the
    285   // CookieTreeAppCacheNode is valid.
    286   explicit CookieTreeAppCacheNode(
    287       const GURL& origin_url,
    288       std::list<appcache::AppCacheInfo>::iterator appcache_info);
    289   virtual ~CookieTreeAppCacheNode();
    290 
    291   virtual void DeleteStoredObjects() OVERRIDE;
    292   virtual DetailedInfo GetDetailedInfo() const OVERRIDE;
    293 
    294  private:
    295   GURL origin_url_;
    296   std::list<appcache::AppCacheInfo>::iterator appcache_info_;
    297   DISALLOW_COPY_AND_ASSIGN(CookieTreeAppCacheNode);
    298 };
    299 
    300 class CookieTreeAppCachesNode : public CookieTreeNode {
    301  public:
    302   CookieTreeAppCachesNode();
    303   virtual ~CookieTreeAppCachesNode();
    304 
    305   virtual DetailedInfo GetDetailedInfo() const OVERRIDE;
    306 
    307   void AddAppCacheNode(CookieTreeAppCacheNode* child) {
    308     AddChildSortedByTitle(child);
    309   }
    310 
    311  private:
    312   DISALLOW_COPY_AND_ASSIGN(CookieTreeAppCachesNode);
    313 };
    314 
    315 // CookieTreeDatabaseNode -----------------------------------------------------
    316 class CookieTreeDatabaseNode : public CookieTreeNode {
    317  public:
    318   friend class CookieTreeDatabasesNode;
    319 
    320   // database_info should remain valid at least as long as the
    321   // CookieTreeDatabaseNode is valid.
    322   explicit CookieTreeDatabaseNode(
    323       std::list<BrowsingDataDatabaseHelper::DatabaseInfo>::iterator
    324           database_info);
    325   virtual ~CookieTreeDatabaseNode();
    326 
    327   virtual void DeleteStoredObjects() OVERRIDE;
    328   virtual DetailedInfo GetDetailedInfo() const OVERRIDE;
    329 
    330  private:
    331   // database_info_ is expected to remain valid as long as the
    332   // CookieTreeDatabaseNode is valid.
    333   std::list<BrowsingDataDatabaseHelper::DatabaseInfo>::iterator
    334       database_info_;
    335 
    336   DISALLOW_COPY_AND_ASSIGN(CookieTreeDatabaseNode);
    337 };
    338 
    339 class CookieTreeDatabasesNode : public CookieTreeNode {
    340  public:
    341   CookieTreeDatabasesNode();
    342   virtual ~CookieTreeDatabasesNode();
    343 
    344   virtual DetailedInfo GetDetailedInfo() const OVERRIDE;
    345 
    346   void AddDatabaseNode(CookieTreeDatabaseNode* child) {
    347     AddChildSortedByTitle(child);
    348   }
    349 
    350  private:
    351   DISALLOW_COPY_AND_ASSIGN(CookieTreeDatabasesNode);
    352 };
    353 
    354 // CookieTreeFileSystemNode --------------------------------------------------
    355 class CookieTreeFileSystemNode : public CookieTreeNode {
    356  public:
    357   friend class CookieTreeFileSystemsNode;
    358 
    359   // file_system_info should remain valid at least as long as the
    360   // CookieTreeFileSystemNode is valid.
    361   explicit CookieTreeFileSystemNode(
    362       std::list<BrowsingDataFileSystemHelper::FileSystemInfo>::iterator
    363           file_system_info);
    364   virtual ~CookieTreeFileSystemNode();
    365 
    366   virtual void DeleteStoredObjects() OVERRIDE;
    367   virtual DetailedInfo GetDetailedInfo() const OVERRIDE;
    368 
    369  private:
    370   // file_system_info_ expected to remain valid as long as the
    371   // CookieTreeFileSystemNode is valid.
    372   std::list<BrowsingDataFileSystemHelper::FileSystemInfo>::iterator
    373       file_system_info_;
    374 
    375   DISALLOW_COPY_AND_ASSIGN(CookieTreeFileSystemNode);
    376 };
    377 
    378 class CookieTreeFileSystemsNode : public CookieTreeNode {
    379  public:
    380   CookieTreeFileSystemsNode();
    381   virtual ~CookieTreeFileSystemsNode();
    382 
    383   virtual DetailedInfo GetDetailedInfo() const OVERRIDE;
    384 
    385   void AddFileSystemNode(CookieTreeFileSystemNode* child) {
    386     AddChildSortedByTitle(child);
    387   }
    388 
    389  private:
    390   DISALLOW_COPY_AND_ASSIGN(CookieTreeFileSystemsNode);
    391 };
    392 
    393 // CookieTreeLocalStorageNode -------------------------------------------------
    394 class CookieTreeLocalStorageNode : public CookieTreeNode {
    395  public:
    396   // local_storage_info should remain valid at least as long as the
    397   // CookieTreeLocalStorageNode is valid.
    398   explicit CookieTreeLocalStorageNode(
    399       std::list<BrowsingDataLocalStorageHelper::LocalStorageInfo>::iterator
    400           local_storage_info);
    401   virtual ~CookieTreeLocalStorageNode();
    402 
    403   // CookieTreeNode methods:
    404   virtual void DeleteStoredObjects() OVERRIDE;
    405   virtual DetailedInfo GetDetailedInfo() const OVERRIDE;
    406 
    407  private:
    408   // local_storage_info_ is expected to remain valid as long as the
    409   // CookieTreeLocalStorageNode is valid.
    410   std::list<BrowsingDataLocalStorageHelper::LocalStorageInfo>::iterator
    411       local_storage_info_;
    412 
    413   DISALLOW_COPY_AND_ASSIGN(CookieTreeLocalStorageNode);
    414 };
    415 
    416 class CookieTreeLocalStoragesNode : public CookieTreeNode {
    417  public:
    418   CookieTreeLocalStoragesNode();
    419   virtual ~CookieTreeLocalStoragesNode();
    420 
    421   virtual DetailedInfo GetDetailedInfo() const OVERRIDE;
    422 
    423   void AddLocalStorageNode(CookieTreeLocalStorageNode* child) {
    424     AddChildSortedByTitle(child);
    425   }
    426 
    427  private:
    428 
    429   DISALLOW_COPY_AND_ASSIGN(CookieTreeLocalStoragesNode);
    430 };
    431 
    432 
    433 // CookieTreeSessionStorageNode -----------------------------------------------
    434 class CookieTreeSessionStorageNode : public CookieTreeNode {
    435  public:
    436   // session_storage_info should remain valid at least as long as the
    437   // CookieTreeSessionStorageNode is valid.
    438   explicit CookieTreeSessionStorageNode(
    439       std::list<BrowsingDataLocalStorageHelper::LocalStorageInfo>::iterator
    440           session_storage_info);
    441   virtual ~CookieTreeSessionStorageNode();
    442 
    443   // CookieTreeNode methods:
    444   virtual void DeleteStoredObjects() OVERRIDE;
    445   virtual DetailedInfo GetDetailedInfo() const OVERRIDE;
    446 
    447  private:
    448   // session_storage_info_ is expected to remain valid as long as the
    449   // CookieTreeSessionStorageNode is valid.
    450   std::list<BrowsingDataLocalStorageHelper::LocalStorageInfo>::iterator
    451       session_storage_info_;
    452 
    453   DISALLOW_COPY_AND_ASSIGN(CookieTreeSessionStorageNode);
    454 };
    455 
    456 class CookieTreeSessionStoragesNode : public CookieTreeNode {
    457  public:
    458   CookieTreeSessionStoragesNode();
    459   virtual ~CookieTreeSessionStoragesNode();
    460 
    461   virtual DetailedInfo GetDetailedInfo() const OVERRIDE;
    462 
    463   void AddSessionStorageNode(CookieTreeSessionStorageNode* child) {
    464     AddChildSortedByTitle(child);
    465   }
    466 
    467  private:
    468 
    469   DISALLOW_COPY_AND_ASSIGN(CookieTreeSessionStoragesNode);
    470 };
    471 
    472 // CookieTreeIndexedDBNode -----------------------------------------------
    473 class CookieTreeIndexedDBNode : public CookieTreeNode {
    474  public:
    475   // indexed_db_info should remain valid at least as long as the
    476   // CookieTreeIndexedDBNode is valid.
    477   explicit CookieTreeIndexedDBNode(
    478       std::list<content::IndexedDBInfo>::iterator
    479           indexed_db_info);
    480   virtual ~CookieTreeIndexedDBNode();
    481 
    482   // CookieTreeNode methods:
    483   virtual void DeleteStoredObjects() OVERRIDE;
    484   virtual DetailedInfo GetDetailedInfo() const OVERRIDE;
    485 
    486  private:
    487   // indexed_db_info_ is expected to remain valid as long as the
    488   // CookieTreeIndexedDBNode is valid.
    489   std::list<content::IndexedDBInfo>::iterator
    490       indexed_db_info_;
    491 
    492   DISALLOW_COPY_AND_ASSIGN(CookieTreeIndexedDBNode);
    493 };
    494 
    495 class CookieTreeIndexedDBsNode : public CookieTreeNode {
    496  public:
    497   CookieTreeIndexedDBsNode();
    498   virtual ~CookieTreeIndexedDBsNode();
    499 
    500   virtual DetailedInfo GetDetailedInfo() const OVERRIDE;
    501 
    502   void AddIndexedDBNode(CookieTreeIndexedDBNode* child) {
    503     AddChildSortedByTitle(child);
    504   }
    505 
    506  private:
    507   DISALLOW_COPY_AND_ASSIGN(CookieTreeIndexedDBsNode);
    508 };
    509 
    510 // CookieTreeQuotaNode --------------------------------------------------
    511 class CookieTreeQuotaNode : public CookieTreeNode {
    512  public:
    513   // quota_info should remain valid at least as long as the CookieTreeQuotaNode
    514   // is valid.
    515   explicit CookieTreeQuotaNode(
    516       std::list<BrowsingDataQuotaHelper::QuotaInfo>::iterator quota_info);
    517   virtual ~CookieTreeQuotaNode();
    518 
    519   virtual void DeleteStoredObjects() OVERRIDE;
    520   virtual DetailedInfo GetDetailedInfo() const OVERRIDE;
    521 
    522  private:
    523   // quota_info_ is expected to remain valid as long as the CookieTreeQuotaNode
    524   // is valid.
    525   std::list<BrowsingDataQuotaHelper::QuotaInfo>::iterator quota_info_;
    526 
    527   DISALLOW_COPY_AND_ASSIGN(CookieTreeQuotaNode);
    528 };
    529 
    530 // CookieTreeServerBoundCertNode ---------------------------------------------
    531 class CookieTreeServerBoundCertNode : public CookieTreeNode {
    532  public:
    533   friend class CookieTreeServerBoundCertsNode;
    534 
    535   // The iterator should remain valid at least as long as the
    536   // CookieTreeServerBoundCertNode is valid.
    537   explicit CookieTreeServerBoundCertNode(
    538       net::ServerBoundCertStore::ServerBoundCertList::iterator cert);
    539   virtual ~CookieTreeServerBoundCertNode();
    540 
    541   // CookieTreeNode methods:
    542   virtual void DeleteStoredObjects() OVERRIDE;
    543   virtual DetailedInfo GetDetailedInfo() const OVERRIDE;
    544 
    545  private:
    546   // server_bound_cert_ is expected to remain valid as long as the
    547   // CookieTreeServerBoundCertNode is valid.
    548   net::ServerBoundCertStore::ServerBoundCertList::iterator server_bound_cert_;
    549 
    550   DISALLOW_COPY_AND_ASSIGN(CookieTreeServerBoundCertNode);
    551 };
    552 
    553 class CookieTreeServerBoundCertsNode : public CookieTreeNode {
    554  public:
    555   CookieTreeServerBoundCertsNode();
    556   virtual ~CookieTreeServerBoundCertsNode();
    557 
    558   virtual DetailedInfo GetDetailedInfo() const OVERRIDE;
    559 
    560   void AddServerBoundCertNode(CookieTreeServerBoundCertNode* child) {
    561     AddChildSortedByTitle(child);
    562   }
    563 
    564  private:
    565   DISALLOW_COPY_AND_ASSIGN(CookieTreeServerBoundCertsNode);
    566 };
    567 
    568 // CookieTreeFlashLSONode ----------------------------------------------------
    569 class CookieTreeFlashLSONode : public CookieTreeNode {
    570  public:
    571   explicit CookieTreeFlashLSONode(const std::string& domain);
    572   virtual ~CookieTreeFlashLSONode();
    573 
    574   // CookieTreeNode methods:
    575   virtual void DeleteStoredObjects() OVERRIDE;
    576   virtual DetailedInfo GetDetailedInfo() const OVERRIDE;
    577 
    578  private:
    579   std::string domain_;
    580 
    581   DISALLOW_COPY_AND_ASSIGN(CookieTreeFlashLSONode);
    582 };
    583 
    584 // CookiesTreeModel -----------------------------------------------------------
    585 class CookiesTreeModel : public ui::TreeNodeModel<CookieTreeNode> {
    586  public:
    587   CookiesTreeModel(LocalDataContainer* data_container,
    588                    ExtensionSpecialStoragePolicy* special_storage_policy,
    589                    bool group_by_cookie_source);
    590   virtual ~CookiesTreeModel();
    591 
    592   // Because non-cookie nodes are fetched in a background thread, they are not
    593   // present at the time the Model is created. The Model then notifies its
    594   // observers for every item added from databases, local storage, and
    595   // appcache. We extend the Observer interface to add notifications before and
    596   // after these batch inserts.
    597   class Observer : public ui::TreeModelObserver {
    598    public:
    599     virtual void TreeModelBeginBatch(CookiesTreeModel* model) {}
    600     virtual void TreeModelEndBatch(CookiesTreeModel* model) {}
    601   };
    602 
    603   // This class defines the scope for batch updates. It can be created as a
    604   // local variable and the destructor will terminate the batch update, if one
    605   // has been started.
    606   class ScopedBatchUpdateNotifier {
    607    public:
    608     ScopedBatchUpdateNotifier(CookiesTreeModel* model,
    609                               CookieTreeNode* node);
    610     ~ScopedBatchUpdateNotifier();
    611 
    612     void StartBatchUpdate();
    613 
    614    private:
    615     CookiesTreeModel* model_;
    616     CookieTreeNode* node_;
    617     bool batch_in_progress_;
    618   };
    619 
    620   // ui::TreeModel methods:
    621   // Returns the set of icons for the nodes in the tree. You only need override
    622   // this if you don't want to use the default folder icons.
    623   virtual void GetIcons(std::vector<gfx::ImageSkia>* icons) OVERRIDE;
    624 
    625   // Returns the index of the icon to use for |node|. Return -1 to use the
    626   // default icon. The index is relative to the list of icons returned from
    627   // GetIcons.
    628   virtual int GetIconIndex(ui::TreeModelNode* node) OVERRIDE;
    629 
    630   // CookiesTreeModel methods:
    631   void DeleteAllStoredObjects();
    632 
    633   // Deletes a specific node in the tree, identified by |cookie_node|, and its
    634   // subtree.
    635   void DeleteCookieNode(CookieTreeNode* cookie_node);
    636 
    637   // Filter the origins to only display matched results.
    638   void UpdateSearchResults(const string16& filter);
    639 
    640   // Returns the set of extensions which protect the data item represented by
    641   // this node from deletion.
    642   // Returns NULL if the node doesn't represent a protected data item or the
    643   // special storage policy is NULL.
    644   const ExtensionSet* ExtensionsProtectingNode(
    645       const CookieTreeNode& cookie_node);
    646 
    647   // Manages CookiesTreeModel::Observers. This will also call
    648   // TreeNodeModel::AddObserver so that it gets all the proper notifications.
    649   // Note that the converse is not true: simply adding a TreeModelObserver will
    650   // not get CookiesTreeModel::Observer notifications.
    651   virtual void AddCookiesTreeObserver(Observer* observer);
    652   virtual void RemoveCookiesTreeObserver(Observer* observer);
    653 
    654   // Methods that update the model based on the data retrieved by the browsing
    655   // data helpers.
    656   void PopulateAppCacheInfo(LocalDataContainer* container);
    657   void PopulateCookieInfo(LocalDataContainer* container);
    658   void PopulateDatabaseInfo(LocalDataContainer* container);
    659   void PopulateLocalStorageInfo(LocalDataContainer* container);
    660   void PopulateSessionStorageInfo(LocalDataContainer* container);
    661   void PopulateIndexedDBInfo(LocalDataContainer* container);
    662   void PopulateFileSystemInfo(LocalDataContainer* container);
    663   void PopulateQuotaInfo(LocalDataContainer* container);
    664   void PopulateServerBoundCertInfo(LocalDataContainer* container);
    665   void PopulateFlashLSOInfo(LocalDataContainer* container);
    666 
    667   BrowsingDataCookieHelper* GetCookieHelper(const std::string& app_id);
    668   LocalDataContainer* data_container() {
    669     return data_container_.get();
    670   }
    671 
    672  private:
    673   enum CookieIconIndex {
    674     ORIGIN = 0,
    675     COOKIE = 1,
    676     DATABASE = 2
    677   };
    678 
    679   void NotifyObserverBeginBatch();
    680   void NotifyObserverEndBatch();
    681 
    682   void PopulateAppCacheInfoWithFilter(LocalDataContainer* container,
    683                                       ScopedBatchUpdateNotifier* notifier,
    684                                       const string16& filter);
    685   void PopulateCookieInfoWithFilter(LocalDataContainer* container,
    686                                     ScopedBatchUpdateNotifier* notifier,
    687                                     const string16& filter);
    688   void PopulateDatabaseInfoWithFilter(LocalDataContainer* container,
    689                                       ScopedBatchUpdateNotifier* notifier,
    690                                       const string16& filter);
    691   void PopulateLocalStorageInfoWithFilter(LocalDataContainer* container,
    692                                           ScopedBatchUpdateNotifier* notifier,
    693                                           const string16& filter);
    694   void PopulateSessionStorageInfoWithFilter(LocalDataContainer* container,
    695                                             ScopedBatchUpdateNotifier* notifier,
    696                                             const string16& filter);
    697   void PopulateIndexedDBInfoWithFilter(LocalDataContainer* container,
    698                                        ScopedBatchUpdateNotifier* notifier,
    699                                        const string16& filter);
    700   void PopulateFileSystemInfoWithFilter(LocalDataContainer* container,
    701                                         ScopedBatchUpdateNotifier* notifier,
    702                                         const string16& filter);
    703   void PopulateQuotaInfoWithFilter(LocalDataContainer* container,
    704                                    ScopedBatchUpdateNotifier* notifier,
    705                                    const string16& filter);
    706   void PopulateServerBoundCertInfoWithFilter(
    707       LocalDataContainer* container,
    708       ScopedBatchUpdateNotifier* notifier,
    709       const string16& filter);
    710   void PopulateFlashLSOInfoWithFilter(LocalDataContainer* container,
    711                                       ScopedBatchUpdateNotifier* notifier,
    712                                       const string16& filter);
    713 
    714   // Map of app ids to LocalDataContainer objects to use when retrieving
    715   // locally stored data.
    716   scoped_ptr<LocalDataContainer> data_container_;
    717 
    718   // The extension special storage policy; see ExtensionsProtectingNode() above.
    719   scoped_refptr<ExtensionSpecialStoragePolicy> special_storage_policy_;
    720 
    721   // The CookiesTreeModel maintains a separate list of observers that are
    722   // specifically of the type CookiesTreeModel::Observer.
    723   ObserverList<Observer> cookies_observer_list_;
    724 
    725   // If true, use the CanonicalCookie::Source attribute to group cookies.
    726   // Otherwise, use the CanonicalCookie::Domain attribute.
    727   bool group_by_cookie_source_;
    728 
    729   // If this is non-zero, then this model is batching updates (there's a lot of
    730   // notifications coming down the pipe). This is an integer is used to balance
    731   // calls to Begin/EndBatch() if they're called in a nested manner.
    732   int batch_update_;
    733 };
    734 
    735 #endif  // CHROME_BROWSER_BROWSING_DATA_COOKIES_TREE_MODEL_H_
    736