| OLD | NEW |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 #include "chrome/browser/chromeos/policy/upload_job_impl.h" | 5 #include "chrome/browser/chromeos/policy/upload_job_impl.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <utility> |
| 8 | 9 |
| 9 #include "base/logging.h" | 10 #include "base/logging.h" |
| 10 #include "base/macros.h" | 11 #include "base/macros.h" |
| 11 #include "base/rand_util.h" | 12 #include "base/rand_util.h" |
| 12 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
| 13 #include "google_apis/gaia/gaia_constants.h" | 14 #include "google_apis/gaia/gaia_constants.h" |
| 14 #include "google_apis/gaia/google_service_auth_error.h" | 15 #include "google_apis/gaia/google_service_auth_error.h" |
| 15 #include "net/http/http_status_code.h" | 16 #include "net/http/http_status_code.h" |
| 16 #include "net/url_request/url_request_status.h" | 17 #include "net/url_request/url_request_status.h" |
| 17 | 18 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 DISALLOW_COPY_AND_ASSIGN(DataSegment); | 108 DISALLOW_COPY_AND_ASSIGN(DataSegment); |
| 108 }; | 109 }; |
| 109 | 110 |
| 110 DataSegment::DataSegment( | 111 DataSegment::DataSegment( |
| 111 const std::string& name, | 112 const std::string& name, |
| 112 const std::string& filename, | 113 const std::string& filename, |
| 113 scoped_ptr<std::string> data, | 114 scoped_ptr<std::string> data, |
| 114 const std::map<std::string, std::string>& header_entries) | 115 const std::map<std::string, std::string>& header_entries) |
| 115 : name_(name), | 116 : name_(name), |
| 116 filename_(filename), | 117 filename_(filename), |
| 117 data_(data.Pass()), | 118 data_(std::move(data)), |
| 118 header_entries_(header_entries) { | 119 header_entries_(header_entries) { |
| 119 DCHECK(data_); | 120 DCHECK(data_); |
| 120 } | 121 } |
| 121 | 122 |
| 122 const std::map<std::string, std::string>& DataSegment::GetHeaderEntries() | 123 const std::map<std::string, std::string>& DataSegment::GetHeaderEntries() |
| 123 const { | 124 const { |
| 124 return header_entries_; | 125 return header_entries_; |
| 125 } | 126 } |
| 126 | 127 |
| 127 const std::string& DataSegment::GetName() const { | 128 const std::string& DataSegment::GetName() const { |
| 128 return name_; | 129 return name_; |
| 129 } | 130 } |
| 130 | 131 |
| 131 const std::string& DataSegment::GetFilename() const { | 132 const std::string& DataSegment::GetFilename() const { |
| 132 return filename_; | 133 return filename_; |
| 133 } | 134 } |
| 134 | 135 |
| 135 scoped_ptr<std::string> DataSegment::GetData() { | 136 scoped_ptr<std::string> DataSegment::GetData() { |
| 136 return data_.Pass(); | 137 return std::move(data_); |
| 137 } | 138 } |
| 138 | 139 |
| 139 bool DataSegment::CheckIfDataContains(const std::string& chunk) { | 140 bool DataSegment::CheckIfDataContains(const std::string& chunk) { |
| 140 DCHECK(data_); | 141 DCHECK(data_); |
| 141 return data_->find(chunk) != std::string::npos; | 142 return data_->find(chunk) != std::string::npos; |
| 142 } | 143 } |
| 143 | 144 |
| 144 size_t DataSegment::GetDataSize() const { | 145 size_t DataSegment::GetDataSize() const { |
| 145 DCHECK(data_); | 146 DCHECK(data_); |
| 146 return data_->size(); | 147 return data_->size(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 166 OAuth2TokenService* token_service, | 167 OAuth2TokenService* token_service, |
| 167 scoped_refptr<net::URLRequestContextGetter> url_context_getter, | 168 scoped_refptr<net::URLRequestContextGetter> url_context_getter, |
| 168 Delegate* delegate, | 169 Delegate* delegate, |
| 169 scoped_ptr<MimeBoundaryGenerator> boundary_generator) | 170 scoped_ptr<MimeBoundaryGenerator> boundary_generator) |
| 170 : OAuth2TokenService::Consumer("cros_upload_job"), | 171 : OAuth2TokenService::Consumer("cros_upload_job"), |
| 171 upload_url_(upload_url), | 172 upload_url_(upload_url), |
| 172 account_id_(account_id), | 173 account_id_(account_id), |
| 173 token_service_(token_service), | 174 token_service_(token_service), |
| 174 url_context_getter_(url_context_getter), | 175 url_context_getter_(url_context_getter), |
| 175 delegate_(delegate), | 176 delegate_(delegate), |
| 176 boundary_generator_(boundary_generator.Pass()), | 177 boundary_generator_(std::move(boundary_generator)), |
| 177 state_(IDLE), | 178 state_(IDLE), |
| 178 retry_(0) { | 179 retry_(0) { |
| 179 DCHECK(token_service_); | 180 DCHECK(token_service_); |
| 180 DCHECK(url_context_getter_); | 181 DCHECK(url_context_getter_); |
| 181 DCHECK(delegate_); | 182 DCHECK(delegate_); |
| 182 if (!upload_url_.is_valid()) { | 183 if (!upload_url_.is_valid()) { |
| 183 state_ = ERROR; | 184 state_ = ERROR; |
| 184 NOTREACHED() << upload_url_ << " is not a valid URL."; | 185 NOTREACHED() << upload_url_ << " is not a valid URL."; |
| 185 } | 186 } |
| 186 } | 187 } |
| 187 | 188 |
| 188 UploadJobImpl::~UploadJobImpl() { | 189 UploadJobImpl::~UploadJobImpl() { |
| 189 } | 190 } |
| 190 | 191 |
| 191 void UploadJobImpl::AddDataSegment( | 192 void UploadJobImpl::AddDataSegment( |
| 192 const std::string& name, | 193 const std::string& name, |
| 193 const std::string& filename, | 194 const std::string& filename, |
| 194 const std::map<std::string, std::string>& header_entries, | 195 const std::map<std::string, std::string>& header_entries, |
| 195 scoped_ptr<std::string> data) { | 196 scoped_ptr<std::string> data) { |
| 196 // Cannot add data to busy or failed instance. | 197 // Cannot add data to busy or failed instance. |
| 197 DCHECK_EQ(IDLE, state_); | 198 DCHECK_EQ(IDLE, state_); |
| 198 if (state_ != IDLE) | 199 if (state_ != IDLE) |
| 199 return; | 200 return; |
| 200 | 201 |
| 201 scoped_ptr<DataSegment> data_segment( | 202 scoped_ptr<DataSegment> data_segment( |
| 202 new DataSegment(name, filename, data.Pass(), header_entries)); | 203 new DataSegment(name, filename, std::move(data), header_entries)); |
| 203 data_segments_.push_back(data_segment.Pass()); | 204 data_segments_.push_back(std::move(data_segment)); |
| 204 } | 205 } |
| 205 | 206 |
| 206 void UploadJobImpl::Start() { | 207 void UploadJobImpl::Start() { |
| 207 // Cannot start an upload on a busy or failed instance. | 208 // Cannot start an upload on a busy or failed instance. |
| 208 DCHECK_EQ(IDLE, state_); | 209 DCHECK_EQ(IDLE, state_); |
| 209 if (state_ != IDLE) | 210 if (state_ != IDLE) |
| 210 return; | 211 return; |
| 211 RequestAccessToken(); | 212 RequestAccessToken(); |
| 212 } | 213 } |
| 213 | 214 |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 if (success) { | 404 if (success) { |
| 404 state_ = SUCCESS; | 405 state_ = SUCCESS; |
| 405 delegate_->OnSuccess(); | 406 delegate_->OnSuccess(); |
| 406 } else { | 407 } else { |
| 407 state_ = ERROR; | 408 state_ = ERROR; |
| 408 delegate_->OnFailure(SERVER_ERROR); | 409 delegate_->OnFailure(SERVER_ERROR); |
| 409 } | 410 } |
| 410 } | 411 } |
| 411 | 412 |
| 412 } // namespace policy | 413 } // namespace policy |
| OLD | NEW |