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_LOCAL_DATA_CONTAINER_H_
6#define CHROME_BROWSER_BROWSING_DATA_LOCAL_DATA_CONTAINER_H_
7
8#include <list>
9#include <map>
10#include <string>
11#include <vector>
12
13#include "base/memory/ref_counted.h"
14#include "base/memory/weak_ptr.h"
15#include "base/strings/string16.h"
16#include "chrome/browser/browsing_data/browsing_data_appcache_helper.h"
17#include "chrome/browser/browsing_data/browsing_data_cookie_helper.h"
18#include "chrome/browser/browsing_data/browsing_data_database_helper.h"
19#include "chrome/browser/browsing_data/browsing_data_file_system_helper.h"
20#include "chrome/browser/browsing_data/browsing_data_indexed_db_helper.h"
21#include "chrome/browser/browsing_data/browsing_data_local_storage_helper.h"
22#include "chrome/browser/browsing_data/browsing_data_quota_helper.h"
23#include "chrome/browser/browsing_data/browsing_data_server_bound_cert_helper.h"
24#include "net/ssl/server_bound_cert_store.h"
25
26class BrowsingDataFlashLSOHelper;
27class CookiesTreeModel;
28class LocalDataContainer;
29
30namespace net {
31class CanonicalCookie;
32}
33
34// Friendly typedefs for the multiple types of lists used in the model.
35namespace {
36
37typedef std::list<net::CanonicalCookie> CookieList;
38typedef std::list<BrowsingDataDatabaseHelper::DatabaseInfo> DatabaseInfoList;
39typedef std::list<BrowsingDataLocalStorageHelper::LocalStorageInfo>
40    LocalStorageInfoList;
41typedef std::list<BrowsingDataLocalStorageHelper::LocalStorageInfo>
42    SessionStorageInfoList;
43typedef std::list<content::IndexedDBInfo>
44    IndexedDBInfoList;
45typedef std::list<BrowsingDataFileSystemHelper::FileSystemInfo>
46    FileSystemInfoList;
47typedef std::list<BrowsingDataQuotaHelper::QuotaInfo> QuotaInfoList;
48typedef net::ServerBoundCertStore::ServerBoundCertList ServerBoundCertList;
49typedef std::map<GURL, std::list<appcache::AppCacheInfo> > AppCacheInfoMap;
50typedef std::vector<std::string> FlashLSODomainList;
51
52} // namespace
53
54// LocalDataContainer ---------------------------------------------------------
55// This class is a wrapper around all the BrowsingData*Helper classes. Because
56// isolated applications have separate storage, we need different helper
57// instances. As such, this class contains the app name and id, along with the
58// helpers for all of the data types we need. The browser-wide "app id" will be
59// the empty string, as no app can have an empty id.
60class LocalDataContainer {
61 public:
62  LocalDataContainer(
63      BrowsingDataCookieHelper* cookie_helper,
64      BrowsingDataDatabaseHelper* database_helper,
65      BrowsingDataLocalStorageHelper* local_storage_helper,
66      BrowsingDataLocalStorageHelper* session_storage_helper,
67      BrowsingDataAppCacheHelper* appcache_helper,
68      BrowsingDataIndexedDBHelper* indexed_db_helper,
69      BrowsingDataFileSystemHelper* file_system_helper,
70      BrowsingDataQuotaHelper* quota_helper,
71      BrowsingDataServerBoundCertHelper* server_bound_cert_helper,
72      BrowsingDataFlashLSOHelper* flash_data_helper);
73  virtual ~LocalDataContainer();
74
75  // This method must be called to start the process of fetching the resources.
76  // The delegate passed in is called back to deliver the updates.
77  void Init(CookiesTreeModel* delegate);
78
79 private:
80  friend class CookiesTreeModel;
81  friend class CookieTreeAppCacheNode;
82  friend class CookieTreeCookieNode;
83  friend class CookieTreeDatabaseNode;
84  friend class CookieTreeLocalStorageNode;
85  friend class CookieTreeSessionStorageNode;
86  friend class CookieTreeIndexedDBNode;
87  friend class CookieTreeFileSystemNode;
88  friend class CookieTreeQuotaNode;
89  friend class CookieTreeServerBoundCertNode;
90  friend class CookieTreeFlashLSONode;
91
92  // Callback methods to be invoked when fetching the data is complete.
93  void OnAppCacheModelInfoLoaded();
94  void OnCookiesModelInfoLoaded(const net::CookieList& cookie_list);
95  void OnDatabaseModelInfoLoaded(const DatabaseInfoList& database_info);
96  void OnLocalStorageModelInfoLoaded(
97      const LocalStorageInfoList& local_storage_info);
98  void OnSessionStorageModelInfoLoaded(
99      const LocalStorageInfoList& local_storage_info);
100  void OnIndexedDBModelInfoLoaded(
101      const IndexedDBInfoList& indexed_db_info);
102  void OnFileSystemModelInfoLoaded(
103      const FileSystemInfoList& file_system_info);
104  void OnQuotaModelInfoLoaded(const QuotaInfoList& quota_info);
105  void OnServerBoundCertModelInfoLoaded(const ServerBoundCertList& cert_list);
106  void OnFlashLSOInfoLoaded(const FlashLSODomainList& domains);
107
108  // Pointers to the helper objects, needed to retreive all the types of locally
109  // stored data.
110  scoped_refptr<BrowsingDataAppCacheHelper> appcache_helper_;
111  scoped_refptr<BrowsingDataCookieHelper> cookie_helper_;
112  scoped_refptr<BrowsingDataDatabaseHelper> database_helper_;
113  scoped_refptr<BrowsingDataLocalStorageHelper> local_storage_helper_;
114  scoped_refptr<BrowsingDataLocalStorageHelper> session_storage_helper_;
115  scoped_refptr<BrowsingDataIndexedDBHelper> indexed_db_helper_;
116  scoped_refptr<BrowsingDataFileSystemHelper> file_system_helper_;
117  scoped_refptr<BrowsingDataQuotaHelper> quota_helper_;
118  scoped_refptr<BrowsingDataServerBoundCertHelper> server_bound_cert_helper_;
119  scoped_refptr<BrowsingDataFlashLSOHelper> flash_lso_helper_;
120
121  // Storage for all the data that was retrieved through the helper objects.
122  // The collected data is used for (re)creating the CookiesTreeModel.
123  AppCacheInfoMap appcache_info_;
124  CookieList cookie_list_;
125  DatabaseInfoList database_info_list_;
126  LocalStorageInfoList local_storage_info_list_;
127  LocalStorageInfoList session_storage_info_list_;
128  IndexedDBInfoList indexed_db_info_list_;
129  FileSystemInfoList file_system_info_list_;
130  QuotaInfoList quota_info_list_;
131  ServerBoundCertList server_bound_cert_list_;
132  FlashLSODomainList flash_lso_domain_list_;
133
134  // A delegate, which must outlive this object. The update callbacks use the
135  // delegate to deliver the updated data to the CookieTreeModel.
136  CookiesTreeModel* model_;
137
138  base::WeakPtrFactory<LocalDataContainer> weak_ptr_factory_;
139
140  DISALLOW_COPY_AND_ASSIGN(LocalDataContainer);
141};
142
143#endif  // CHROME_BROWSER_BROWSING_DATA_LOCAL_DATA_CONTAINER_H_
144