| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 BLIMP_ENGINE_MOJO_BLOB_CHANNEL_SERVICE_H_ | 5 #ifndef BLIMP_ENGINE_MOJO_BLOB_CHANNEL_SERVICE_H_ |
| 6 #define BLIMP_ENGINE_MOJO_BLOB_CHANNEL_SERVICE_H_ | 6 #define BLIMP_ENGINE_MOJO_BLOB_CHANNEL_SERVICE_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> |
| 9 | 10 |
| 11 #include "base/memory/weak_ptr.h" |
| 12 #include "base/threading/thread_checker.h" |
| 10 #include "blimp/engine/mojo/blob_channel.mojom.h" | 13 #include "blimp/engine/mojo/blob_channel.mojom.h" |
| 14 #include "blimp/net/blob_channel/blob_channel_sender.h" |
| 11 #include "mojo/public/cpp/bindings/binding_set.h" | 15 #include "mojo/public/cpp/bindings/binding_set.h" |
| 12 | 16 |
| 13 namespace blimp { | 17 namespace blimp { |
| 14 | |
| 15 class BlobChannelSender; | |
| 16 | |
| 17 namespace engine { | 18 namespace engine { |
| 18 | 19 |
| 19 // Service for processing BlobChannel requests from the renderer. | 20 // Service for processing BlobChannel requests from the renderer. |
| 20 // Runs on the browser process. | 21 // Caller is responsible for executing all methods on the IO thread. |
| 22 // The class may interact with objects on the UI thread by posting tasks to |
| 23 // |ui_task_runner_|. |
| 21 class BlobChannelService : public mojom::BlobChannel { | 24 class BlobChannelService : public mojom::BlobChannel { |
| 22 public: | 25 public: |
| 23 // |blob_channel_sender| must outlive the Mojo connection. | 26 // |blob_channel_sender|: The BlobChannelSender object which will receive |
| 24 explicit BlobChannelService(BlobChannelSender* blob_channel_sender); | 27 // blobs and answer delivery status queries. |
| 28 // |blob_sender_task_runner|: The task runner that will process all |
| 29 // interactions with |blob_channel_sender|. |
| 30 BlobChannelService( |
| 31 base::WeakPtr<BlobChannelSender> blob_channel_sender, |
| 32 scoped_refptr<base::SingleThreadTaskRunner> blob_sender_task_runner); |
| 25 | 33 |
| 26 ~BlobChannelService() override; | 34 ~BlobChannelService() override; |
| 27 | 35 |
| 28 // Factory method called by Mojo. | 36 // Factory method called by Mojo. |
| 29 // Binds |this| to the connection specified by |request|. | 37 // Binds |this| to the connection specified by |request|. |
| 30 void BindRequest(mojo::InterfaceRequest<mojom::BlobChannel> request); | 38 void BindRequest(mojo::InterfaceRequest<mojom::BlobChannel> request); |
| 31 | 39 |
| 32 private: | 40 private: |
| 41 std::vector<BlobChannelSender::CacheStateEntry> GetCachedBlobIdsOnUiThread(); |
| 42 |
| 43 // Processes the return value from BlobChannelSender::GetCachedBlobIds(). |
| 44 void OnGetCachedBlobsCompleted( |
| 45 const BlobChannelService::GetCachedBlobIdsCallback& response_callback, |
| 46 const std::vector<BlobChannelSender::CacheStateEntry>& ids); |
| 47 |
| 33 // BlobChannel implementation. | 48 // BlobChannel implementation. |
| 34 void GetCachedBlobIds( | 49 void GetCachedBlobIds( |
| 35 const GetCachedBlobIdsCallback& response_callback) override; | 50 const GetCachedBlobIdsCallback& response_callback) override; |
| 36 void PutBlob(const std::string& id, | 51 void PutBlob(const std::string& id, |
| 37 mojo::ScopedSharedBufferHandle data, | 52 mojo::ScopedSharedBufferHandle data, |
| 38 uint32_t size) override; | 53 uint32_t size) override; |
| 39 void DeliverBlob(const std::string& id) override; | 54 void DeliverBlob(const std::string& id) override; |
| 40 | 55 |
| 41 mojo::BindingSet<mojom::BlobChannel> bindings_; | 56 mojo::BindingSet<mojom::BlobChannel> bindings_; |
| 42 | 57 |
| 43 // Sender object which will receive the blobs passed over the Mojo service. | 58 // Sender object which will receive the blobs passed over the Mojo service. |
| 44 BlobChannelSender* blob_channel_sender_; | 59 base::WeakPtr<BlobChannelSender> blob_channel_sender_; |
| 60 |
| 61 // UI thread TaskRunner. |
| 62 scoped_refptr<base::SingleThreadTaskRunner> blob_sender_task_runner_; |
| 63 |
| 64 base::ThreadChecker thread_checker_; |
| 65 |
| 66 base::WeakPtrFactory<BlobChannelService> weak_factory_; |
| 45 | 67 |
| 46 DISALLOW_COPY_AND_ASSIGN(BlobChannelService); | 68 DISALLOW_COPY_AND_ASSIGN(BlobChannelService); |
| 47 }; | 69 }; |
| 48 | 70 |
| 49 } // namespace engine | 71 } // namespace engine |
| 50 } // namespace blimp | 72 } // namespace blimp |
| 51 | 73 |
| 52 #endif // BLIMP_ENGINE_MOJO_BLOB_CHANNEL_SERVICE_H_ | 74 #endif // BLIMP_ENGINE_MOJO_BLOB_CHANNEL_SERVICE_H_ |
| OLD | NEW |