Chromium Code Reviews| Index: chrome/browser/browsing_data_filesystem_helper.h |
| diff --git a/chrome/browser/browsing_data_filesystem_helper.h b/chrome/browser/browsing_data_filesystem_helper.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..dab404e757e528443255d46d2e5e29b31b0fc791 |
| --- /dev/null |
| +++ b/chrome/browser/browsing_data_filesystem_helper.h |
| @@ -0,0 +1,149 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_BROWSER_BROWSING_DATA_FILESYSTEM_HELPER_H_ |
| +#define CHROME_BROWSER_BROWSING_DATA_FILESYSTEM_HELPER_H_ |
| +#pragma once |
| + |
| +#include <string> |
| +#include <vector> |
| + |
| +#include "base/callback_old.h" |
| +#include "base/file_path.h" |
| +#include "base/memory/ref_counted.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/synchronization/lock.h" |
| +#include "base/time.h" |
| +#include "chrome/common/url_constants.h" |
| +#include "googleurl/src/gurl.h" |
| +#include "webkit/fileapi/file_system_types.h" |
| + |
| +class Profile; |
| + |
| +// BrowsingDataFilesystemHelper is an interface for classes dealing with |
| +// aggregating and deleting browsing data stored in local filesystems. A |
| +// 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.
|
| +// initiate the flow, and it'll be notified by the callback in its UI thread at |
| +// some later point. The client must call CancelNotification() if it's |
| +// destroyed before the callback is notified. |
| +class BrowsingDataFilesystemHelper |
| + : public base::RefCountedThreadSafe<BrowsingDataFilesystemHelper> { |
| + public: |
| + // Contains detailed information about a filesystem |
| + struct FilesystemInfo { |
| + FilesystemInfo( |
| + const std::string& protocol, |
| + const std::string& host, |
| + const std::string& port, |
| + const GURL& origin, |
| + bool has_persistent, |
| + bool has_temporary); |
| + ~FilesystemInfo(); |
| + |
| + bool IsFileSchemeData() { |
| + return protocol == chrome::kFileScheme; |
| + } |
| + |
| + std::string protocol; |
| + std::string host; |
| + std::string port; |
| + GURL origin; |
| + bool has_persistent; |
| + bool has_temporary; |
| + base::Time last_modified; |
| + }; |
| + |
| + // Create a BrowsingDataFilesystemHelper instance for the filesystems |
| + // stored in |profile|'s user data directory. |
| + static BrowsingDataFilesystemHelper* Create(Profile* profile); |
| + |
| + // Starts the fetching process, which will notify its completion via |
| + // callback. |
| + // This must be called only in the UI thread. |
| + virtual void StartFetching( |
| + Callback1<const std::vector<FilesystemInfo>& >::Type* callback) = 0; |
| + // Cancels the notification callback (i.e., the window that created it no |
| + // longer exists). |
| + // This must be called only in the UI thread. |
| + virtual void CancelNotification() = 0; |
| + // Requests a single filesystem to be deleted in the FILE thread. |
| + virtual void DeleteFilesystemOrigin(const GURL& origin) = 0; |
| + |
| + virtual ~BrowsingDataFilesystemHelper() {} |
| + protected: |
| + friend class base::RefCountedThreadSafe<BrowsingDataFilesystemHelper>; |
| +}; |
| + |
| +// This class is an implementation of BrowsingDataFilesystemHelper that does |
| +// 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.
|
| +// passed as a parameter. |
| +class CannedBrowsingDataFilesystemHelper |
| + : public BrowsingDataFilesystemHelper { |
| + public: |
| + explicit CannedBrowsingDataFilesystemHelper(Profile* profile); |
| + |
| + // Return a copy of the filesystem helper. Only one consumer can use the |
| + // StartFetching method at a time, so we need to create a copy of the helper |
| + // everytime we instantiate a cookies tree model for it. |
| + CannedBrowsingDataFilesystemHelper* Clone(); |
| + |
| + // Add a filesystem to the set of canned filesystems that is |
| + // returned by this helper. |
| + void AddFilesystem(const GURL& origin, |
| + fileapi::FileSystemType type); |
| + |
| + // Clear the list of canned filesystems. |
| + void Reset(); |
| + |
| + // True if no filesystems are currently stored. |
| + bool empty() const; |
| + |
| + // BrowsingDataFilesystemHelper methods. |
| + virtual void StartFetching( |
| + Callback1<const std::vector<FilesystemInfo>& >::Type* callback); |
| + virtual void CancelNotification() {} |
| + virtual void DeleteFilesystemOrigin(const GURL& origin) {} |
| + |
| + private: |
| + struct PendingFilesystemInfo { |
| + PendingFilesystemInfo(); |
| + PendingFilesystemInfo(const GURL& origin, fileapi::FileSystemType type); |
| + ~PendingFilesystemInfo(); |
| + |
| + GURL origin; |
| + fileapi::FileSystemType type; |
| + }; |
| + |
| + virtual ~CannedBrowsingDataFilesystemHelper(); |
| + |
| + // Convert the pending filesystem info to filesystem info objects. |
| + void ConvertPendingInfoInWebKitThread(); |
| + |
| + void NotifyInUIThread(); |
| + |
| + Profile* profile_; |
| + |
| + // Lock to protect access to pending_filesystem_info_; |
| + mutable base::Lock lock_; |
| + |
| + // This may mutate on WEBKIT and UI threads. |
| + std::vector<PendingFilesystemInfo> pending_filesystem_info_; |
| + |
| + // This only mutates on the WEBKIT thread. |
| + std::vector<FilesystemInfo> filesystem_info_; |
| + |
| + // This only mutates on the UI thread. |
| + scoped_ptr<Callback1<const std::vector<FilesystemInfo>& >::Type > |
| + completion_callback_; |
| + |
| + // Indicates whether or not we're currently fetching information: |
| + // it's true when StartFetching() is called in the UI thread, and it's reset |
| + // after we notified the callback in the UI thread. |
| + // This only mutates on the UI thread. |
| + bool is_fetching_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(CannedBrowsingDataFilesystemHelper); |
| +}; |
| + |
| +#endif // CHROME_BROWSER_BROWSING_DATA_FILESYSTEM_HELPER_H_ |