browsing_data_indexed_db_helper.h revision 3345a6884c488ff3a535c2c9acdd33d74b37e311
1// Copyright (c) 2010 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_INDEXED_DB_HELPER_H_ 6#define CHROME_BROWSER_BROWSING_DATA_INDEXED_DB_HELPER_H_ 7#pragma once 8 9#include <string> 10#include <vector> 11 12#include "base/callback.h" 13#include "base/file_path.h" 14#include "base/ref_counted.h" 15#include "base/time.h" 16#include "chrome/common/url_constants.h" 17#include "googleurl/src/gurl.h" 18 19class Profile; 20 21// BrowsingDataIndexedDBHelper is an interface for classes dealing with 22// aggregating and deleting browsing data stored in indexed databases. A 23// client of this class need to call StartFetching from the UI thread to 24// initiate the flow, and it'll be notified by the callback in its UI thread at 25// some later point. The client must call CancelNotification() if it's 26// destroyed before the callback is notified. 27class BrowsingDataIndexedDBHelper 28 : public base::RefCountedThreadSafe<BrowsingDataIndexedDBHelper> { 29 public: 30 // Contains detailed information about an indexed database. 31 struct IndexedDBInfo { 32 IndexedDBInfo( 33 const std::string& protocol, 34 const std::string& host, 35 unsigned short port, 36 const std::string& database_identifier, 37 const std::string& origin, 38 const std::string& database_name, 39 const FilePath& file_path, 40 int64 size, 41 base::Time last_modified) 42 : protocol(protocol), 43 host(host), 44 port(port), 45 database_identifier(database_identifier), 46 origin(origin), 47 database_name(database_name), 48 file_path(file_path), 49 size(size), 50 last_modified(last_modified) { 51 } 52 53 bool IsFileSchemeData() { 54 return protocol == chrome::kFileScheme; 55 } 56 57 std::string protocol; 58 std::string host; 59 unsigned short port; 60 std::string database_identifier; 61 std::string origin; 62 std::string database_name; 63 FilePath file_path; 64 int64 size; 65 base::Time last_modified; 66 }; 67 68 // Create a BrowsingDataIndexedDBHelper instance for the indexed databases 69 // stored in |profile|'s user data directory. 70 static BrowsingDataIndexedDBHelper* Create(Profile* profile); 71 72 // Starts the fetching process, which will notify its completion via 73 // callback. 74 // This must be called only in the UI thread. 75 virtual void StartFetching( 76 Callback1<const std::vector<IndexedDBInfo>& >::Type* callback) = 0; 77 // Cancels the notification callback (i.e., the window that created it no 78 // longer exists). 79 // This must be called only in the UI thread. 80 virtual void CancelNotification() = 0; 81 // Requests a single indexed database file to be deleted in the WEBKIT thread. 82 virtual void DeleteIndexedDBFile(const FilePath& file_path) = 0; 83 84 protected: 85 friend class base::RefCountedThreadSafe<BrowsingDataIndexedDBHelper>; 86 virtual ~BrowsingDataIndexedDBHelper() {} 87}; 88 89// This class is an implementation of BrowsingDataIndexedDBHelper that does 90// not fetch its information from the indexed database tracker, but gets them 91// passed as a parameter. 92class CannedBrowsingDataIndexedDBHelper 93 : public BrowsingDataIndexedDBHelper { 94 public: 95 explicit CannedBrowsingDataIndexedDBHelper(Profile* profile); 96 97 // Add a indexed database to the set of canned indexed databases that is 98 // returned by this helper. 99 void AddIndexedDB(const GURL& origin, 100 const string16& name, 101 const string16& description); 102 103 // Clear the list of canned indexed databases. 104 void Reset(); 105 106 // True if no indexed databases are currently stored. 107 bool empty() const; 108 109 // BrowsingDataIndexedDBHelper methods. 110 virtual void StartFetching( 111 Callback1<const std::vector<IndexedDBInfo>& >::Type* callback); 112 virtual void CancelNotification() {} 113 virtual void DeleteIndexedDBFile(const FilePath& file_path) {} 114 115 private: 116 virtual ~CannedBrowsingDataIndexedDBHelper() {} 117 118 Profile* profile_; 119 120 std::vector<IndexedDBInfo> indexed_db_info_; 121 122 DISALLOW_COPY_AND_ASSIGN(CannedBrowsingDataIndexedDBHelper); 123}; 124 125#endif // CHROME_BROWSER_BROWSING_DATA_INDEXED_DB_HELPER_H_ 126