Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 CHROME_BROWSER_CHROMEOS_POLICY_UPLOAD_JOB_IMPL_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_POLICY_UPLOAD_JOB_IMPL_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_POLICY_UPLOAD_JOB_IMPL_H_ | 6 #define CHROME_BROWSER_CHROMEOS_POLICY_UPLOAD_JOB_IMPL_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 59 | 59 |
| 60 // UploadJob: | 60 // UploadJob: |
| 61 void AddDataSegment(const std::string& name, | 61 void AddDataSegment(const std::string& name, |
| 62 const std::string& filename, | 62 const std::string& filename, |
| 63 const std::map<std::string, std::string>& header_entries, | 63 const std::map<std::string, std::string>& header_entries, |
| 64 std::unique_ptr<std::string> data) override; | 64 std::unique_ptr<std::string> data) override; |
| 65 void Start() override; | 65 void Start() override; |
| 66 | 66 |
| 67 private: | 67 private: |
| 68 // Indicates the current state of the UploadJobImpl. | 68 // Indicates the current state of the UploadJobImpl. |
| 69 // State transitions for successful upload: | |
| 70 // IDLE -> ACQUIRING_TOKEN -> PREPARING_CONTENT -> UPLOADING -> SUCCESS | |
| 71 // If error happens, state goes back to ACQUIRING_TOKEN | |
| 72 // State transitions when error occurs once: | |
| 73 // IDLE -> ACQUIRING_TOKEN -> PREPARING_CONTENT -> UPLOADING -> | |
| 74 // -> ACQUIRING_TOKEN -> PREPARING_CONTENT -> UPLOADING -> SUCCESS | |
| 75 // State transitions when tried unsuccessfully kMaxRetries times: | |
| 76 // ... -> PPREPARING_CONTENT -> UPLOADING -> ERROR | |
|
Andrew T Wilson (Slow)
2016/04/08 15:42:56
nit: PPREPARING->PREPARING
Marton Hunyady
2016/04/08 16:47:46
Done.
| |
| 69 enum State { | 77 enum State { |
| 70 IDLE, // Start() has not been called. | 78 IDLE, // Start() has not been called. |
| 71 ACQUIRING_TOKEN, // Trying to acquire the access token. | 79 ACQUIRING_TOKEN, // Trying to acquire the access token. |
| 72 PREPARING_CONTENT, // Currently encoding the content. | 80 PREPARING_CONTENT, // Currently encoding the content. |
| 73 UPLOADING, // Upload started. | 81 UPLOADING, // Upload started. |
| 74 SUCCESS, // Upload successfully completed. | 82 SUCCESS, // Upload successfully completed. |
| 75 ERROR // Upload failed. | 83 ERROR // Upload failed. |
| 76 }; | 84 }; |
| 77 | 85 |
| 78 // OAuth2TokenService::Consumer: | 86 // OAuth2TokenService::Consumer: |
| 79 void OnGetTokenSuccess(const OAuth2TokenService::Request* request, | 87 void OnGetTokenSuccess(const OAuth2TokenService::Request* request, |
| 80 const std::string& access_token, | 88 const std::string& access_token, |
| 81 const base::Time& expiration_time) override; | 89 const base::Time& expiration_time) override; |
| 82 void OnGetTokenFailure(const OAuth2TokenService::Request* request, | 90 void OnGetTokenFailure(const OAuth2TokenService::Request* request, |
| 83 const GoogleServiceAuthError& error) override; | 91 const GoogleServiceAuthError& error) override; |
| 84 | 92 |
| 85 // net::URLFetcherDelegate: | 93 // net::URLFetcherDelegate: |
| 86 void OnURLFetchComplete(const net::URLFetcher* source) override; | 94 void OnURLFetchComplete(const net::URLFetcher* source) override; |
| 87 | 95 |
| 96 void HandleError(ErrorCode errorCode); | |
| 97 | |
| 88 // Requests an access token for the upload scope. | 98 // Requests an access token for the upload scope. |
| 89 void RequestAccessToken(); | 99 void RequestAccessToken(); |
| 90 | 100 |
| 91 // Dispatches POST request to URLFetcher. | 101 // Dispatches POST request to URLFetcher. |
| 92 void StartUpload(const std::string& access_token); | 102 void StartUpload(const std::string& access_token); |
| 93 | 103 |
| 94 // Constructs the body of the POST request by concatenating the | 104 // Constructs the body of the POST request by concatenating the |
| 95 // |data_segments_|, separated by appropriate content-disposition headers and | 105 // |data_segments_|, separated by appropriate content-disposition headers and |
| 96 // a MIME boundary. Places the request body in |post_data_| and a copy of the | 106 // a MIME boundary. Places the request body in |post_data_| and a copy of the |
| 97 // MIME boundary in |mime_boundary_|. Returns true on success. If |post_data_| | 107 // MIME boundary in |mime_boundary_|. Returns true on success. If |post_data_| |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 146 | 156 |
| 147 // The data chunks to be uploaded. | 157 // The data chunks to be uploaded. |
| 148 ScopedVector<DataSegment> data_segments_; | 158 ScopedVector<DataSegment> data_segments_; |
| 149 | 159 |
| 150 DISALLOW_COPY_AND_ASSIGN(UploadJobImpl); | 160 DISALLOW_COPY_AND_ASSIGN(UploadJobImpl); |
| 151 }; | 161 }; |
| 152 | 162 |
| 153 } // namespace policy | 163 } // namespace policy |
| 154 | 164 |
| 155 #endif // CHROME_BROWSER_CHROMEOS_POLICY_UPLOAD_JOB_IMPL_H_ | 165 #endif // CHROME_BROWSER_CHROMEOS_POLICY_UPLOAD_JOB_IMPL_H_ |
| OLD | NEW |