Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_CONTEXT_WRAPPER_H_ | 5 #ifndef CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_CONTEXT_WRAPPER_H_ |
| 6 #define CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_CONTEXT_WRAPPER_H_ | 6 #define CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_CONTEXT_WRAPPER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/memory_pressure_listener.h" | 12 #include "base/memory/memory_pressure_listener.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "components/memory_coordinator/common/memory_coordinator_client.h" | |
| 14 #include "content/common/content_export.h" | 15 #include "content/common/content_export.h" |
| 15 #include "content/common/storage_partition_service.mojom.h" | 16 #include "content/common/storage_partition_service.mojom.h" |
| 16 #include "content/public/browser/dom_storage_context.h" | 17 #include "content/public/browser/dom_storage_context.h" |
| 17 #include "url/origin.h" | 18 #include "url/origin.h" |
| 18 | 19 |
| 19 namespace base { | 20 namespace base { |
| 20 class FilePath; | 21 class FilePath; |
| 21 } | 22 } |
| 22 | 23 |
| 23 namespace shell { | 24 namespace shell { |
| 24 class Connector; | 25 class Connector; |
| 25 } | 26 } |
| 26 | 27 |
| 27 namespace storage { | 28 namespace storage { |
| 28 class SpecialStoragePolicy; | 29 class SpecialStoragePolicy; |
| 29 } | 30 } |
| 30 | 31 |
| 31 namespace content { | 32 namespace content { |
| 32 | 33 |
| 33 class DOMStorageContextImpl; | 34 class DOMStorageContextImpl; |
| 34 class LevelDBWrapperImpl; | 35 class LevelDBWrapperImpl; |
| 35 | 36 |
| 36 // This is owned by Storage Partition and encapsulates all its dom storage | 37 // This is owned by Storage Partition and encapsulates all its dom storage |
| 37 // state. | 38 // state. |
| 38 class CONTENT_EXPORT DOMStorageContextWrapper : | 39 class CONTENT_EXPORT DOMStorageContextWrapper : |
| 39 NON_EXPORTED_BASE(public DOMStorageContext), | 40 NON_EXPORTED_BASE(public DOMStorageContext), |
| 40 public base::RefCountedThreadSafe<DOMStorageContextWrapper> { | 41 public base::RefCountedThreadSafe<DOMStorageContextWrapper>, |
| 42 public memory_coordinator::MemoryCoordinatorClient { | |
| 41 public: | 43 public: |
| 42 // If |data_path| is empty, nothing will be saved to disk. | 44 // If |data_path| is empty, nothing will be saved to disk. |
| 43 DOMStorageContextWrapper( | 45 DOMStorageContextWrapper( |
| 44 shell::Connector* connector, | 46 shell::Connector* connector, |
| 45 const base::FilePath& data_path, | 47 const base::FilePath& data_path, |
| 46 const base::FilePath& local_partition_path, | 48 const base::FilePath& local_partition_path, |
| 47 storage::SpecialStoragePolicy* special_storage_policy); | 49 storage::SpecialStoragePolicy* special_storage_policy); |
| 48 | 50 |
| 49 // DOMStorageContext implementation. | 51 // DOMStorageContext implementation. |
| 50 void GetLocalStorageUsage( | 52 void GetLocalStorageUsage( |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 67 // Called when the BrowserContext/Profile is going away. | 69 // Called when the BrowserContext/Profile is going away. |
| 68 void Shutdown(); | 70 void Shutdown(); |
| 69 | 71 |
| 70 void Flush(); | 72 void Flush(); |
| 71 | 73 |
| 72 // See mojom::StoragePartitionService interface. | 74 // See mojom::StoragePartitionService interface. |
| 73 void OpenLocalStorage(const url::Origin& origin, | 75 void OpenLocalStorage(const url::Origin& origin, |
| 74 mojom::LevelDBObserverPtr observer, | 76 mojom::LevelDBObserverPtr observer, |
| 75 mojom::LevelDBWrapperRequest request); | 77 mojom::LevelDBWrapperRequest request); |
| 76 | 78 |
| 79 private: | |
| 77 // Called on UI thread when the system is under memory pressure. | 80 // Called on UI thread when the system is under memory pressure. |
| 78 void OnMemoryPressure( | 81 void OnMemoryPressure( |
| 79 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level); | 82 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level); |
| 80 | 83 |
| 81 private: | 84 // memory_coordinator::MemoryCoordinatorClient implementation: |
| 85 void OnMemoryStateChange(memory_coordinator::MemoryState state) override; | |
| 86 | |
| 82 friend class DOMStorageMessageFilter; // for access to context() | 87 friend class DOMStorageMessageFilter; // for access to context() |
|
michaeln
2016/09/14 19:40:49
nit: it'd be good to keep the two OnMem and PurgeM
hajimehoshi
2016/09/15 09:14:46
Done.
| |
| 83 friend class SessionStorageNamespaceImpl; // ditto | 88 friend class SessionStorageNamespaceImpl; // ditto |
| 84 friend class base::RefCountedThreadSafe<DOMStorageContextWrapper>; | 89 friend class base::RefCountedThreadSafe<DOMStorageContextWrapper>; |
| 85 | 90 |
| 86 ~DOMStorageContextWrapper() override; | 91 ~DOMStorageContextWrapper() override; |
| 87 DOMStorageContextImpl* context() const { return context_.get(); } | 92 DOMStorageContextImpl* context() const { return context_.get(); } |
| 88 | 93 |
| 94 void PurgeMemory(bool aggressively); | |
| 95 | |
| 89 // An inner class to keep all mojo-ish details together and not bleed them | 96 // An inner class to keep all mojo-ish details together and not bleed them |
| 90 // through the public interface. | 97 // through the public interface. |
| 91 class MojoState; | 98 class MojoState; |
| 92 std::unique_ptr<MojoState> mojo_state_; | 99 std::unique_ptr<MojoState> mojo_state_; |
| 93 | 100 |
| 94 // To receive memory pressure signals. | 101 // To receive memory pressure signals. |
| 95 std::unique_ptr<base::MemoryPressureListener> memory_pressure_listener_; | 102 std::unique_ptr<base::MemoryPressureListener> memory_pressure_listener_; |
| 96 | 103 |
| 97 scoped_refptr<DOMStorageContextImpl> context_; | 104 scoped_refptr<DOMStorageContextImpl> context_; |
| 98 | 105 |
| 99 DISALLOW_IMPLICIT_CONSTRUCTORS(DOMStorageContextWrapper); | 106 DISALLOW_IMPLICIT_CONSTRUCTORS(DOMStorageContextWrapper); |
| 100 }; | 107 }; |
| 101 | 108 |
| 102 } // namespace content | 109 } // namespace content |
| 103 | 110 |
| 104 #endif // CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_CONTEXT_WRAPPER_H_ | 111 #endif // CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_CONTEXT_WRAPPER_H_ |
| OLD | NEW |