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

Side by Side Diff: net/http/http_cache_data_access.h

Issue 2519473002: Fixes the cache lock issue. (Closed)
Patch Set: Redesigned the fix using DataAccess class for eliminating Orphan API.(Rebased till refs/heads/master@{#442607}) Created 3 years, 11 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 (c) 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 NET_HTTP_HTTP_CACHE_DATA_ACCESS_H_
6 #define NET_HTTP_HTTP_CACHE_DATA_ACCESS_H_
7
8 #include <net/http/http_cache.h>
9 #include <memory>
10
11 namespace net {
12
13 // This class encapsulates the functionality for reading from the
14 // network and writing to the cache. It acts as a helper class to its consumers,
15 // which are currently HttpCache::Transaction and HttpCache::SharedWriters.
16 //
17 // Having the functionality separated in this helper class allows the DataAccess
18 // object to out-live its consumer transaction object. Thus the network
19 // transaction can out-live its original creator transaction. This is required
20 // for cases where the network transaction is being shared across multiple
21 // HttpCache::Transactions. For this reason this class should not contain
22 // any specific cache transaction's information.
23 //
24 // Its ownership might be transferred from an HttpCache::Transaction to
25 // HttpCache::SharedWriters for shared writing. The ownership can also be
26 // transferred back in some failure cases when we can no longer continue with
27 // shared writing e.g. cache access failure.
28 class HttpCache::DataAccess {
29 public:
30 DataAccess(std::unique_ptr<HttpTransaction> network_transaction,
31 ActiveEntry* entry);
Randy Smith (Not in Mondays) 2017/01/19 00:53:42 I think it's important to document the lifetime re
shivanisha 2017/01/25 19:46:13 N/A here since DataAccess class no longer exists.
32 ~DataAccess();
33 int Read(scoped_refptr<IOBuffer> buf,
34 int buf_len,
35 const CompletionCallback& callback);
36 int CacheWrite(scoped_refptr<IOBuffer> buf,
37 int write_len,
38 const CompletionCallback& callback);
39
40 // Called to signal completion of asynchronous IO.
41 void OnIOComplete(int result);
42
43 friend class Transaction;
44 friend class SharedWriters;
45
46 private:
47 enum State {
48 STATE_NONE,
49 STATE_NETWORK_READ,
50 STATE_NETWORK_READ_COMPLETE,
51 STATE_CACHE_WRITE_DATA,
52 STATE_CACHE_WRITE_DATA_COMPLETE,
53 };
54
55 int DoLoop(int result);
56 int DoNetworkRead();
57 int DoNetworkReadComplete(int result);
58 int DoCacheWriteData(int num_bytes);
59 int DoCacheWriteDataComplete(int result);
60
61 State next_state_ = STATE_NONE;
62 CompletionCallback callback_; // Consumer's callback.
63 std::unique_ptr<HttpTransaction> network_transaction_;
64 CompletionCallback io_callback_;
Randy Smith (Not in Mondays) 2017/01/19 00:53:42 Suggestion: This is currently set in the construct
shivanisha 2017/01/25 19:46:13 N/A since DataAccess class no longer exists.
65 scoped_refptr<IOBuffer> read_buf_;
66 int io_buf_len_ = 0;
67 int write_len_ = 0;
68 ActiveEntry* entry_ = nullptr;
69 base::WeakPtrFactory<DataAccess> weak_factory_;
70
71 DISALLOW_COPY_AND_ASSIGN(DataAccess);
72 };
73
74 } // namespace net
75
76 #endif // NET_HTTP_HTTP_CACHE_DATA_ACCESS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698