Use multiline attribute to check for IA2_STATE_MULTILINE.
[chromium-blink-merge.git] / content / browser / streams / stream_registry.h
blob05c53100f04896f23d7a69a4550d7e02b49b7e11
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_
8 #include <map>
9 #include <set>
11 #include "base/basictypes.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/threading/non_thread_safe.h"
14 #include "content/browser/streams/stream_register_observer.h"
15 #include "content/common/content_export.h"
16 #include "url/gurl.h"
18 namespace content {
20 class Stream;
22 // Maintains a mapping of blob: URLs to active streams.
23 class CONTENT_EXPORT StreamRegistry : public base::NonThreadSafe {
24 public:
25 StreamRegistry();
26 virtual ~StreamRegistry();
28 // Registers a stream, and sets its URL.
29 void RegisterStream(Stream* stream);
31 // Clones a stream. Returns true on success, or false if |src_url| doesn't
32 // exist.
33 bool CloneStream(const GURL& url, const GURL& src_url);
35 void UnregisterStream(const GURL& url);
37 // Called by Stream instances to request increase of memory usage. If the
38 // total memory usage for this registry is going to exceed the limit,
39 // returns false. Otherwise, updates |total_memory_usage_| and returns true.
41 // |current_size| is the up-to-date size of ByteStream of the Stream instance
42 // and |increase| must be the amount of data going to be added to the Stream
43 // instance.
44 bool UpdateMemoryUsage(const GURL& url, size_t current_size, size_t increase);
46 // Gets the stream associated with |url|. Returns NULL if there is no such
47 // stream.
48 scoped_refptr<Stream> GetStream(const GURL& url);
50 void set_max_memory_usage_for_testing(size_t size) {
51 max_memory_usage_ = size;
54 void SetRegisterObserver(const GURL& url, StreamRegisterObserver* observer);
55 void RemoveRegisterObserver(const GURL& url);
57 // If the reader is aborted before the stream is registered, call this method
58 // to reduce the memory consumption. After this method is called,
59 // RegisterStream doesn't register the stream of the URL.
60 void AbortPendingStream(const GURL& url);
62 private:
63 typedef std::map<GURL, scoped_refptr<Stream> > StreamMap;
65 StreamMap streams_;
66 std::map<GURL, StreamRegisterObserver*> register_observers_;
67 std::set<GURL> reader_aborted_urls_;
69 size_t total_memory_usage_;
71 // Maximum amount of memory allowed to use for Stream instances registered
72 // with this registry.
73 size_t max_memory_usage_;
75 DISALLOW_COPY_AND_ASSIGN(StreamRegistry);
78 } // namespace content
80 #endif // CONTENT_BROWSER_STREAMS_STREAM_REGISTRY_H_