Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(527)

Side by Side Diff: media/blink/url_index.h

Issue 1165903002: Multi reader/writer cache/buffer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more tests Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 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 MEDIA_BLINK_URL_INDEX_H_
6 #define MEDIA_BLINK_URL_INDEX_H_
7
8 #include <map>
9 #include <vector>
10 #include "base/memory/ref_counted.h"
11 #include "base/threading/thread_checker.h"
12 #include "media/blink/lru.h"
13 #include "url/gurl.h"
14
15 namespace media {
16
17 #ifndef MEDIA_BLINK_BUFFERED_RESOURCE_LOADER_H_
18 const int64 kPositionNotSpecified = -1;
19 #endif
20
21 class UrlIndex;
22
23 class UrlData : public base::RefCounted<UrlData> {
24 public:
25 // Keep in sync with WebMediaPlayer::CORSMode.
26 enum CORSMode { kUnspecified, kAnonymous, kUseCredentials };
27 typedef std::pair<GURL, CORSMode> KeyType;
28
29 const GURL url() const { return url_; }
30 const GURL redirects_to() const { return redirects_to_; }
31 CORSMode cors_mode() const { return cors_mode_; }
32 bool range_supported() const { return range_supported_; }
33 bool cacheable() const { return cacheable_; }
34 base::TimeTicks last_used() const { return last_used_; }
35 base::Time last_modified() const { return last_modified_; }
36 base::TimeTicks valid_until() const { return valid_until_; }
37 KeyType key() const;
38
39 // Notifies the url index that this is currently used.
40 // The URL will get a new ID if this is not called
41 // regularly.
42 void Use();
43
44 // Length of data associated with url or |kPositionNotSpecified|
45 int64 length() const { return length_; }
46
47 // DO NOT call this function unless the redirect is to the same
48 // origin or a CORS check has been performed.
49 void set_redirects_to(const GURL& url);
50
51 void set_range_supported();
52 void set_length(int64 length);
53 void set_cacheable(bool cacheable);
54 void set_valid_until(base::TimeTicks t);
55
56 // Set the last_modified time on |urldata|. This also allows the url
57 // index to re-use previously expired UrlData instances. If such
58 // an instance is discovered, it is returned, otherwise |urldata|
59 // is returned.
60 scoped_refptr<UrlData> set_last_modified(base::Time last_modified);
61
62 // Returns true it is valid to keep using this to access cached data.
63 // A single media player instance may choose to ignore this for resources
64 // that have already been opened.
65 bool Valid() const;
66
67 private:
68 friend class UrlIndex;
69 friend class RefCounted<UrlData>;
70
71 ~UrlData();
72 UrlData(const GURL& url,
73 CORSMode cors_mode_,
74 UrlIndex* url_index_);
75 void set_last_modified_internal(base::Time t);
76 void DisconnectFromIndex();
77
78 const GURL url_;
79 const CORSMode cors_mode_;
80
81 GURL redirects_to_;
82 int64 length_;
83 bool range_supported_;
84 bool cacheable_;
85
86 base::TimeTicks last_used_;
87 base::TimeTicks valid_until_;
88 base::Time last_modified_;
89
90 base::ThreadChecker thread_checker_;
91 UrlIndex* url_index_;
92 DISALLOW_COPY_AND_ASSIGN(UrlData);
93 };
94
95 // The UrlIndex lets you look up UrlData instances by url.
96 // It keeps a weak reference to UrlData that it has returned.
liberato (no reviews please) 2015/10/09 17:36:10 i don't see any weak references.
hubbe 2015/10/13 23:08:17 Discussed offline.
97 // Since the multibuffer cache key contains an UrlData reference
98 // we can be sure that UrlData instances with zero references
99 // do not have any cached data associated with them, and they
100 // can safely be removed from the UrlIndex.
101 class UrlIndex {
102 public:
103 UrlIndex();
104 ~UrlIndex();
105 // Creates a new UrlData if not found.
106 // |last_modified| may be null if not known.
107 // Normally you'll want to call Use() on the returned object right away.
108 scoped_refptr<UrlData> GetByUrl(const GURL& gurl,
109 UrlData::CORSMode cors_mode);
110
111
112 private:
113 friend class UrlData;
114 void RemoveUrlData(const UrlData* url_data);
115 // TODO(hubbe): Add support for etag validation.
116 scoped_refptr<UrlData> SetLastModified(scoped_refptr<UrlData> urldata,
117 base::Time last_modified);
118
119 std::map<UrlData::KeyType, UrlData*> by_url_;
120 std::map<UrlData::KeyType, UrlData*> with_last_modified_;
121 std::list<scoped_refptr<UrlData> > to_prune_;
122 bool prune_cb_active_;
123 };
124
125 } // namespace media
126 #endif // MEDIA_BLINK_URL_INDEX_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698