| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_BROWSING_DATA_FILE_SYSTEM_HELPER_H_ | 5 #ifndef CHROME_BROWSER_BROWSING_DATA_FILE_SYSTEM_HELPER_H_ |
| 6 #define CHROME_BROWSER_BROWSING_DATA_FILE_SYSTEM_HELPER_H_ | 6 #define CHROME_BROWSER_BROWSING_DATA_FILE_SYSTEM_HELPER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/callback_old.h" | 12 #include "base/callback_old.h" |
| 13 #include "base/file_path.h" | 13 #include "base/file_path.h" |
| 14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/synchronization/lock.h" | 16 #include "base/synchronization/lock.h" |
| 17 #include "base/time.h" | 17 #include "base/time.h" |
| 18 #include "chrome/common/url_constants.h" | 18 #include "chrome/common/url_constants.h" |
| 19 #include "googleurl/src/gurl.h" | 19 #include "googleurl/src/gurl.h" |
| 20 #include "webkit/fileapi/file_system_types.h" | 20 #include "webkit/fileapi/file_system_types.h" |
| 21 | 21 |
| 22 class Profile; | 22 class Profile; |
| 23 | 23 |
| 24 // BrowsingDataFileSystemHelper is an interface for classes dealing with | 24 // Defines an interface for classes that deal with aggregating and deleting |
| 25 // aggregating and deleting browsing data stored in local filesystems. A | 25 // browsing data stored in an origin's file systems. Clients of this interface |
| 26 // client of this class needs to call StartFetching from the UI thread to | 26 // must call StartFetching from the UI thread to initiate the flow, and will |
| 27 // initiate the flow, and it'll be notified by the callback in its UI thread at | 27 // be notified via a callback at some later point (also in the UI thread). If |
| 28 // some later point. The client must call CancelNotification() if it's | 28 // the client is destroyed before the callback is triggered, it must call |
| 29 // destroyed before the callback is notified. | 29 // CancelNotification. |
| 30 class BrowsingDataFileSystemHelper | 30 class BrowsingDataFileSystemHelper |
| 31 : public base::RefCountedThreadSafe<BrowsingDataFileSystemHelper> { | 31 : public base::RefCountedThreadSafe<BrowsingDataFileSystemHelper> { |
| 32 public: | 32 public: |
| 33 // Contains detailed information about a filesystem | 33 // Detailed information about a file system, including it's origin GURL, |
| 34 // the presence or absence of persistent and temporary storage, and the |
| 35 // amount of data (in bytes) each contains. |
| 34 struct FileSystemInfo { | 36 struct FileSystemInfo { |
| 35 FileSystemInfo( | 37 FileSystemInfo( |
| 36 const GURL& origin, | 38 const GURL& origin, |
| 37 bool has_persistent, | 39 bool has_persistent, |
| 38 bool has_temporary, | 40 bool has_temporary, |
| 39 int64 usage_persistent, | 41 int64 usage_persistent, |
| 40 int64 usage_temporary); | 42 int64 usage_temporary); |
| 41 ~FileSystemInfo(); | 43 ~FileSystemInfo(); |
| 42 | 44 |
| 43 bool IsFileSchemeData() { | |
| 44 return origin.scheme() == chrome::kFileScheme; | |
| 45 } | |
| 46 | |
| 47 GURL origin; | 45 GURL origin; |
| 48 bool has_persistent; | 46 bool has_persistent; |
| 49 bool has_temporary; | 47 bool has_temporary; |
| 50 int64 usage_persistent; | 48 int64 usage_persistent; |
| 51 int64 usage_temporary; | 49 int64 usage_temporary; |
| 52 }; | 50 }; |
| 53 | 51 |
| 54 // Create a BrowsingDataFileSystemHelper instance for the filesystems | 52 // Create a BrowsingDataFileSystemHelper instance for the file systems |
| 55 // stored in |profile|'s user data directory. | 53 // stored in |profile|'s user data directory. |
| 56 static BrowsingDataFileSystemHelper* Create(Profile* profile); | 54 static BrowsingDataFileSystemHelper* Create(Profile* profile); |
| 57 | 55 |
| 58 // Starts the fetching process, which will notify its completion via | 56 // Starts the process of fetching file system data, which will call |callback| |
| 59 // callback. | 57 // upon completion, passing it a constant vector of FileSystemInfo objects. |
| 60 // This must be called only in the UI thread. | 58 // This must be called only in the UI thread. |
| 61 virtual void StartFetching( | 59 virtual void StartFetching( |
| 62 Callback1<const std::vector<FileSystemInfo>& >::Type* callback) = 0; | 60 Callback1<const std::vector<FileSystemInfo>& >::Type* callback) = 0; |
| 63 // Cancels the notification callback (i.e., the window that created it no | 61 |
| 64 // longer exists). | 62 // Cancels the notification callback associated with StartFetching. Clients |
| 65 // This must be called only in the UI thread. | 63 // that are destroyed before the callback is triggered must call this, and |
| 64 // it must be called only on the UI thread. |
| 66 virtual void CancelNotification() = 0; | 65 virtual void CancelNotification() = 0; |
| 67 // Requests a single filesystem to be deleted in the FILE thread. | 66 |
| 67 // Deletes all file systems associated with |origin|. The deletion will occur |
| 68 // on the FILE thread, but this function must be called only on the UI thread. |
| 68 virtual void DeleteFileSystemOrigin(const GURL& origin) = 0; | 69 virtual void DeleteFileSystemOrigin(const GURL& origin) = 0; |
| 69 | 70 |
| 70 protected: | 71 protected: |
| 71 friend class base::RefCountedThreadSafe<BrowsingDataFileSystemHelper>; | 72 friend class base::RefCountedThreadSafe<BrowsingDataFileSystemHelper>; |
| 72 virtual ~BrowsingDataFileSystemHelper() {} | 73 virtual ~BrowsingDataFileSystemHelper() {} |
| 73 }; | 74 }; |
| 74 | 75 |
| 75 // This class is an implementation of BrowsingDataFileSystemHelper that does | 76 // An implementation of the BrowsingDataFileSystemHelper interface that can |
| 76 // not fetch its information from the filesystem tracker, but gets it passed | 77 // be manually populated with data, rather than fetching data from the file |
| 77 // in as a parameter. | 78 // systems created in a particular Profile. |
| 78 class CannedBrowsingDataFileSystemHelper | 79 class CannedBrowsingDataFileSystemHelper |
| 79 : public BrowsingDataFileSystemHelper { | 80 : public BrowsingDataFileSystemHelper { |
| 80 public: | 81 public: |
| 82 // |profile| is unused in this canned implementation, but it's the interface |
| 83 // we're writing to, so we'll accept it, but not store it. |
| 81 explicit CannedBrowsingDataFileSystemHelper(Profile* profile); | 84 explicit CannedBrowsingDataFileSystemHelper(Profile* profile); |
| 82 | 85 |
| 83 // Return a copy of the filesystem helper. Only one consumer can use the | 86 // Creates a copy of the file system helper. StartFetching can only respond |
| 84 // StartFetching method at a time, so we need to create a copy of the helper | 87 // to one client at a time; we need to be able to act on multiple parallel |
| 85 // everytime we instantiate a cookies tree model for it. | 88 // requests in certain situations (see CookiesTreeModel and its clients). For |
| 89 // these cases, simply clone the object and fire off another fetching process. |
| 86 CannedBrowsingDataFileSystemHelper* Clone(); | 90 CannedBrowsingDataFileSystemHelper* Clone(); |
| 87 | 91 |
| 88 // Add a filesystem to the set of canned filesystems that is | 92 // Manually add a filesystem to the set of canned file systems that this |
| 89 // returned by this helper. | 93 // helper returns via StartFetching. If an origin contains both a temporary |
| 94 // and a persistent filesystem, AddFileSystem must be called twice (once for |
| 95 // each file system type). |
| 90 void AddFileSystem(const GURL& origin, | 96 void AddFileSystem(const GURL& origin, |
| 91 fileapi::FileSystemType type, | 97 fileapi::FileSystemType type, |
| 92 int64 size); | 98 int64 size); |
| 93 | 99 |
| 94 // Clear the list of canned filesystems. | 100 // Clear this helper's list of canned filesystems. |
| 95 void Reset(); | 101 void Reset(); |
| 96 | 102 |
| 97 // True if no filesystems are currently stored. | 103 // True if no filesystems are currently stored. |
| 98 bool empty() const; | 104 bool empty() const; |
| 99 | 105 |
| 100 // BrowsingDataFileSystemHelper methods. | 106 // BrowsingDataFileSystemHelper methods. |
| 101 virtual void StartFetching( | 107 virtual void StartFetching( |
| 102 Callback1<const std::vector<FileSystemInfo>& >::Type* callback); | 108 Callback1<const std::vector<FileSystemInfo>& >::Type* callback); |
| 103 virtual void CancelNotification(); | 109 virtual void CancelNotification(); |
| 104 virtual void DeleteFileSystemOrigin(const GURL& origin) {} | 110 virtual void DeleteFileSystemOrigin(const GURL& origin) {} |
| 105 | 111 |
| 106 private: | 112 private: |
| 113 // Used by Clone() to create an object without a Profile |
| 114 CannedBrowsingDataFileSystemHelper(); |
| 115 virtual ~CannedBrowsingDataFileSystemHelper(); |
| 116 |
| 117 // AddFileSystem doesn't store file systems directly, but holds them until |
| 118 // StartFetching is called. At that point, the pending file system data is |
| 119 // merged with the current file system data before being returned to the |
| 120 // client. |
| 107 struct PendingFileSystemInfo { | 121 struct PendingFileSystemInfo { |
| 108 PendingFileSystemInfo(); | 122 PendingFileSystemInfo(); |
| 109 PendingFileSystemInfo(const GURL& origin, | 123 PendingFileSystemInfo(const GURL& origin, |
| 110 fileapi::FileSystemType type, | 124 fileapi::FileSystemType type, |
| 111 int64 size); | 125 int64 size); |
| 112 ~PendingFileSystemInfo(); | 126 ~PendingFileSystemInfo(); |
| 113 | 127 |
| 114 GURL origin; | 128 GURL origin; |
| 115 fileapi::FileSystemType type; | 129 fileapi::FileSystemType type; |
| 116 int64 size; | 130 int64 size; |
| 117 }; | 131 }; |
| 118 | 132 |
| 119 // StartFetching's callback should be executed asynchronously, Notify handles | 133 // Triggers the success callback as the end of a StartFetching workflow. This |
| 120 // that nicely. | 134 // must be called on the UI thread. |
| 121 void Notify(); | 135 void NotifyOnUIThread(); |
| 122 | 136 |
| 123 virtual ~CannedBrowsingDataFileSystemHelper(); | 137 // Holds file systems that have been added to the helper until StartFetching |
| 124 | 138 // is called. |
| 125 Profile* profile_; | |
| 126 | |
| 127 std::vector<PendingFileSystemInfo> pending_file_system_info_; | 139 std::vector<PendingFileSystemInfo> pending_file_system_info_; |
| 128 | 140 |
| 141 // Holds the current list of file systems returned to the client after |
| 142 // StartFetching is called. |
| 129 std::vector<FileSystemInfo> file_system_info_; | 143 std::vector<FileSystemInfo> file_system_info_; |
| 130 | 144 |
| 145 // Holds the callback passed in at the beginning of the StartFetching workflow |
| 146 // so that it can be triggered via NotifyOnUIThread. |
| 131 scoped_ptr<Callback1<const std::vector<FileSystemInfo>& >::Type > | 147 scoped_ptr<Callback1<const std::vector<FileSystemInfo>& >::Type > |
| 132 completion_callback_; | 148 completion_callback_; |
| 133 | 149 |
| 134 // Indicates whether or not we're currently fetching information: | 150 // Indicates whether or not we're currently fetching information: set to true |
| 135 // it's true when StartFetching() is called in the UI thread, and it's reset | 151 // when StartFetching is called on the UI thread, and reset to false when |
| 136 // after we notified the callback in the UI thread. | 152 // NotifyOnUIThread triggers the success callback. |
| 137 // This only mutates on the UI thread. | 153 // This property only mutates on the UI thread. |
| 138 bool is_fetching_; | 154 bool is_fetching_; |
| 139 | 155 |
| 140 DISALLOW_COPY_AND_ASSIGN(CannedBrowsingDataFileSystemHelper); | 156 DISALLOW_COPY_AND_ASSIGN(CannedBrowsingDataFileSystemHelper); |
| 141 }; | 157 }; |
| 142 | 158 |
| 143 #endif // CHROME_BROWSER_BROWSING_DATA_FILE_SYSTEM_HELPER_H_ | 159 #endif // CHROME_BROWSER_BROWSING_DATA_FILE_SYSTEM_HELPER_H_ |
| OLD | NEW |