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