Home | History | Annotate | Download | only in storage
      1 // Copyright 2014 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 EXTENSIONS_BROWSER_API_STORAGE_VALUE_STORE_CACHE_H_
      6 #define EXTENSIONS_BROWSER_API_STORAGE_VALUE_STORE_CACHE_H_
      7 
      8 #include <string>
      9 
     10 #include "base/callback.h"
     11 #include "base/memory/ref_counted.h"
     12 
     13 class ValueStore;
     14 
     15 namespace extensions {
     16 
     17 class Extension;
     18 
     19 // Each namespace of the storage API implements this interface.
     20 // Instances are created on the UI thread, but from then on live on the FILE
     21 // thread. At shutdown, ShutdownOnUI() is first invoked on the UI thread, and
     22 // the destructor is invoked soon after on the FILE thread. This gives
     23 // implementations the chance to work with ValueStores on FILE but observe
     24 // events on UI.
     25 // It also means that any methods invoked on UI *before ShutdownOnUI()* can
     26 // safely post other methods to the FILE thread, since the deletion task is only
     27 // posted to FILE after ShutdownOnUI().
     28 class ValueStoreCache {
     29  public:
     30   typedef base::Callback<void(ValueStore*)> StorageCallback;
     31 
     32   // Invoked on FILE.
     33   virtual ~ValueStoreCache();
     34 
     35   // This is invoked from the UI thread during destruction of the Profile that
     36   // ultimately owns this object. Any Profile-related cleanups should be
     37   // performed in this method, since the destructor will execute later, after
     38   // the Profile is already gone.
     39   virtual void ShutdownOnUI();
     40 
     41   // Requests the cache to invoke |callback| with the appropriate ValueStore
     42   // for the given |extension|. |callback| should be invoked with a NULL
     43   // ValueStore in case of errors.
     44   // |extension| is passed in a scoped_refptr<> because this method is
     45   // asynchronously posted as a task to the loop returned by GetMessageLoop(),
     46   // and this guarantees the Extension is still valid when the method executes.
     47   virtual void RunWithValueStoreForExtension(
     48       const StorageCallback& callback,
     49       scoped_refptr<const Extension> extension) = 0;
     50 
     51   // Requests the cache to delete any storage used by |extension_id|.
     52   virtual void DeleteStorageSoon(const std::string& extension_id) = 0;
     53 };
     54 
     55 }  // namespace extensions
     56 
     57 #endif  // EXTENSIONS_BROWSER_API_STORAGE_VALUE_STORE_CACHE_H_
     58