OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 NET_DISK_CACHE_NET_LOG_PARAMETERS_H_ | 5 #ifndef NET_DISK_CACHE_NET_LOG_PARAMETERS_H_ |
6 #define NET_DISK_CACHE_NET_LOG_PARAMETERS_H_ | 6 #define NET_DISK_CACHE_NET_LOG_PARAMETERS_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "net/base/net_log.h" | 11 #include "net/base/net_log.h" |
12 | 12 |
13 // This file contains a set of NetLog::EventParameters shared by EntryImpls and | 13 // This file contains a set of functions to create NetLog::ParametersCallbacks |
14 // MemEntryImpls. | 14 // shared by EntryImpls and MemEntryImpls. |
15 namespace disk_cache { | 15 namespace disk_cache { |
16 | 16 |
17 // NetLog parameters for the creation of an Entry. Contains the Entry's name | 17 class Entry; |
18 // and whether it was created or opened. | |
19 class EntryCreationParameters : public net::NetLog::EventParameters { | |
20 public: | |
21 EntryCreationParameters(const std::string& key, bool created); | |
22 virtual base::Value* ToValue() const OVERRIDE; | |
23 | 18 |
24 protected: | 19 // Creates a NetLog callback that returns parameters for the creation of an |
25 virtual ~EntryCreationParameters(); | 20 // Entry. Contains the Entry's key and whether it was created or opened. |
| 21 // |entry| can't be NULL, must support GetKey(), and must outlive the returned |
| 22 // callback. |
| 23 net::NetLog::ParametersCallback CreateNetLogEntryCreationCallback( |
| 24 const Entry* entry, |
| 25 bool created); |
26 | 26 |
27 private: | 27 // Creates a NetLog callback that returns parameters for start of a non-sparse |
28 const std::string key_; | 28 // read or write of an Entry. For reads, |truncate| must be false. |
29 const bool created_; | 29 net::NetLog::ParametersCallback CreateNetLogReadWriteDataCallback( |
| 30 int index, |
| 31 int offset, |
| 32 int buf_len, |
| 33 bool truncate); |
30 | 34 |
31 DISALLOW_COPY_AND_ASSIGN(EntryCreationParameters); | 35 // Creates a NetLog callback that returns parameters for when a non-sparse |
32 }; | 36 // read or write completes. For reads, |truncate| must be false. |
| 37 // |bytes_copied| is either the number of bytes copied or a network error |
| 38 // code. |bytes_copied| must not be ERR_IO_PENDING, as it's not a valid |
| 39 // result for an operation. |
| 40 net::NetLog::ParametersCallback CreateNetLogReadWriteCompleteCallback( |
| 41 int bytes_copied); |
33 | 42 |
34 // NetLog parameters for non-sparse reading and writing to an Entry. | 43 // Creates a NetLog callback that returns parameters for when a sparse |
35 class ReadWriteDataParameters : public net::NetLog::EventParameters { | 44 // operation is started. |
36 public: | 45 net::NetLog::ParametersCallback CreateNetLogSparseOperationCallback( |
37 // For reads, |truncate| must be false. | 46 int64 offset, |
38 ReadWriteDataParameters(int index, int offset, int buf_len, bool truncate); | 47 int buff_len); |
39 virtual base::Value* ToValue() const OVERRIDE; | |
40 | 48 |
41 protected: | 49 // Creates a NetLog callback that returns parameters for when a read or write |
42 virtual ~ReadWriteDataParameters(); | 50 // for a sparse entry's child is started. |
| 51 net::NetLog::ParametersCallback CreateNetLogSparseReadWriteCallback( |
| 52 const net::NetLog::Source& source, |
| 53 int child_len); |
43 | 54 |
44 private: | 55 // Creates a NetLog callback that returns parameters for when a call to |
45 const int index_; | 56 // GetAvailableRange returns. |
46 const int offset_; | 57 net::NetLog::ParametersCallback CreateNetLogGetAvailableRangeResultCallback( |
47 const int buf_len_; | 58 int64 start, |
48 const bool truncate_; | 59 int result); |
49 | |
50 DISALLOW_COPY_AND_ASSIGN(ReadWriteDataParameters); | |
51 }; | |
52 | |
53 // NetLog parameters for when a non-sparse read or write completes. | |
54 class ReadWriteCompleteParameters : public net::NetLog::EventParameters { | |
55 public: | |
56 // |bytes_copied| is either the number of bytes copied or a network error | |
57 // code. |bytes_copied| must not be ERR_IO_PENDING, as it's not a valid | |
58 // result for an operation. | |
59 explicit ReadWriteCompleteParameters(int bytes_copied); | |
60 virtual base::Value* ToValue() const OVERRIDE; | |
61 | |
62 protected: | |
63 virtual ~ReadWriteCompleteParameters(); | |
64 | |
65 private: | |
66 const int bytes_copied_; | |
67 | |
68 DISALLOW_COPY_AND_ASSIGN(ReadWriteCompleteParameters); | |
69 }; | |
70 | |
71 // NetLog parameters for when a sparse operation is started. | |
72 class SparseOperationParameters : public net::NetLog::EventParameters { | |
73 public: | |
74 SparseOperationParameters(int64 offset, int buff_len); | |
75 virtual base::Value* ToValue() const OVERRIDE; | |
76 | |
77 protected: | |
78 virtual ~SparseOperationParameters(); | |
79 | |
80 private: | |
81 const int64 offset_; | |
82 const int buff_len_; | |
83 }; | |
84 | |
85 // NetLog parameters for when a read or write for a sparse entry's child is | |
86 // started. | |
87 class SparseReadWriteParameters : public net::NetLog::EventParameters { | |
88 public: | |
89 SparseReadWriteParameters(const net::NetLog::Source& source, int child_len); | |
90 virtual base::Value* ToValue() const OVERRIDE; | |
91 | |
92 protected: | |
93 virtual ~SparseReadWriteParameters(); | |
94 | |
95 private: | |
96 const net::NetLog::Source source_; | |
97 const int child_len_; | |
98 }; | |
99 | |
100 // NetLog parameters for when a call to GetAvailableRange returns. | |
101 class GetAvailableRangeResultParameters : public net::NetLog::EventParameters { | |
102 public: | |
103 // |start| is ignored when |result| < 0. | |
104 GetAvailableRangeResultParameters(int64 start, int result); | |
105 virtual base::Value* ToValue() const OVERRIDE; | |
106 | |
107 protected: | |
108 virtual ~GetAvailableRangeResultParameters(); | |
109 | |
110 private: | |
111 const int64 start_; | |
112 const int result_; | |
113 }; | |
114 | 60 |
115 } // namespace disk_cache | 61 } // namespace disk_cache |
116 | 62 |
117 #endif // NET_DISK_CACHE_NET_LOG_CACHE_PARAMETERS_H_ | 63 #endif // NET_DISK_CACHE_NET_LOG_CACHE_PARAMETERS_H_ |
OLD | NEW |