Update broken references to image assets
[chromium-blink-merge.git] / chrome / browser / chromeos / policy / upload_job.h
blob9702d1299e08bff56e8addd7c4b5478f834defbc
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.
5 #ifndef CHROME_BROWSER_CHROMEOS_POLICY_UPLOAD_JOB_H_
6 #define CHROME_BROWSER_CHROMEOS_POLICY_UPLOAD_JOB_H_
8 #include <map>
9 #include <string>
11 #include "base/macros.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "url/gurl.h"
15 namespace policy {
17 class DataSegment;
19 // UploadJob can be used to upload screenshots and logfiles to the cloud.
20 // Data is uploaded via a POST request of type "multipart/form-data". The class
21 // relies on OAuth2TokenService to acquire an access token with a sufficient
22 // scope. Data segments can be added to the upload queue using AddDataSegment()
23 // and the upload is started by calling Start(). Calls to AddDataSegment() are
24 // only allowed prior to the first call to Start().
25 // An Upload instance may be destroyed at any point in time, the pending
26 // operations are guaranteed to be canceled and the Delegate::OnSuccess() and
27 // Delegate::OnFailure() methods will not be invoked.
28 class UploadJob {
29 public:
30 // If the upload fails, the Delegate's OnFailure() method is invoked with
31 // one of these error codes.
32 enum ErrorCode {
33 CONTENT_ENCODING_ERROR = 0, // Failed to encode content.
34 NETWORK_ERROR = 1, // Network failure.
35 AUTHENTICATION_ERROR = 2, // Authentication failure.
36 SERVER_ERROR = 3 // Server returned error or malformed reply.
39 class Delegate {
40 public:
41 // When the upload finishes successfully, the OnSuccess() method is invoked.
42 virtual void OnSuccess() = 0;
44 // On upload failure, the OnFailure() method is invoked with an ErrorCode
45 // indicating the reason for failure.
46 virtual void OnFailure(ErrorCode error_code) = 0;
48 protected:
49 virtual ~Delegate();
51 private:
52 DISALLOW_ASSIGN(Delegate);
55 virtual ~UploadJob() {}
57 // Adds one data segment to the UploadJob. A DataSegment corresponds
58 // to one "Content-Disposition" in the "multipart" request. As per RFC 2388,
59 // each content-disposition has a |name| field, which must be unique within a
60 // given request. For file uploads the original local file name may be
61 // supplied as well as in the |filename| field. If |filename| references an
62 // empty string, no |filename| header will be added for this data segment.
63 // This method must not be called on an UploadJob instance which is already
64 // uploading.
65 virtual void AddDataSegment(
66 const std::string& name,
67 const std::string& filename,
68 const std::map<std::string, std::string>& header_entries,
69 scoped_ptr<std::string> data) = 0;
71 // Initiates the data upload . This method must only be called once.
72 virtual void Start() = 0;
74 DISALLOW_ASSIGN(UploadJob);
77 } // namespace policy
79 #endif // CHROME_BROWSER_CHROMEOS_POLICY_UPLOAD_JOB_H_