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