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
3 // found in the LICENSE file.
5 #ifndef WEBKIT_GLUE_RESOURCE_REQUEST_BODY_H_
6 #define WEBKIT_GLUE_RESOURCE_REQUEST_BODY_H_
10 #include "base/basictypes.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/supports_user_data.h"
13 #include "webkit/base/data_element.h"
14 #include "webkit/glue/webkit_glue_export.h"
22 class FileSystemContext
;
26 class UploadDataStream
;
29 namespace webkit_blob
{
30 class BlobStorageController
;
33 namespace webkit_glue
{
35 // A struct used to represent upload data. The data field is populated by
36 // WebURLLoader from the data given as WebHTTPBody.
37 class WEBKIT_GLUE_EXPORT ResourceRequestBody
38 : public base::RefCounted
<ResourceRequestBody
>,
39 public base::SupportsUserData
{
41 typedef webkit_base::DataElement Element
;
43 ResourceRequestBody();
45 void AppendBytes(const char* bytes
, int bytes_len
);
46 void AppendFileRange(const base::FilePath
& file_path
,
47 uint64 offset
, uint64 length
,
48 const base::Time
& expected_modification_time
);
49 void AppendBlob(const GURL
& blob_url
);
50 void AppendFileSystemFileRange(const GURL
& url
, uint64 offset
, uint64 length
,
51 const base::Time
& expected_modification_time
);
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
58 net::UploadDataStream
* ResolveElementsAndCreateUploadDataStream(
59 webkit_blob::BlobStorageController
* blob_controller
,
60 fileapi::FileSystemContext
* file_system_context
,
61 base::TaskRunner
* file_task_runner
);
63 const std::vector
<Element
>* elements() const { return &elements_
; }
64 std::vector
<Element
>* elements_mutable() { return &elements_
; }
65 void swap_elements(std::vector
<Element
>* elements
) {
66 elements_
.swap(*elements
);
69 // Identifies a particular upload instance, which is used by the cache to
70 // formulate a cache key. This value should be unique across browser
71 // sessions. A value of 0 is used to indicate an unspecified identifier.
72 void set_identifier(int64 id
) { identifier_
= id
; }
73 int64
identifier() const { return identifier_
; }
76 friend class base::RefCounted
<ResourceRequestBody
>;
77 virtual ~ResourceRequestBody();
79 // Resolves the |blob_url| using |blob_controller| and appends resolved
80 // items to |resolved_elements|.
81 void ResolveBlobReference(webkit_blob::BlobStorageController
* blob_controller
,
83 std::vector
<const Element
*>* resolved_elements
);
85 std::vector
<Element
> elements_
;
88 DISALLOW_COPY_AND_ASSIGN(ResourceRequestBody
);
91 } // namespace webkit_glue
93 #endif // WEBKIT_GLUE_RESOURCE_REQUEST_BODY_H_