OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef BLIMP_ENGINE_MOJO_BLOB_CHANNEL_SERVICE_H_ | |
6 #define BLIMP_ENGINE_MOJO_BLOB_CHANNEL_SERVICE_H_ | |
7 | |
8 #include <string> | |
9 #include <vector> | |
10 | |
11 #include "base/memory/weak_ptr.h" | |
12 #include "base/threading/thread_checker.h" | |
13 #include "blimp/engine/mojo/blob_channel.mojom.h" | |
14 #include "blimp/net/blob_channel/blob_channel_sender.h" | |
15 #include "mojo/public/cpp/bindings/binding_set.h" | |
16 | |
17 namespace blimp { | |
18 namespace engine { | |
19 | |
20 // Service for processing BlobChannel requests from the renderer. | |
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_|. | |
24 class BlobChannelService : public mojom::BlobChannel { | |
25 public: | |
26 // |blob_channel_sender|: The BlobChannelSender object which will receive | |
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); | |
33 | |
34 ~BlobChannelService() override; | |
35 | |
36 // Factory method called by Mojo. | |
37 // Binds |this| to the connection specified by |request|. | |
38 void BindRequest(mojo::InterfaceRequest<mojom::BlobChannel> request); | |
39 | |
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 | |
48 // BlobChannel implementation. | |
49 void GetCachedBlobIds( | |
50 const GetCachedBlobIdsCallback& response_callback) override; | |
51 void PutBlob(const std::string& id, | |
52 mojo::ScopedSharedBufferHandle data, | |
53 uint32_t size) override; | |
54 void DeliverBlob(const std::string& id) override; | |
55 | |
56 mojo::BindingSet<mojom::BlobChannel> bindings_; | |
57 | |
58 // Sender object which will receive the blobs passed over the Mojo service. | |
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_; | |
67 | |
68 DISALLOW_COPY_AND_ASSIGN(BlobChannelService); | |
69 }; | |
70 | |
71 } // namespace engine | |
72 } // namespace blimp | |
73 | |
74 #endif // BLIMP_ENGINE_MOJO_BLOB_CHANNEL_SERVICE_H_ | |
OLD | NEW |