1 // Copyright (c) 2013 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.
5 #ifndef CONTENT_BROWSER_STREAMS_STREAM_REGISTRY_H_
6 #define CONTENT_BROWSER_STREAMS_STREAM_REGISTRY_H_
10 #include "base/basictypes.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/threading/non_thread_safe.h"
13 #include "content/common/content_export.h"
20 // Maintains a mapping of blob: URLs to active streams.
21 class CONTENT_EXPORT StreamRegistry
: public base::NonThreadSafe
{
24 virtual ~StreamRegistry();
26 // Registers a stream, and sets its URL.
27 void RegisterStream(scoped_refptr
<Stream
> stream
);
29 // Clones a stream. Returns true on success, or false if |src_url| doesn't
31 bool CloneStream(const GURL
& url
, const GURL
& src_url
);
33 void UnregisterStream(const GURL
& url
);
35 // Called by Stream instances to request increase of memory usage. If the
36 // total memory usage for this registry is going to exceed the limit,
37 // returns false. Otherwise, updates |total_memory_usage_| and returns true.
39 // |current_size| is the up-to-date size of ByteStream of the Stream instance
40 // and |increase| must be the amount of data going to be added to the Stream
42 bool UpdateMemoryUsage(const GURL
& url
, size_t current_size
, size_t increase
);
44 // Gets the stream associated with |url|. Returns NULL if there is no such
46 scoped_refptr
<Stream
> GetStream(const GURL
& url
);
48 void set_max_memory_usage_for_testing(size_t size
) {
49 max_memory_usage_
= size
;
53 typedef std::map
<GURL
, scoped_refptr
<Stream
> > StreamMap
;
57 size_t total_memory_usage_
;
59 // Maximum amount of memory allowed to use for Stream instances registered
60 // with this registry.
61 size_t max_memory_usage_
;
63 DISALLOW_COPY_AND_ASSIGN(StreamRegistry
);
66 } // namespace content
68 #endif // CONTENT_BROWSER_STREAMS_STREAM_REGISTRY_H_