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