Commit 5e4cbe03 authored by kristipark's avatar kristipark Committed by Commit Bot

[DevTools] [IndexedDB] Live update IndexedDB

Refreshes the IDB tree and table data if IDB is modified.

Bug: 729793
Change-Id: I806e44ea6b5db884a2ab8ce9279745e023ac2732
Reviewed-on: https://chromium-review.googlesource.com/658486
Commit-Queue: Kristi Park <kristipark@chromium.org>
Reviewed-by: default avatarDmitry Gozman <dgozman@chromium.org>
Reviewed-by: default avatarMichael Nordman <michaeln@chromium.org>
Cr-Commit-Position: refs/heads/master@{#505227}
parent db84e5ac
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "content/browser/cache_storage/cache_storage_context_impl.h" #include "content/browser/cache_storage/cache_storage_context_impl.h"
#include "content/browser/devtools/protocol/devtools_domain_handler.h" #include "content/browser/devtools/protocol/devtools_domain_handler.h"
#include "content/browser/devtools/protocol/storage.h" #include "content/browser/devtools/protocol/storage.h"
#include "content/browser/indexed_db/indexed_db_context_impl.h"
namespace content { namespace content {
...@@ -27,31 +28,46 @@ class StorageHandler : public DevToolsDomainHandler, ...@@ -27,31 +28,46 @@ class StorageHandler : public DevToolsDomainHandler,
StorageHandler(); StorageHandler();
~StorageHandler() override; ~StorageHandler() override;
// content::protocol::DevToolsDomainHandler
void Wire(UberDispatcher* dispatcher) override; void Wire(UberDispatcher* dispatcher) override;
void SetRenderFrameHost(RenderFrameHostImpl* host) override; void SetRenderFrameHost(RenderFrameHostImpl* host) override;
Response Disable() override;
// content::protocol::storage::Backend
Response ClearDataForOrigin( Response ClearDataForOrigin(
const std::string& origin, const std::string& origin,
const std::string& storage_types) override; const std::string& storage_types) override;
void GetUsageAndQuota( void GetUsageAndQuota(
const String& origin, const String& origin,
std::unique_ptr<GetUsageAndQuotaCallback> callback) override; std::unique_ptr<GetUsageAndQuotaCallback> callback) override;
// Ignores all double calls to track an origin. // Ignores all double calls to track an origin.
Response TrackCacheStorageForOrigin(const std::string& origin) override; Response TrackCacheStorageForOrigin(const std::string& origin) override;
Response UntrackCacheStorageForOrigin(const std::string& origin) override; Response UntrackCacheStorageForOrigin(const std::string& origin) override;
Response TrackIndexedDBForOrigin(const std::string& origin) override;
Response UntrackIndexedDBForOrigin(const std::string& origin) override;
private: private:
// See definition for lifetime information. // See definition for lifetime information.
class CacheStorageObserver; class CacheStorageObserver;
class IndexedDBObserver;
// Not thread safe.
CacheStorageObserver* GetCacheStorageObserver(); CacheStorageObserver* GetCacheStorageObserver();
IndexedDBObserver* GetIndexedDBObserver();
void NotifyCacheStorageListChanged(const std::string& origin); void NotifyCacheStorageListChanged(const std::string& origin);
void NotifyCacheStorageContentChanged(const std::string& origin, void NotifyCacheStorageContentChanged(const std::string& origin,
const std::string& name); const std::string& name);
void NotifyIndexedDBListChanged(const std::string& origin);
void NotifyIndexedDBContentChanged(const std::string& origin,
const base::string16& database_name,
const base::string16& object_store_name);
std::unique_ptr<Storage::Frontend> frontend_; std::unique_ptr<Storage::Frontend> frontend_;
RenderFrameHostImpl* host_; RenderFrameHostImpl* host_;
std::unique_ptr<CacheStorageObserver> cache_storage_observer_; std::unique_ptr<CacheStorageObserver> cache_storage_observer_;
std::unique_ptr<IndexedDBObserver> indexed_db_observer_;
base::WeakPtrFactory<StorageHandler> weak_ptr_factory_; base::WeakPtrFactory<StorageHandler> weak_ptr_factory_;
......
...@@ -470,6 +470,32 @@ void IndexedDBContextImpl::DatabaseDeleted(const Origin& origin) { ...@@ -470,6 +470,32 @@ void IndexedDBContextImpl::DatabaseDeleted(const Origin& origin) {
QueryDiskAndUpdateQuotaUsage(origin); QueryDiskAndUpdateQuotaUsage(origin);
} }
void IndexedDBContextImpl::AddObserver(
IndexedDBContextImpl::Observer* observer) {
DCHECK(!observers_.HasObserver(observer));
observers_.AddObserver(observer);
}
void IndexedDBContextImpl::RemoveObserver(
IndexedDBContextImpl::Observer* observer) {
observers_.RemoveObserver(observer);
}
void IndexedDBContextImpl::NotifyIndexedDBListChanged(const Origin& origin) {
for (auto& observer : observers_)
observer.OnIndexedDBListChanged(origin);
}
void IndexedDBContextImpl::NotifyIndexedDBContentChanged(
const Origin& origin,
const base::string16& database_name,
const base::string16& object_store_name) {
for (auto& observer : observers_) {
observer.OnIndexedDBContentChanged(origin, database_name,
object_store_name);
}
}
IndexedDBContextImpl::~IndexedDBContextImpl() { IndexedDBContextImpl::~IndexedDBContextImpl() {
if (factory_.get()) { if (factory_.get()) {
TaskRunner()->PostTask(FROM_HERE, TaskRunner()->PostTask(FROM_HERE,
...@@ -551,6 +577,7 @@ void IndexedDBContextImpl::QueryDiskAndUpdateQuotaUsage(const Origin& origin) { ...@@ -551,6 +577,7 @@ void IndexedDBContextImpl::QueryDiskAndUpdateQuotaUsage(const Origin& origin) {
quota_manager_proxy()->NotifyStorageModified( quota_manager_proxy()->NotifyStorageModified(
storage::QuotaClient::kIndexedDatabase, origin.GetURL(), storage::QuotaClient::kIndexedDatabase, origin.GetURL(),
storage::kStorageTypeTemporary, difference); storage::kStorageTypeTemporary, difference);
NotifyIndexedDBListChanged(origin);
} }
} }
......
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
#include <map> #include <map>
#include <memory> #include <memory>
#include <set> #include <set>
#include <string>
#include <vector> #include <vector>
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
...@@ -51,6 +50,18 @@ class CONTENT_EXPORT IndexedDBContextImpl : public IndexedDBContext { ...@@ -51,6 +50,18 @@ class CONTENT_EXPORT IndexedDBContextImpl : public IndexedDBContext {
FORCE_CLOSE_REASON_MAX FORCE_CLOSE_REASON_MAX
}; };
class Observer {
public:
virtual void OnIndexedDBListChanged(const url::Origin& origin) = 0;
virtual void OnIndexedDBContentChanged(
const url::Origin& origin,
const base::string16& database_name,
const base::string16& object_store_name) = 0;
protected:
virtual ~Observer() {};
};
// The indexed db directory. // The indexed db directory.
static const base::FilePath::CharType kIndexedDBDirectory[]; static const base::FilePath::CharType kIndexedDBDirectory[];
...@@ -125,6 +136,15 @@ class CONTENT_EXPORT IndexedDBContextImpl : public IndexedDBContext { ...@@ -125,6 +136,15 @@ class CONTENT_EXPORT IndexedDBContextImpl : public IndexedDBContext {
bool is_incognito() const { return data_path_.empty(); } bool is_incognito() const { return data_path_.empty(); }
// Only callable on the IDB task runner.
void AddObserver(Observer* observer);
void RemoveObserver(Observer* observer);
void NotifyIndexedDBListChanged(const url::Origin& origin);
void NotifyIndexedDBContentChanged(const url::Origin& origin,
const base::string16& database_name,
const base::string16& object_store_name);
protected: protected:
~IndexedDBContextImpl() override; ~IndexedDBContextImpl() override;
...@@ -162,6 +182,7 @@ class CONTENT_EXPORT IndexedDBContextImpl : public IndexedDBContext { ...@@ -162,6 +182,7 @@ class CONTENT_EXPORT IndexedDBContextImpl : public IndexedDBContext {
scoped_refptr<base::SequencedTaskRunner> task_runner_; scoped_refptr<base::SequencedTaskRunner> task_runner_;
std::unique_ptr<std::set<url::Origin>> origin_set_; std::unique_ptr<std::set<url::Origin>> origin_set_;
std::map<url::Origin, int64_t> origin_size_map_; std::map<url::Origin, int64_t> origin_size_map_;
base::ObserverList<Observer> observers_;
DISALLOW_COPY_AND_ASSIGN(IndexedDBContextImpl); DISALLOW_COPY_AND_ASSIGN(IndexedDBContextImpl);
}; };
......
...@@ -1380,6 +1380,9 @@ leveldb::Status IndexedDBDatabase::PutOperation( ...@@ -1380,6 +1380,9 @@ leveldb::Status IndexedDBDatabase::PutOperation(
? blink::kWebIDBAdd ? blink::kWebIDBAdd
: blink::kWebIDBPut, : blink::kWebIDBPut,
IndexedDBKeyRange(*key), &params->value); IndexedDBKeyRange(*key), &params->value);
factory_->NotifyIndexedDBContentChanged(
origin(), metadata_.name,
metadata_.object_stores[params->object_store_id].name);
return s; return s;
} }
...@@ -1678,6 +1681,8 @@ leveldb::Status IndexedDBDatabase::DeleteRangeOperation( ...@@ -1678,6 +1681,8 @@ leveldb::Status IndexedDBDatabase::DeleteRangeOperation(
callbacks->OnSuccess(); callbacks->OnSuccess();
FilterObservation(transaction, object_store_id, blink::kWebIDBDelete, FilterObservation(transaction, object_store_id, blink::kWebIDBDelete,
*key_range, nullptr); *key_range, nullptr);
factory_->NotifyIndexedDBContentChanged(
origin(), metadata_.name, metadata_.object_stores[object_store_id].name);
return s; return s;
} }
...@@ -1708,6 +1713,8 @@ leveldb::Status IndexedDBDatabase::ClearOperation( ...@@ -1708,6 +1713,8 @@ leveldb::Status IndexedDBDatabase::ClearOperation(
FilterObservation(transaction, object_store_id, blink::kWebIDBClear, FilterObservation(transaction, object_store_id, blink::kWebIDBClear,
IndexedDBKeyRange(), nullptr); IndexedDBKeyRange(), nullptr);
factory_->NotifyIndexedDBContentChanged(
origin(), metadata_.name, metadata_.object_stores[object_store_id].name);
return s; return s;
} }
......
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
#include <map> #include <map>
#include <memory> #include <memory>
#include <set> #include <set>
#include <string>
#include <utility> #include <utility>
#include "base/files/file_path.h" #include "base/files/file_path.h"
...@@ -94,6 +93,11 @@ class CONTENT_EXPORT IndexedDBFactory ...@@ -94,6 +93,11 @@ class CONTENT_EXPORT IndexedDBFactory
virtual size_t GetConnectionCount(const url::Origin& origin) const = 0; virtual size_t GetConnectionCount(const url::Origin& origin) const = 0;
virtual void NotifyIndexedDBContentChanged(
const url::Origin& origin,
const base::string16& database_name,
const base::string16& object_store_name) = 0;
protected: protected:
friend class base::RefCountedThreadSafe<IndexedDBFactory>; friend class base::RefCountedThreadSafe<IndexedDBFactory>;
......
...@@ -619,4 +619,14 @@ size_t IndexedDBFactoryImpl::GetConnectionCount(const Origin& origin) const { ...@@ -619,4 +619,14 @@ size_t IndexedDBFactoryImpl::GetConnectionCount(const Origin& origin) const {
return count; return count;
} }
void IndexedDBFactoryImpl::NotifyIndexedDBContentChanged(
const url::Origin& origin,
const base::string16& database_name,
const base::string16& object_store_name) {
if (!context_)
return;
context_->NotifyIndexedDBContentChanged(origin, database_name,
object_store_name);
}
} // namespace content } // namespace content
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
#include <map> #include <map>
#include <memory> #include <memory>
#include <set> #include <set>
#include <string>
#include "base/gtest_prod_util.h" #include "base/gtest_prod_util.h"
#include "base/macros.h" #include "base/macros.h"
...@@ -80,6 +79,11 @@ class CONTENT_EXPORT IndexedDBFactoryImpl : public IndexedDBFactory { ...@@ -80,6 +79,11 @@ class CONTENT_EXPORT IndexedDBFactoryImpl : public IndexedDBFactory {
size_t GetConnectionCount(const url::Origin& origin) const override; size_t GetConnectionCount(const url::Origin& origin) const override;
void NotifyIndexedDBContentChanged(
const url::Origin& origin,
const base::string16& database_name,
const base::string16& object_store_name) override;
protected: protected:
~IndexedDBFactoryImpl() override; ~IndexedDBFactoryImpl() override;
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#include <stddef.h> #include <stddef.h>
#include <memory> #include <memory>
#include <string>
#include "base/macros.h" #include "base/macros.h"
#include "content/browser/indexed_db/indexed_db_factory.h" #include "content/browser/indexed_db/indexed_db_factory.h"
...@@ -88,6 +87,12 @@ class MockIndexedDBFactory : public IndexedDBFactory { ...@@ -88,6 +87,12 @@ class MockIndexedDBFactory : public IndexedDBFactory {
MOCK_METHOD2(ReportOutstandingBlobs, MOCK_METHOD2(ReportOutstandingBlobs,
void(const url::Origin& origin, bool blobs_outstanding)); void(const url::Origin& origin, bool blobs_outstanding));
MOCK_METHOD1(NotifyIndexedDBListChanged, void(const url::Origin& origin));
MOCK_METHOD3(NotifyIndexedDBContentChanged,
void(const url::Origin& origin,
const base::string16& database_name,
const base::string16& object_store_name));
protected: protected:
virtual ~MockIndexedDBFactory(); virtual ~MockIndexedDBFactory();
......
...@@ -4927,6 +4927,20 @@ ...@@ -4927,6 +4927,20 @@
{ "name": "origin", "type": "string", "description": "Security origin." } { "name": "origin", "type": "string", "description": "Security origin." }
], ],
"description": "Unregisters origin from receiving notifications for cache storage." "description": "Unregisters origin from receiving notifications for cache storage."
},
{
"name": "trackIndexedDBForOrigin",
"parameters": [
{ "name": "origin", "type": "string", "description": "Security origin." }
],
"description": "Registers origin to be notified when an update occurs to its IndexedDB."
},
{
"name": "untrackIndexedDBForOrigin",
"parameters": [
{ "name": "origin", "type": "string", "description": "Security origin." }
],
"description": "Unregisters origin from receiving notifications for IndexedDB."
} }
], ],
"events": [ "events": [
...@@ -4944,6 +4958,22 @@ ...@@ -4944,6 +4958,22 @@
{ "name": "cacheName", "type": "string", "description": "Name of cache in origin." } { "name": "cacheName", "type": "string", "description": "Name of cache in origin." }
], ],
"description": "A cache's contents have been modified." "description": "A cache's contents have been modified."
},
{
"name": "indexedDBListUpdated",
"parameters": [
{ "name": "origin", "type": "string", "description": "Origin to update." }
],
"description": "The origin's IndexedDB database list has been modified."
},
{
"name": "indexedDBContentUpdated",
"parameters": [
{ "name": "origin", "type": "string", "description": "Origin to update." },
{ "name": "databaseName", "type": "string", "description": "Database to update." },
{ "name": "objectStoreName", "type": "string", "description": "ObjectStore to update." }
],
"description": "The origin's IndexedDB object store has been modified."
} }
] ]
}, },
......
...@@ -267,6 +267,22 @@ SDK.ServiceWorkerCacheModel = class extends SDK.SDKModel { ...@@ -267,6 +267,22 @@ SDK.ServiceWorkerCacheModel = class extends SDK.SDKModel {
this.dispatchEventToListeners( this.dispatchEventToListeners(
SDK.ServiceWorkerCacheModel.Events.CacheStorageContentUpdated, {origin: origin, cacheName: cacheName}); SDK.ServiceWorkerCacheModel.Events.CacheStorageContentUpdated, {origin: origin, cacheName: cacheName});
} }
/**
* @param {string} origin
* @override
*/
indexedDBListUpdated(origin) {
}
/**
* @param {string} origin
* @param {string} databaseName
* @param {string} objectStoreName
* @override
*/
indexedDBContentUpdated(origin, databaseName, objectStoreName) {
}
}; };
SDK.SDKModel.register(SDK.ServiceWorkerCacheModel, SDK.Target.Capability.Browser, false); SDK.SDKModel.register(SDK.ServiceWorkerCacheModel, SDK.Target.Capability.Browser, false);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment