| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/gdata/gdata_operations.h" | 5 #include "chrome/browser/chromeos/gdata/gdata_operations.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
| 9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
| 10 #include "chrome/browser/chromeos/gdata/gdata_util.h" | 10 #include "chrome/browser/chromeos/gdata/gdata_util.h" |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 DCHECK(!auth_token.empty()); | 176 DCHECK(!auth_token.empty()); |
| 177 | 177 |
| 178 GURL url = GetURL(); | 178 GURL url = GetURL(); |
| 179 DCHECK(!url.is_empty()); | 179 DCHECK(!url.is_empty()); |
| 180 DVLOG(1) << "URL: " << url.spec(); | 180 DVLOG(1) << "URL: " << url.spec(); |
| 181 | 181 |
| 182 url_fetcher_.reset(URLFetcher::Create(url, GetRequestType(), this)); | 182 url_fetcher_.reset(URLFetcher::Create(url, GetRequestType(), this)); |
| 183 url_fetcher_->SetRequestContext(profile_->GetRequestContext()); | 183 url_fetcher_->SetRequestContext(profile_->GetRequestContext()); |
| 184 // Always set flags to neither send nor save cookies. | 184 // Always set flags to neither send nor save cookies. |
| 185 url_fetcher_->SetLoadFlags( | 185 url_fetcher_->SetLoadFlags( |
| 186 net::LOAD_DO_NOT_SEND_COOKIES | net::LOAD_DO_NOT_SAVE_COOKIES); | 186 net::LOAD_DO_NOT_SEND_COOKIES | net::LOAD_DO_NOT_SAVE_COOKIES | |
| 187 net::LOAD_DISABLE_CACHE); |
| 187 if (save_temp_file_) { | 188 if (save_temp_file_) { |
| 188 url_fetcher_->SaveResponseToTemporaryFile( | 189 url_fetcher_->SaveResponseToTemporaryFile( |
| 189 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)); | 190 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)); |
| 191 } else if (!output_file_path_.empty()){ |
| 192 url_fetcher_->SaveResponseToFileAtPath(output_file_path_, |
| 193 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)); |
| 190 } | 194 } |
| 191 | 195 |
| 192 // Add request headers. | 196 // Add request headers. |
| 193 // Note that SetExtraRequestHeaders clears the current headers and sets it | 197 // Note that SetExtraRequestHeaders clears the current headers and sets it |
| 194 // to the passed-in headers, so calling it for each header will result in | 198 // to the passed-in headers, so calling it for each header will result in |
| 195 // only the last header being set in request headers. | 199 // only the last header being set in request headers. |
| 196 url_fetcher_->AddExtraRequestHeader(kGDataVersionHeader); | 200 url_fetcher_->AddExtraRequestHeader(kGDataVersionHeader); |
| 197 url_fetcher_->AddExtraRequestHeader( | 201 url_fetcher_->AddExtraRequestHeader( |
| 198 base::StringPrintf(kAuthorizationHeaderFormat, auth_token.data())); | 202 base::StringPrintf(kAuthorizationHeaderFormat, auth_token.data())); |
| 199 std::vector<std::string> headers = GetExtraRequestHeaders(); | 203 std::vector<std::string> headers = GetExtraRequestHeaders(); |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 return AddStandardUrlParams(GURL(kAccountMetadataURL)); | 424 return AddStandardUrlParams(GURL(kAccountMetadataURL)); |
| 421 } | 425 } |
| 422 | 426 |
| 423 //============================ DownloadFileOperation =========================== | 427 //============================ DownloadFileOperation =========================== |
| 424 | 428 |
| 425 DownloadFileOperation::DownloadFileOperation( | 429 DownloadFileOperation::DownloadFileOperation( |
| 426 GDataOperationRegistry* registry, | 430 GDataOperationRegistry* registry, |
| 427 Profile* profile, | 431 Profile* profile, |
| 428 const DownloadActionCallback& callback, | 432 const DownloadActionCallback& callback, |
| 429 const GURL& document_url, | 433 const GURL& document_url, |
| 430 const FilePath& virtual_path) | 434 const FilePath& virtual_path, |
| 435 const FilePath& output_file_path) |
| 431 : UrlFetchOperationBase(registry, | 436 : UrlFetchOperationBase(registry, |
| 432 GDataOperationRegistry::OPERATION_DOWNLOAD, | 437 GDataOperationRegistry::OPERATION_DOWNLOAD, |
| 433 virtual_path, | 438 virtual_path, |
| 434 profile), | 439 profile), |
| 435 callback_(callback), | 440 callback_(callback), |
| 436 document_url_(document_url) { | 441 document_url_(document_url) { |
| 437 // Make sure we download the content into a temp file. | 442 // Make sure we download the content into a temp file. |
| 438 save_temp_file_ = true; | 443 if (output_file_path.empty()) |
| 444 save_temp_file_ = true; |
| 445 else |
| 446 output_file_path_ = output_file_path; |
| 439 } | 447 } |
| 440 | 448 |
| 441 DownloadFileOperation::~DownloadFileOperation() {} | 449 DownloadFileOperation::~DownloadFileOperation() {} |
| 442 | 450 |
| 443 // Overridden from UrlFetchOperationBase. | 451 // Overridden from UrlFetchOperationBase. |
| 444 GURL DownloadFileOperation::GetURL() const { | 452 GURL DownloadFileOperation::GetURL() const { |
| 445 return document_url_; | 453 return document_url_; |
| 446 } | 454 } |
| 447 | 455 |
| 448 void DownloadFileOperation::OnURLFetchDownloadProgress(const URLFetcher* source, | 456 void DownloadFileOperation::OnURLFetchDownloadProgress(const URLFetcher* source, |
| (...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 914 } | 922 } |
| 915 | 923 |
| 916 void ResumeUploadOperation::OnURLFetchUploadProgress( | 924 void ResumeUploadOperation::OnURLFetchUploadProgress( |
| 917 const content::URLFetcher* source, int64 current, int64 total) { | 925 const content::URLFetcher* source, int64 current, int64 total) { |
| 918 // Adjust the progress values according to the range currently uploaded. | 926 // Adjust the progress values according to the range currently uploaded. |
| 919 NotifyProgress(params_.start_range + current, params_.content_length); | 927 NotifyProgress(params_.start_range + current, params_.content_length); |
| 920 } | 928 } |
| 921 | 929 |
| 922 | 930 |
| 923 } // namespace gdata | 931 } // namespace gdata |
| OLD | NEW |