| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_INDEXED_DB_INDEXED_DB_DISPATCHER_HOST_H_ | 5 #ifndef CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_DISPATCHER_HOST_H_ |
| 6 #define CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_DISPATCHER_HOST_H_ | 6 #define CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_DISPATCHER_HOST_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| 11 #include <memory> | 11 #include <memory> |
| 12 #include <string> | 12 #include <string> |
| 13 #include <utility> | 13 #include <utility> |
| 14 #include <vector> | 14 #include <vector> |
| 15 | 15 |
| 16 #include "base/macros.h" | 16 #include "base/macros.h" |
| 17 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
| 18 #include "content/browser/blob_storage/chrome_blob_storage_context.h" | 18 #include "content/browser/blob_storage/chrome_blob_storage_context.h" |
| 19 #include "content/common/indexed_db/indexed_db.mojom.h" | 19 #include "content/common/indexed_db/indexed_db.mojom.h" |
| 20 #include "content/public/browser/browser_associated_interface.h" | 20 #include "content/public/browser/browser_thread.h" |
| 21 #include "content/public/browser/browser_message_filter.h" | 21 #include "mojo/public/cpp/bindings/associated_binding_set.h" |
| 22 #include "net/url_request/url_request_context_getter.h" | 22 #include "net/url_request/url_request_context_getter.h" |
| 23 #include "storage/browser/blob/blob_data_handle.h" | 23 #include "storage/browser/blob/blob_data_handle.h" |
| 24 | 24 |
| 25 namespace url { | 25 namespace url { |
| 26 class Origin; | 26 class Origin; |
| 27 } | 27 } |
| 28 | 28 |
| 29 namespace content { | 29 namespace content { |
| 30 class IndexedDBBlobInfo; | 30 class IndexedDBBlobInfo; |
| 31 class IndexedDBCallbacks; | 31 class IndexedDBCallbacks; |
| 32 class IndexedDBContextImpl; | 32 class IndexedDBContextImpl; |
| 33 class IndexedDBDatabaseCallbacks; | 33 class IndexedDBDatabaseCallbacks; |
| 34 | 34 |
| 35 // Handles all IndexedDB related messages from a particular renderer process. | 35 // Handles all IndexedDB related messages from a particular renderer process. |
| 36 class IndexedDBDispatcherHost | 36 class IndexedDBDispatcherHost |
| 37 : public BrowserMessageFilter, | 37 : public base::RefCountedThreadSafe<IndexedDBDispatcherHost, |
| 38 public BrowserAssociatedInterface<::indexed_db::mojom::Factory>, | 38 BrowserThread::DeleteOnIOThread>, |
| 39 public ::indexed_db::mojom::Factory { | 39 public ::indexed_db::mojom::Factory { |
| 40 public: | 40 public: |
| 41 // Only call the constructor from the UI thread. | 41 // Only call the constructor from the UI thread. |
| 42 IndexedDBDispatcherHost(int ipc_process_id, | 42 IndexedDBDispatcherHost(int ipc_process_id, |
| 43 net::URLRequestContextGetter* request_context_getter, | 43 net::URLRequestContextGetter* request_context_getter, |
| 44 IndexedDBContextImpl* indexed_db_context, | 44 IndexedDBContextImpl* indexed_db_context, |
| 45 ChromeBlobStorageContext* blob_storage_context); | 45 ChromeBlobStorageContext* blob_storage_context); |
| 46 | 46 |
| 47 // BrowserMessageFilter implementation. | 47 void AddBinding(::indexed_db::mojom::FactoryAssociatedRequest request); |
| 48 void OnChannelClosing() override; | |
| 49 void OnDestruct() const override; | |
| 50 bool OnMessageReceived(const IPC::Message& message) override; | |
| 51 | 48 |
| 52 // A shortcut for accessing our context. | 49 // A shortcut for accessing our context. |
| 53 IndexedDBContextImpl* context() const { return indexed_db_context_.get(); } | 50 IndexedDBContextImpl* context() const { return indexed_db_context_.get(); } |
| 54 storage::BlobStorageContext* blob_storage_context() const { | 51 storage::BlobStorageContext* blob_storage_context() const { |
| 55 return blob_storage_context_->context(); | 52 return blob_storage_context_->context(); |
| 56 } | 53 } |
| 57 int ipc_process_id() const { return ipc_process_id_; } | 54 int ipc_process_id() const { return ipc_process_id_; } |
| 58 | 55 |
| 59 std::string HoldBlobData(const IndexedDBBlobInfo& blob_info); | 56 std::string HoldBlobData(const IndexedDBBlobInfo& blob_info); |
| 60 void DropBlobData(const std::string& uuid); | 57 void DropBlobData(const std::string& uuid); |
| 61 | 58 |
| 62 // True if the channel is closing/closed and outstanding requests | |
| 63 // can be abandoned. Only access on IndexedDB thread. | |
| 64 bool IsOpen() const; | |
| 65 | |
| 66 private: | 59 private: |
| 67 // Friends to enable OnDestruct() delegation. | 60 // Friends to enable OnDestruct() delegation. |
| 68 friend class BrowserThread; | 61 friend class BrowserThread; |
| 69 friend class base::DeleteHelper<IndexedDBDispatcherHost>; | 62 friend class base::DeleteHelper<IndexedDBDispatcherHost>; |
| 70 | 63 |
| 71 ~IndexedDBDispatcherHost() override; | 64 ~IndexedDBDispatcherHost() override; |
| 72 | 65 |
| 73 // indexed_db::mojom::Factory implementation: | 66 // indexed_db::mojom::Factory implementation: |
| 74 void GetDatabaseNames( | 67 void GetDatabaseNames( |
| 75 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info, | 68 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info, |
| (...skipping 29 matching lines...) Expand all Loading... |
| 105 scoped_refptr<IndexedDBContextImpl> indexed_db_context_; | 98 scoped_refptr<IndexedDBContextImpl> indexed_db_context_; |
| 106 scoped_refptr<ChromeBlobStorageContext> blob_storage_context_; | 99 scoped_refptr<ChromeBlobStorageContext> blob_storage_context_; |
| 107 | 100 |
| 108 // Maps blob uuid to a pair (handle, ref count). Entry is added and/or count | 101 // Maps blob uuid to a pair (handle, ref count). Entry is added and/or count |
| 109 // is incremented in HoldBlobData(), and count is decremented and/or entry | 102 // is incremented in HoldBlobData(), and count is decremented and/or entry |
| 110 // removed in DropBlobData(). | 103 // removed in DropBlobData(). |
| 111 std::map<std::string, | 104 std::map<std::string, |
| 112 std::pair<std::unique_ptr<storage::BlobDataHandle>, int>> | 105 std::pair<std::unique_ptr<storage::BlobDataHandle>, int>> |
| 113 blob_data_handle_map_; | 106 blob_data_handle_map_; |
| 114 | 107 |
| 115 // Only access on IndexedDB thread. | 108 // Used to set file permissions for blob storage. |
| 116 bool is_open_ = true; | 109 const int ipc_process_id_; |
| 117 | 110 |
| 118 // Used to set file permissions for blob storage. | 111 mojo::AssociatedBindingSet<::indexed_db::mojom::Factory> bindings_; |
| 119 int ipc_process_id_; | |
| 120 | 112 |
| 121 DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBDispatcherHost); | 113 DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBDispatcherHost); |
| 122 }; | 114 }; |
| 123 | 115 |
| 124 } // namespace content | 116 } // namespace content |
| 125 | 117 |
| 126 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_DISPATCHER_HOST_H_ | 118 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_DISPATCHER_HOST_H_ |
| OLD | NEW |