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); |
kuan
2012/03/20 03:22:19
these same load flags are used by DownloadFileOper
zel
2012/03/20 04:31:17
goo catch. i don't think we ever want to cache any
| |
187 if (save_temp_file_) { | 187 if (save_temp_file_) { |
188 url_fetcher_->SaveResponseToTemporaryFile( | 188 url_fetcher_->SaveResponseToTemporaryFile( |
189 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)); | 189 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)); |
190 } else if (!output_file_path_.empty()){ | |
191 url_fetcher_->SaveResponseToFileAtPath(output_file_path_, | |
192 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)); | |
190 } | 193 } |
191 | 194 |
192 // Add request headers. | 195 // Add request headers. |
193 // Note that SetExtraRequestHeaders clears the current headers and sets it | 196 // 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 | 197 // to the passed-in headers, so calling it for each header will result in |
195 // only the last header being set in request headers. | 198 // only the last header being set in request headers. |
196 url_fetcher_->AddExtraRequestHeader(kGDataVersionHeader); | 199 url_fetcher_->AddExtraRequestHeader(kGDataVersionHeader); |
197 url_fetcher_->AddExtraRequestHeader( | 200 url_fetcher_->AddExtraRequestHeader( |
198 base::StringPrintf(kAuthorizationHeaderFormat, auth_token.data())); | 201 base::StringPrintf(kAuthorizationHeaderFormat, auth_token.data())); |
199 std::vector<std::string> headers = GetExtraRequestHeaders(); | 202 std::vector<std::string> headers = GetExtraRequestHeaders(); |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
420 return AddStandardUrlParams(GURL(kAccountMetadataURL)); | 423 return AddStandardUrlParams(GURL(kAccountMetadataURL)); |
421 } | 424 } |
422 | 425 |
423 //============================ DownloadFileOperation =========================== | 426 //============================ DownloadFileOperation =========================== |
424 | 427 |
425 DownloadFileOperation::DownloadFileOperation( | 428 DownloadFileOperation::DownloadFileOperation( |
426 GDataOperationRegistry* registry, | 429 GDataOperationRegistry* registry, |
427 Profile* profile, | 430 Profile* profile, |
428 const DownloadActionCallback& callback, | 431 const DownloadActionCallback& callback, |
429 const GURL& document_url, | 432 const GURL& document_url, |
430 const FilePath& virtual_path) | 433 const FilePath& virtual_path, |
434 const FilePath& output_file_path) | |
431 : UrlFetchOperationBase(registry, | 435 : UrlFetchOperationBase(registry, |
432 GDataOperationRegistry::OPERATION_DOWNLOAD, | 436 GDataOperationRegistry::OPERATION_DOWNLOAD, |
433 virtual_path, | 437 virtual_path, |
434 profile), | 438 profile), |
435 callback_(callback), | 439 callback_(callback), |
436 document_url_(document_url) { | 440 document_url_(document_url) { |
437 // Make sure we download the content into a temp file. | 441 // Make sure we download the content into a temp file. |
438 save_temp_file_ = true; | 442 if (output_file_path.empty()) |
443 save_temp_file_ = true; | |
444 else | |
445 output_file_path_ = output_file_path; | |
439 } | 446 } |
440 | 447 |
441 DownloadFileOperation::~DownloadFileOperation() {} | 448 DownloadFileOperation::~DownloadFileOperation() {} |
442 | 449 |
443 // Overridden from UrlFetchOperationBase. | 450 // Overridden from UrlFetchOperationBase. |
444 GURL DownloadFileOperation::GetURL() const { | 451 GURL DownloadFileOperation::GetURL() const { |
445 return document_url_; | 452 return document_url_; |
446 } | 453 } |
447 | 454 |
448 void DownloadFileOperation::OnURLFetchDownloadProgress(const URLFetcher* source, | 455 void DownloadFileOperation::OnURLFetchDownloadProgress(const URLFetcher* source, |
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
914 } | 921 } |
915 | 922 |
916 void ResumeUploadOperation::OnURLFetchUploadProgress( | 923 void ResumeUploadOperation::OnURLFetchUploadProgress( |
917 const content::URLFetcher* source, int64 current, int64 total) { | 924 const content::URLFetcher* source, int64 current, int64 total) { |
918 // Adjust the progress values according to the range currently uploaded. | 925 // Adjust the progress values according to the range currently uploaded. |
919 NotifyProgress(params_.start_range + current, params_.content_length); | 926 NotifyProgress(params_.start_range + current, params_.content_length); |
920 } | 927 } |
921 | 928 |
922 | 929 |
923 } // namespace gdata | 930 } // namespace gdata |
OLD | NEW |