Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / net / disk_cache / simple / simple_backend_impl.h
index 996cfd2..48c422f 100644 (file)
@@ -34,6 +34,11 @@ namespace disk_cache {
 // files.
 // See http://www.chromium.org/developers/design-documents/network-stack/disk-cache/very-simple-backend
 //
+// The SimpleBackendImpl provides safe iteration; mutating entries during
+// iteration cannot cause a crash. It is undefined whether entries created or
+// destroyed during the iteration will be included in any pre-existing
+// iterations.
+//
 // The non-static functions below must be called on the IO thread unless
 // otherwise stated.
 
@@ -44,10 +49,12 @@ class NET_EXPORT_PRIVATE SimpleBackendImpl : public Backend,
     public SimpleIndexDelegate,
     public base::SupportsWeakPtr<SimpleBackendImpl> {
  public:
-  SimpleBackendImpl(const base::FilePath& path, int max_bytes,
-                    net::CacheType cache_type,
-                    base::SingleThreadTaskRunner* cache_thread,
-                    net::NetLog* net_log);
+  SimpleBackendImpl(
+      const base::FilePath& path,
+      int max_bytes,
+      net::CacheType cache_type,
+      const scoped_refptr<base::SingleThreadTaskRunner>& cache_thread,
+      net::NetLog* net_log);
 
   virtual ~SimpleBackendImpl();
 
@@ -95,14 +102,15 @@ class NET_EXPORT_PRIVATE SimpleBackendImpl : public Backend,
                                  const CompletionCallback& callback) OVERRIDE;
   virtual int DoomEntriesSince(base::Time initial_time,
                                const CompletionCallback& callback) OVERRIDE;
-  virtual int OpenNextEntry(void** iter, Entry** next_entry,
-                            const CompletionCallback& callback) OVERRIDE;
-  virtual void EndEnumeration(void** iter) OVERRIDE;
+  virtual scoped_ptr<Iterator> CreateIterator() OVERRIDE;
   virtual void GetStats(
       std::vector<std::pair<std::string, std::string> >* stats) OVERRIDE;
   virtual void OnExternalCacheHit(const std::string& key) OVERRIDE;
 
  private:
+  class SimpleIterator;
+  friend class SimpleIterator;
+
   typedef base::hash_map<uint64, SimpleEntryImpl*> EntryMap;
 
   typedef base::Callback<void(base::Time mtime, uint64 max_size, int result)>
@@ -153,21 +161,13 @@ class NET_EXPORT_PRIVATE SimpleBackendImpl : public Backend,
   // which is very important to prevent races in DoomEntries() above.
   int DoomEntryFromHash(uint64 entry_hash, const CompletionCallback & callback);
 
-  // Called when the index is initilized to find the next entry in the iterator
-  // |iter|. If there are no more hashes in the iterator list, net::ERR_FAILED
-  // is returned. Otherwise, calls OpenEntryFromHash.
-  void GetNextEntryInIterator(void** iter,
-                              Entry** next_entry,
-                              const CompletionCallback& callback,
-                              int error_code);
-
   // Called when we tried to open an entry with hash alone. When a blank entry
   // has been created and filled in with information from the disk - based on a
   // hash alone - this checks that a duplicate active entry was not created
   // using a key in the meantime.
   void OnEntryOpenedFromHash(uint64 hash,
                              Entry** entry,
-                             scoped_refptr<SimpleEntryImpl> simple_entry,
+                             const scoped_refptr<SimpleEntryImpl>& simple_entry,
                              const CompletionCallback& callback,
                              int error_code);
 
@@ -175,18 +175,10 @@ class NET_EXPORT_PRIVATE SimpleBackendImpl : public Backend,
   // opened, a check for key mismatch is performed.
   void OnEntryOpenedFromKey(const std::string key,
                             Entry** entry,
-                            scoped_refptr<SimpleEntryImpl> simple_entry,
+                            const scoped_refptr<SimpleEntryImpl>& simple_entry,
                             const CompletionCallback& callback,
                             int error_code);
 
-  // Called at the end of the asynchronous operation triggered by
-  // OpenEntryFromHash. Makes sure to continue iterating if the open entry was
-  // not a success.
-  void CheckIterationReturnValue(void** iter,
-                                 Entry** entry,
-                                 const CompletionCallback& callback,
-                                 int error_code);
-
   // A callback thunk used by DoomEntries to clear the |entries_pending_doom_|
   // after a mass doom.
   void DoomEntriesComplete(scoped_ptr<std::vector<uint64> > entry_hashes,