OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 WEBKIT_GLUE_RESOURCE_REQUEST_BODY_H_ | 5 #ifndef WEBKIT_COMMON_RESOURCE_REQUEST_BODY_H_ |
6 #define WEBKIT_GLUE_RESOURCE_REQUEST_BODY_H_ | 6 #define WEBKIT_COMMON_RESOURCE_REQUEST_BODY_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/supports_user_data.h" | 12 #include "base/supports_user_data.h" |
| 13 #include "googleurl/src/gurl.h" |
13 #include "webkit/base/data_element.h" | 14 #include "webkit/base/data_element.h" |
14 #include "webkit/glue/webkit_glue_export.h" | 15 #include "webkit/common/webkit_common_export.h" |
15 | 16 |
16 namespace base { | 17 namespace base { |
17 class FilePath; | 18 class FilePath; |
18 class TaskRunner; | |
19 } | |
20 | |
21 namespace fileapi { | |
22 class FileSystemContext; | |
23 } | |
24 | |
25 namespace net { | |
26 class UploadDataStream; | |
27 } | |
28 | |
29 namespace webkit_blob { | |
30 class BlobStorageController; | |
31 } | 19 } |
32 | 20 |
33 namespace webkit_glue { | 21 namespace webkit_glue { |
34 | 22 |
35 // A struct used to represent upload data. The data field is populated by | 23 // A struct used to represent upload data. The data field is populated by |
36 // WebURLLoader from the data given as WebHTTPBody. | 24 // WebURLLoader from the data given as WebHTTPBody. |
37 class WEBKIT_GLUE_EXPORT ResourceRequestBody | 25 class WEBKIT_COMMON_EXPORT ResourceRequestBody |
38 : public base::RefCounted<ResourceRequestBody>, | 26 : public base::RefCounted<ResourceRequestBody>, |
39 public base::SupportsUserData { | 27 public base::SupportsUserData { |
40 public: | 28 public: |
41 typedef webkit_base::DataElement Element; | 29 typedef webkit_base::DataElement Element; |
42 | 30 |
43 ResourceRequestBody(); | 31 ResourceRequestBody(); |
44 | 32 |
45 void AppendBytes(const char* bytes, int bytes_len); | 33 void AppendBytes(const char* bytes, int bytes_len); |
46 void AppendFileRange(const base::FilePath& file_path, | 34 void AppendFileRange(const base::FilePath& file_path, |
47 uint64 offset, uint64 length, | 35 uint64 offset, uint64 length, |
48 const base::Time& expected_modification_time); | 36 const base::Time& expected_modification_time); |
49 void AppendBlob(const GURL& blob_url); | 37 void AppendBlob(const GURL& blob_url); |
50 void AppendFileSystemFileRange(const GURL& url, uint64 offset, uint64 length, | 38 void AppendFileSystemFileRange(const GURL& url, uint64 offset, uint64 length, |
51 const base::Time& expected_modification_time); | 39 const base::Time& expected_modification_time); |
52 | 40 |
53 // Creates a new UploadDataStream from this request body. This also resolves | |
54 // any blob references using given |blob_controller|. |file_system_context| is | |
55 // used to create FileStreamReader for files with filesystem URLs. | |
56 // |file_task_runner| is used to perform file operations when the data gets | |
57 // uploaded. | |
58 net::UploadDataStream* ResolveElementsAndCreateUploadDataStream( | |
59 webkit_blob::BlobStorageController* blob_controller, | |
60 fileapi::FileSystemContext* file_system_context, | |
61 base::TaskRunner* file_task_runner); | |
62 | |
63 const std::vector<Element>* elements() const { return &elements_; } | 41 const std::vector<Element>* elements() const { return &elements_; } |
64 std::vector<Element>* elements_mutable() { return &elements_; } | 42 std::vector<Element>* elements_mutable() { return &elements_; } |
65 void swap_elements(std::vector<Element>* elements) { | 43 void swap_elements(std::vector<Element>* elements) { |
66 elements_.swap(*elements); | 44 elements_.swap(*elements); |
67 } | 45 } |
68 | 46 |
69 // Identifies a particular upload instance, which is used by the cache to | 47 // Identifies a particular upload instance, which is used by the cache to |
70 // formulate a cache key. This value should be unique across browser | 48 // formulate a cache key. This value should be unique across browser |
71 // sessions. A value of 0 is used to indicate an unspecified identifier. | 49 // sessions. A value of 0 is used to indicate an unspecified identifier. |
72 void set_identifier(int64 id) { identifier_ = id; } | 50 void set_identifier(int64 id) { identifier_ = id; } |
73 int64 identifier() const { return identifier_; } | 51 int64 identifier() const { return identifier_; } |
74 | 52 |
75 private: | 53 private: |
76 friend class base::RefCounted<ResourceRequestBody>; | 54 friend class base::RefCounted<ResourceRequestBody>; |
77 virtual ~ResourceRequestBody(); | 55 virtual ~ResourceRequestBody(); |
78 | 56 |
79 // Resolves the |blob_url| using |blob_controller| and appends resolved | |
80 // items to |resolved_elements|. | |
81 void ResolveBlobReference(webkit_blob::BlobStorageController* blob_controller, | |
82 const GURL& blob_url, | |
83 std::vector<const Element*>* resolved_elements); | |
84 | |
85 std::vector<Element> elements_; | 57 std::vector<Element> elements_; |
86 int64 identifier_; | 58 int64 identifier_; |
87 | 59 |
88 DISALLOW_COPY_AND_ASSIGN(ResourceRequestBody); | 60 DISALLOW_COPY_AND_ASSIGN(ResourceRequestBody); |
89 }; | 61 }; |
90 | 62 |
91 } // namespace webkit_glue | 63 } // namespace webkit_glue |
92 | 64 |
93 #endif // WEBKIT_GLUE_RESOURCE_REQUEST_BODY_H_ | 65 #endif // WEBKIT_GLUE_RESOURCE_REQUEST_BODY_H_ |
OLD | NEW |