| 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_associated_interface.h" |
| 21 #include "content/public/browser/browser_message_filter.h" | 21 #include "content/public/browser/browser_message_filter.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 #include "url/gurl.h" | |
| 25 | 24 |
| 26 namespace url { | 25 namespace url { |
| 27 class Origin; | 26 class Origin; |
| 28 } | 27 } |
| 29 | 28 |
| 30 namespace content { | 29 namespace content { |
| 31 class IndexedDBBlobInfo; | 30 class IndexedDBBlobInfo; |
| 32 class IndexedDBCallbacks; | 31 class IndexedDBCallbacks; |
| 33 class IndexedDBContextImpl; | 32 class IndexedDBContextImpl; |
| 34 class IndexedDBDatabaseCallbacks; | 33 class IndexedDBDatabaseCallbacks; |
| 35 | 34 |
| 36 // Handles all IndexedDB related messages from a particular renderer process. | 35 // Handles all IndexedDB related messages from a particular renderer process. |
| 37 class IndexedDBDispatcherHost | 36 class IndexedDBDispatcherHost |
| 38 : public BrowserMessageFilter, | 37 : public BrowserMessageFilter, |
| 39 public BrowserAssociatedInterface<::indexed_db::mojom::Factory>, | 38 public BrowserAssociatedInterface<::indexed_db::mojom::Factory>, |
| 40 public ::indexed_db::mojom::Factory { | 39 public ::indexed_db::mojom::Factory { |
| 41 public: | 40 public: |
| 42 // Only call the constructor from the UI thread. | 41 // Only call the constructor from the UI thread. |
| 43 IndexedDBDispatcherHost(int ipc_process_id, | 42 IndexedDBDispatcherHost(int ipc_process_id, |
| 44 net::URLRequestContextGetter* request_context_getter, | 43 net::URLRequestContextGetter* request_context_getter, |
| 45 IndexedDBContextImpl* indexed_db_context, | 44 IndexedDBContextImpl* indexed_db_context, |
| 46 ChromeBlobStorageContext* blob_storage_context); | 45 ChromeBlobStorageContext* blob_storage_context); |
| 47 | 46 |
| 48 // BrowserMessageFilter implementation. | 47 // BrowserMessageFilter implementation. |
| 49 void OnChannelClosing() override; | 48 void OnChannelClosing() override; |
| 50 void OnDestruct() const override; | 49 void OnDestruct() const override; |
| 51 bool OnMessageReceived(const IPC::Message& message) override; | 50 bool OnMessageReceived(const IPC::Message& message) override; |
| 52 | 51 |
| 53 void FinishTransaction(int64_t host_transaction_id, bool committed); | |
| 54 | |
| 55 // A shortcut for accessing our context. | 52 // A shortcut for accessing our context. |
| 56 IndexedDBContextImpl* context() const { return indexed_db_context_.get(); } | 53 IndexedDBContextImpl* context() const { return indexed_db_context_.get(); } |
| 57 storage::BlobStorageContext* blob_storage_context() const { | 54 storage::BlobStorageContext* blob_storage_context() const { |
| 58 return blob_storage_context_->context(); | 55 return blob_storage_context_->context(); |
| 59 } | 56 } |
| 60 int ipc_process_id() const { return ipc_process_id_; } | 57 int ipc_process_id() const { return ipc_process_id_; } |
| 61 | 58 |
| 62 bool RegisterTransactionId(int64_t host_transaction_id, | |
| 63 const url::Origin& origin); | |
| 64 bool GetTransactionSize(int64_t host_transaction_id, | |
| 65 int64_t* transaction_size); | |
| 66 void AddToTransaction(int64_t host_transaction_id, int64_t value_length); | |
| 67 | |
| 68 // These are called to map a 32-bit front-end (renderer-specific) transaction | |
| 69 // id to and from a back-end ("host") transaction id that encodes the process | |
| 70 // id in the high 32 bits. The mapping is host-specific and ids are validated. | |
| 71 int64_t HostTransactionId(int64_t transaction_id); | |
| 72 int64_t RendererTransactionId(int64_t host_transaction_id); | |
| 73 | |
| 74 // These are called to decode a host transaction ID, for diagnostic purposes. | |
| 75 static uint32_t TransactionIdToRendererTransactionId( | |
| 76 int64_t host_transaction_id); | |
| 77 static uint32_t TransactionIdToProcessId(int64_t host_transaction_id); | |
| 78 | |
| 79 std::string HoldBlobData(const IndexedDBBlobInfo& blob_info); | 59 std::string HoldBlobData(const IndexedDBBlobInfo& blob_info); |
| 80 void DropBlobData(const std::string& uuid); | 60 void DropBlobData(const std::string& uuid); |
| 81 | 61 |
| 82 // True if the channel is closing/closed and outstanding requests | 62 // True if the channel is closing/closed and outstanding requests |
| 83 // can be abandoned. Only access on IndexedDB thread. | 63 // can be abandoned. Only access on IndexedDB thread. |
| 84 bool IsOpen() const; | 64 bool IsOpen() const; |
| 85 | 65 |
| 86 private: | 66 private: |
| 87 // Friends to enable OnDestruct() delegation. | 67 // Friends to enable OnDestruct() delegation. |
| 88 friend class BrowserThread; | 68 friend class BrowserThread; |
| 89 friend class base::DeleteHelper<IndexedDBDispatcherHost>; | 69 friend class base::DeleteHelper<IndexedDBDispatcherHost>; |
| 90 | 70 |
| 91 // Used in nested classes. | |
| 92 typedef std::map<int64_t, int64_t> TransactionIDToSizeMap; | |
| 93 typedef std::map<int64_t, url::Origin> TransactionIDToOriginMap; | |
| 94 | |
| 95 ~IndexedDBDispatcherHost() override; | 71 ~IndexedDBDispatcherHost() override; |
| 96 | 72 |
| 97 // indexed_db::mojom::Factory implementation: | 73 // indexed_db::mojom::Factory implementation: |
| 98 void GetDatabaseNames( | 74 void GetDatabaseNames( |
| 99 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info, | 75 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info, |
| 100 const url::Origin& origin) override; | 76 const url::Origin& origin) override; |
| 101 void Open(::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info, | 77 void Open(::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info, |
| 102 ::indexed_db::mojom::DatabaseCallbacksAssociatedPtrInfo | 78 ::indexed_db::mojom::DatabaseCallbacksAssociatedPtrInfo |
| 103 database_callbacks_info, | 79 database_callbacks_info, |
| 104 const url::Origin& origin, | 80 const url::Origin& origin, |
| (...skipping 26 matching lines...) Expand all Loading... |
| 131 | 107 |
| 132 // Maps blob uuid to a pair (handle, ref count). Entry is added and/or count | 108 // Maps blob uuid to a pair (handle, ref count). Entry is added and/or count |
| 133 // is incremented in HoldBlobData(), and count is decremented and/or entry | 109 // is incremented in HoldBlobData(), and count is decremented and/or entry |
| 134 // removed in DropBlobData(). | 110 // removed in DropBlobData(). |
| 135 std::map<std::string, | 111 std::map<std::string, |
| 136 std::pair<std::unique_ptr<storage::BlobDataHandle>, int>> | 112 std::pair<std::unique_ptr<storage::BlobDataHandle>, int>> |
| 137 blob_data_handle_map_; | 113 blob_data_handle_map_; |
| 138 | 114 |
| 139 // Only access on IndexedDB thread. | 115 // Only access on IndexedDB thread. |
| 140 bool is_open_ = true; | 116 bool is_open_ = true; |
| 141 TransactionIDToSizeMap transaction_size_map_; | |
| 142 TransactionIDToOriginMap transaction_origin_map_; | |
| 143 | 117 |
| 144 // Used to set file permissions for blob storage. | 118 // Used to set file permissions for blob storage. |
| 145 int ipc_process_id_; | 119 int ipc_process_id_; |
| 146 | 120 |
| 147 DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBDispatcherHost); | 121 DISALLOW_IMPLICIT_CONSTRUCTORS(IndexedDBDispatcherHost); |
| 148 }; | 122 }; |
| 149 | 123 |
| 150 } // namespace content | 124 } // namespace content |
| 151 | 125 |
| 152 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_DISPATCHER_HOST_H_ | 126 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_DISPATCHER_HOST_H_ |
| OLD | NEW |