Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011 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_FILESYSTEM_HELPER_H_ | |
| 6 #define CHROME_BROWSER_BROWSING_DATA_FILESYSTEM_HELPER_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include <string> | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "base/callback_old.h" | |
| 13 #include "base/file_path.h" | |
| 14 #include "base/memory/ref_counted.h" | |
| 15 #include "base/memory/scoped_ptr.h" | |
| 16 #include "base/synchronization/lock.h" | |
| 17 #include "base/time.h" | |
| 18 #include "chrome/common/url_constants.h" | |
| 19 #include "googleurl/src/gurl.h" | |
| 20 #include "webkit/fileapi/file_system_types.h" | |
| 21 | |
| 22 class Profile; | |
| 23 | |
| 24 // BrowsingDataFilesystemHelper is an interface for classes dealing with | |
| 25 // aggregating and deleting browsing data stored in local filesystems. A | |
| 26 // client of this class need to call StartFetching from the UI thread to | |
|
ericu
2011/05/24 23:08:15
typo: needs
Mike West
2011/05/25 09:22:36
Done.
| |
| 27 // initiate the flow, and it'll be notified by the callback in its UI thread at | |
| 28 // some later point. The client must call CancelNotification() if it's | |
| 29 // destroyed before the callback is notified. | |
| 30 class BrowsingDataFilesystemHelper | |
| 31 : public base::RefCountedThreadSafe<BrowsingDataFilesystemHelper> { | |
| 32 public: | |
| 33 // Contains detailed information about a filesystem | |
| 34 struct FilesystemInfo { | |
| 35 FilesystemInfo( | |
| 36 const std::string& protocol, | |
| 37 const std::string& host, | |
| 38 const std::string& port, | |
| 39 const GURL& origin, | |
| 40 bool has_persistent, | |
| 41 bool has_temporary); | |
| 42 ~FilesystemInfo(); | |
| 43 | |
| 44 bool IsFileSchemeData() { | |
| 45 return protocol == chrome::kFileScheme; | |
| 46 } | |
| 47 | |
| 48 std::string protocol; | |
| 49 std::string host; | |
| 50 std::string port; | |
| 51 GURL origin; | |
| 52 bool has_persistent; | |
| 53 bool has_temporary; | |
| 54 base::Time last_modified; | |
| 55 }; | |
| 56 | |
| 57 // Create a BrowsingDataFilesystemHelper instance for the filesystems | |
| 58 // stored in |profile|'s user data directory. | |
| 59 static BrowsingDataFilesystemHelper* Create(Profile* profile); | |
| 60 | |
| 61 // Starts the fetching process, which will notify its completion via | |
| 62 // callback. | |
| 63 // This must be called only in the UI thread. | |
| 64 virtual void StartFetching( | |
| 65 Callback1<const std::vector<FilesystemInfo>& >::Type* callback) = 0; | |
| 66 // Cancels the notification callback (i.e., the window that created it no | |
| 67 // longer exists). | |
| 68 // This must be called only in the UI thread. | |
| 69 virtual void CancelNotification() = 0; | |
| 70 // Requests a single filesystem to be deleted in the FILE thread. | |
| 71 virtual void DeleteFilesystemOrigin(const GURL& origin) = 0; | |
| 72 | |
| 73 virtual ~BrowsingDataFilesystemHelper() {} | |
| 74 protected: | |
| 75 friend class base::RefCountedThreadSafe<BrowsingDataFilesystemHelper>; | |
| 76 }; | |
| 77 | |
| 78 // This class is an implementation of BrowsingDataFilesystemHelper that does | |
| 79 // not fetch its information from the filesystem tracker, but gets them | |
|
ericu
2011/05/24 23:08:15
s/them/it/
Mike West
2011/05/25 09:22:36
Done.
| |
| 80 // passed as a parameter. | |
| 81 class CannedBrowsingDataFilesystemHelper | |
| 82 : public BrowsingDataFilesystemHelper { | |
| 83 public: | |
| 84 explicit CannedBrowsingDataFilesystemHelper(Profile* profile); | |
| 85 | |
| 86 // Return a copy of the filesystem helper. Only one consumer can use the | |
| 87 // StartFetching method at a time, so we need to create a copy of the helper | |
| 88 // everytime we instantiate a cookies tree model for it. | |
| 89 CannedBrowsingDataFilesystemHelper* Clone(); | |
| 90 | |
| 91 // Add a filesystem to the set of canned filesystems that is | |
| 92 // returned by this helper. | |
| 93 void AddFilesystem(const GURL& origin, | |
| 94 fileapi::FileSystemType type); | |
| 95 | |
| 96 // Clear the list of canned filesystems. | |
| 97 void Reset(); | |
| 98 | |
| 99 // True if no filesystems are currently stored. | |
| 100 bool empty() const; | |
| 101 | |
| 102 // BrowsingDataFilesystemHelper methods. | |
| 103 virtual void StartFetching( | |
| 104 Callback1<const std::vector<FilesystemInfo>& >::Type* callback); | |
| 105 virtual void CancelNotification() {} | |
| 106 virtual void DeleteFilesystemOrigin(const GURL& origin) {} | |
| 107 | |
| 108 private: | |
| 109 struct PendingFilesystemInfo { | |
| 110 PendingFilesystemInfo(); | |
| 111 PendingFilesystemInfo(const GURL& origin, fileapi::FileSystemType type); | |
| 112 ~PendingFilesystemInfo(); | |
| 113 | |
| 114 GURL origin; | |
| 115 fileapi::FileSystemType type; | |
| 116 }; | |
| 117 | |
| 118 virtual ~CannedBrowsingDataFilesystemHelper(); | |
| 119 | |
| 120 // Convert the pending filesystem info to filesystem info objects. | |
| 121 void ConvertPendingInfoInWebKitThread(); | |
| 122 | |
| 123 void NotifyInUIThread(); | |
| 124 | |
| 125 Profile* profile_; | |
| 126 | |
| 127 // Lock to protect access to pending_filesystem_info_; | |
| 128 mutable base::Lock lock_; | |
| 129 | |
| 130 // This may mutate on WEBKIT and UI threads. | |
| 131 std::vector<PendingFilesystemInfo> pending_filesystem_info_; | |
| 132 | |
| 133 // This only mutates on the WEBKIT thread. | |
| 134 std::vector<FilesystemInfo> filesystem_info_; | |
| 135 | |
| 136 // This only mutates on the UI thread. | |
| 137 scoped_ptr<Callback1<const std::vector<FilesystemInfo>& >::Type > | |
| 138 completion_callback_; | |
| 139 | |
| 140 // Indicates whether or not we're currently fetching information: | |
| 141 // it's true when StartFetching() is called in the UI thread, and it's reset | |
| 142 // after we notified the callback in the UI thread. | |
| 143 // This only mutates on the UI thread. | |
| 144 bool is_fetching_; | |
| 145 | |
| 146 DISALLOW_COPY_AND_ASSIGN(CannedBrowsingDataFilesystemHelper); | |
| 147 }; | |
| 148 | |
| 149 #endif // CHROME_BROWSER_BROWSING_DATA_FILESYSTEM_HELPER_H_ | |
| OLD | NEW |