| 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 <list> |
| 9 #include <string> | 10 #include <string> |
| 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 // Defines an interface for classes that deal with aggregating and deleting | 24 // Defines an interface for classes that deal with aggregating and deleting |
| 25 // browsing data stored in an origin's file systems. | 25 // browsing data stored in an origin's file systems. |
| 26 // BrowsingDataFileSystemHelper instances for a specific profile should be | 26 // BrowsingDataFileSystemHelper instances for a specific profile should be |
| 27 // created via the static Create method. Each instance will lazily fetch file | 27 // created via the static Create method. Each instance will lazily fetch file |
| 28 // system data when a client calls StartFetching from the UI thread, and will | 28 // system data when a client calls StartFetching from the UI thread, and will |
| 29 // notify the client via a supplied callback when the data is available. | 29 // notify the client via a supplied callback when the data is available. |
| 30 // Only one StartFetching task can run at a time: executing StartFetching while | 30 // Only one StartFetching task can run at a time: executing StartFetching while |
| 31 // another StartFetching task is running will DCHECK. If the client must abort | 31 // another StartFetching task is running will DCHECK. If the client must abort |
| 32 // the process before completion (it's destroyed, for example) then it must call | 32 // the process before completion (it's destroyed, for example) then it must call |
| 33 // CancelNotification. | 33 // CancelNotification. |
| 34 // | 34 // |
| 35 // The client's callback is passed a vector of FileSystemInfo objects containing | 35 // The client's callback is passed a list of FileSystemInfo objects containing |
| 36 // usage information for each origin's temporary and persistent file systems. | 36 // usage information for each origin's temporary and persistent file systems. |
| 37 // | 37 // |
| 38 // Clients may remove an origin's file systems at any time (even before fetching | 38 // Clients may remove an origin's file systems at any time (even before fetching |
| 39 // data) by calling DeleteFileSystemOrigin() on the UI thread. Calling | 39 // data) by calling DeleteFileSystemOrigin() on the UI thread. Calling |
| 40 // DeleteFileSystemOrigin() for an origin that doesn't have any is safe; it's | 40 // DeleteFileSystemOrigin() for an origin that doesn't have any is safe; it's |
| 41 // just an expensive NOOP. | 41 // just an expensive NOOP. |
| 42 class BrowsingDataFileSystemHelper | 42 class BrowsingDataFileSystemHelper |
| 43 : public base::RefCountedThreadSafe<BrowsingDataFileSystemHelper> { | 43 : public base::RefCountedThreadSafe<BrowsingDataFileSystemHelper> { |
| 44 public: | 44 public: |
| 45 // Detailed information about a file system, including it's origin GURL, | 45 // Detailed information about a file system, including it's origin GURL, |
| (...skipping 23 matching lines...) Expand all Loading... |
| 69 // Creates a BrowsingDataFileSystemHelper instance for the file systems | 69 // Creates a BrowsingDataFileSystemHelper instance for the file systems |
| 70 // stored in |profile|'s user data directory. The BrowsingDataFileSystemHelper | 70 // stored in |profile|'s user data directory. The BrowsingDataFileSystemHelper |
| 71 // object will hold a reference to the Profile that's passed in, but is not | 71 // object will hold a reference to the Profile that's passed in, but is not |
| 72 // responsible for destroying it. | 72 // responsible for destroying it. |
| 73 // | 73 // |
| 74 // The BrowsingDataFileSystemHelper will not change the profile itself, but | 74 // The BrowsingDataFileSystemHelper will not change the profile itself, but |
| 75 // can modify data it contains (by removing file systems). | 75 // can modify data it contains (by removing file systems). |
| 76 static BrowsingDataFileSystemHelper* Create(Profile* profile); | 76 static BrowsingDataFileSystemHelper* Create(Profile* profile); |
| 77 | 77 |
| 78 // Starts the process of fetching file system data, which will call |callback| | 78 // Starts the process of fetching file system data, which will call |callback| |
| 79 // upon completion, passing it a constant vector of FileSystemInfo objects. | 79 // upon completion, passing it a constant list of FileSystemInfo objects. |
| 80 // StartFetching must be called only in the UI thread; the provided Callback1 | 80 // StartFetching must be called only in the UI thread; the provided Callback1 |
| 81 // will likewise be executed asynchronously on the UI thread. | 81 // will likewise be executed asynchronously on the UI thread. |
| 82 // | 82 // |
| 83 // BrowsingDataFileSystemHelper takes ownership of the Callback1, and is | 83 // BrowsingDataFileSystemHelper takes ownership of the Callback1, and is |
| 84 // responsible for deleting it once it's no longer needed. | 84 // responsible for deleting it once it's no longer needed. |
| 85 virtual void StartFetching( | 85 virtual void StartFetching( |
| 86 Callback1<const std::vector<FileSystemInfo>& >::Type* callback) = 0; | 86 Callback1<const std::list<FileSystemInfo>& >::Type* callback) = 0; |
| 87 | 87 |
| 88 // Cancels the notification callback associated with StartFetching. Clients | 88 // Cancels the notification callback associated with StartFetching. Clients |
| 89 // that are destroyed before the callback is triggered must call this, and | 89 // that are destroyed before the callback is triggered must call this, and |
| 90 // it must be called only on the UI thread. | 90 // it must be called only on the UI thread. |
| 91 virtual void CancelNotification() = 0; | 91 virtual void CancelNotification() = 0; |
| 92 | 92 |
| 93 // Deletes any temporary or persistent file systems associated with |origin| | 93 // Deletes any temporary or persistent file systems associated with |origin| |
| 94 // from the disk. Deletion will occur asynchronously on the FILE thread, but | 94 // from the disk. Deletion will occur asynchronously on the FILE thread, but |
| 95 // this function must be called only on the UI thread. | 95 // this function must be called only on the UI thread. |
| 96 virtual void DeleteFileSystemOrigin(const GURL& origin) = 0; | 96 virtual void DeleteFileSystemOrigin(const GURL& origin) = 0; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 int64 size); | 131 int64 size); |
| 132 | 132 |
| 133 // Clear this helper's list of canned filesystems. | 133 // Clear this helper's list of canned filesystems. |
| 134 void Reset(); | 134 void Reset(); |
| 135 | 135 |
| 136 // True if no filesystems are currently stored. | 136 // True if no filesystems are currently stored. |
| 137 bool empty() const; | 137 bool empty() const; |
| 138 | 138 |
| 139 // BrowsingDataFileSystemHelper methods. | 139 // BrowsingDataFileSystemHelper methods. |
| 140 virtual void StartFetching( | 140 virtual void StartFetching( |
| 141 Callback1<const std::vector<FileSystemInfo>& >::Type* callback); | 141 Callback1<const std::list<FileSystemInfo>& >::Type* callback); |
| 142 virtual void CancelNotification(); | 142 virtual void CancelNotification(); |
| 143 | 143 |
| 144 // Note that this doesn't actually have an implementation for this canned | 144 // Note that this doesn't actually have an implementation for this canned |
| 145 // class. It hasn't been necessary for anything that uses the canned | 145 // class. It hasn't been necessary for anything that uses the canned |
| 146 // implementation, as the canned class is only used in tests, or in read-only | 146 // implementation, as the canned class is only used in tests, or in read-only |
| 147 // contexts (like the non-modal cookie dialog). | 147 // contexts (like the non-modal cookie dialog). |
| 148 virtual void DeleteFileSystemOrigin(const GURL& origin) {} | 148 virtual void DeleteFileSystemOrigin(const GURL& origin) {} |
| 149 | 149 |
| 150 private: | 150 private: |
| 151 // Used by Clone() to create an object without a Profile | 151 // Used by Clone() to create an object without a Profile |
| 152 CannedBrowsingDataFileSystemHelper(); | 152 CannedBrowsingDataFileSystemHelper(); |
| 153 virtual ~CannedBrowsingDataFileSystemHelper(); | 153 virtual ~CannedBrowsingDataFileSystemHelper(); |
| 154 | 154 |
| 155 // Triggers the success callback as the end of a StartFetching workflow. This | 155 // Triggers the success callback as the end of a StartFetching workflow. This |
| 156 // must be called on the UI thread. | 156 // must be called on the UI thread. |
| 157 void NotifyOnUIThread(); | 157 void NotifyOnUIThread(); |
| 158 | 158 |
| 159 // Holds the current list of file systems returned to the client after | 159 // Holds the current list of file systems returned to the client after |
| 160 // StartFetching is called. | 160 // StartFetching is called. |
| 161 std::vector<FileSystemInfo> file_system_info_; | 161 std::list<FileSystemInfo> file_system_info_; |
| 162 | 162 |
| 163 // Holds the callback passed in at the beginning of the StartFetching workflow | 163 // Holds the callback passed in at the beginning of the StartFetching workflow |
| 164 // so that it can be triggered via NotifyOnUIThread. | 164 // so that it can be triggered via NotifyOnUIThread. |
| 165 scoped_ptr<Callback1<const std::vector<FileSystemInfo>& >::Type > | 165 scoped_ptr<Callback1<const std::list<FileSystemInfo>& >::Type > |
| 166 completion_callback_; | 166 completion_callback_; |
| 167 | 167 |
| 168 // Indicates whether or not we're currently fetching information: set to true | 168 // Indicates whether or not we're currently fetching information: set to true |
| 169 // when StartFetching is called on the UI thread, and reset to false when | 169 // when StartFetching is called on the UI thread, and reset to false when |
| 170 // NotifyOnUIThread triggers the success callback. | 170 // NotifyOnUIThread triggers the success callback. |
| 171 // This property only mutates on the UI thread. | 171 // This property only mutates on the UI thread. |
| 172 bool is_fetching_; | 172 bool is_fetching_; |
| 173 | 173 |
| 174 DISALLOW_COPY_AND_ASSIGN(CannedBrowsingDataFileSystemHelper); | 174 DISALLOW_COPY_AND_ASSIGN(CannedBrowsingDataFileSystemHelper); |
| 175 }; | 175 }; |
| 176 | 176 |
| 177 #endif // CHROME_BROWSER_BROWSING_DATA_FILE_SYSTEM_HELPER_H_ | 177 #endif // CHROME_BROWSER_BROWSING_DATA_FILE_SYSTEM_HELPER_H_ |
| OLD | NEW |