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_RENDERER_BLOB_CHANNEL_SENDER_PROXY_H_ | 5 #ifndef BLIMP_ENGINE_RENDERER_BLOB_CHANNEL_SENDER_PROXY_H_ |
6 #define BLIMP_ENGINE_RENDERER_BLOB_CHANNEL_SENDER_PROXY_H_ | 6 #define BLIMP_ENGINE_RENDERER_BLOB_CHANNEL_SENDER_PROXY_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
| 10 #include <vector> |
10 | 11 |
11 #include "base/containers/hash_tables.h" | 12 #include "base/containers/hash_tables.h" |
| 13 #include "base/memory/weak_ptr.h" |
12 #include "blimp/common/blimp_common_export.h" | 14 #include "blimp/common/blimp_common_export.h" |
13 #include "blimp/engine/mojo/blob_channel.mojom.h" | 15 #include "blimp/engine/mojo/blob_channel.mojom.h" |
14 #include "blimp/net/blob_channel/blob_channel_sender.h" | 16 #include "blimp/net/blob_channel/blob_channel_sender.h" |
15 | 17 |
16 namespace blimp { | 18 namespace blimp { |
17 namespace engine { | 19 namespace engine { |
18 | 20 |
19 // Class for sending blobs (e.g. images) from the renderer to the browser | 21 // Class for sending blobs (e.g. images) from the renderer to the browser |
20 // process. | 22 // process. |
21 class BLIMP_COMMON_EXPORT BlobChannelSenderProxy : public BlobChannelSender { | 23 class BLIMP_COMMON_EXPORT BlobChannelSenderProxy : public BlobChannelSender { |
22 public: | 24 public: |
| 25 // Asynchronously request the set of cache keys from the browser process. |
| 26 // Knowledge of the browser's cache allows the renderer to avoid re-encoding |
| 27 // and re-transferring image assets that are already tracked by the |
| 28 // browser-side cache. |
| 29 // |
| 30 // If |this| is used in the brief time before the response arrives, |
| 31 // the object will continue to work, but false negatives will be returned |
| 32 // for IsInEngineCache() and IsInClientCache(). |
23 BlobChannelSenderProxy(); | 33 BlobChannelSenderProxy(); |
24 ~BlobChannelSenderProxy() override; | 34 ~BlobChannelSenderProxy() override; |
25 | 35 |
26 // Returns true if the blob is known to exist within the Engine cache. | 36 // Returns true if the blob is known to exist within the Engine cache. |
27 bool IsInEngineCache(const std::string& id) const; | 37 bool IsInEngineCache(const std::string& id) const; |
28 | 38 |
29 // Returns true if the blob has been delivered to the Client cache. | 39 // Returns true if the blob has been delivered to the Client cache. |
30 bool IsInClientCache(const std::string& id) const; | 40 bool IsInClientCache(const std::string& id) const; |
31 | 41 |
32 // BlobChannelSender implementation. | 42 // BlobChannelSender implementation. |
| 43 std::vector<CacheStateEntry> GetCachedBlobIds() const override; |
33 void PutBlob(const BlobId& id, BlobDataPtr data) override; | 44 void PutBlob(const BlobId& id, BlobDataPtr data) override; |
34 void DeliverBlob(const BlobId& id) override; | 45 void DeliverBlob(const BlobId& id) override; |
35 | 46 |
36 private: | 47 private: |
| 48 void OnGetCacheStateComplete(mojo::Map<mojo::String, bool> cache_state); |
| 49 |
37 // BlobChannel Mojo IPC stub, used for delivering blobs to the browser | 50 // BlobChannel Mojo IPC stub, used for delivering blobs to the browser |
38 // process. | 51 // process. |
39 mojom::BlobChannelPtr blob_channel_; | 52 mojom::BlobChannelPtr blob_channel_; |
40 | 53 |
41 // Local copy of the cache state for the local and remote BlobChannel. | 54 // Local copy of the cache state for the local and remote BlobChannel. |
42 // Knowledge of the cache state enables callers to avoid unnecessary | 55 // Knowledge of the cache state enables callers to avoid unnecessary |
43 // image encoding and transferral if the content is already in the system. | 56 // image encoding and transferral if the content is already in the system. |
44 base::hash_map<std::string, bool> replication_state_; | 57 base::hash_map<std::string, bool> replication_state_; |
45 | 58 |
| 59 base::WeakPtrFactory<BlobChannelSenderProxy> weak_factory_; |
| 60 |
46 DISALLOW_COPY_AND_ASSIGN(BlobChannelSenderProxy); | 61 DISALLOW_COPY_AND_ASSIGN(BlobChannelSenderProxy); |
47 }; | 62 }; |
48 | 63 |
49 } // namespace engine | 64 } // namespace engine |
50 } // namespace blimp | 65 } // namespace blimp |
51 | 66 |
52 #endif // BLIMP_ENGINE_RENDERER_BLOB_CHANNEL_SENDER_PROXY_H_ | 67 #endif // BLIMP_ENGINE_RENDERER_BLOB_CHANNEL_SENDER_PROXY_H_ |
OLD | NEW |