Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(574)

Side by Side Diff: chrome/browser/translate/translate_url_fetcher.cc

Issue 17390018: Refactoring: Create TranslateScript from TranslateManager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@refactoring-translate-url-fetcher
Patch Set: Removed the nits Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/translate/translate_url_fetcher.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/translate/translate_url_fetcher.h" 5 #include "chrome/browser/translate/translate_url_fetcher.h"
6 6
7 #include "chrome/browser/browser_process.h" 7 #include "chrome/browser/browser_process.h"
8 #include "net/base/load_flags.h" 8 #include "net/base/load_flags.h"
9 #include "net/http/http_status_code.h" 9 #include "net/http/http_status_code.h"
10 #include "net/url_request/url_fetcher.h" 10 #include "net/url_request/url_fetcher.h"
11 #include "net/url_request/url_request_status.h" 11 #include "net/url_request/url_request_status.h"
12 12
13 namespace { 13 namespace {
14 14
15 // Retry parameter for fetching. 15 // Retry parameter for fetching.
16 const int kMaxRetryOn5xx = 5;
17 const int kMaxRetry = 16; 16 const int kMaxRetry = 16;
18 17
19 } // namespace 18 } // namespace
20 19
21 TranslateURLFetcher::TranslateURLFetcher(int id) 20 TranslateURLFetcher::TranslateURLFetcher(int id)
22 : id_(id), 21 : id_(id),
23 state_(IDLE), 22 state_(IDLE),
24 retry_count_(0) { 23 retry_count_(0) {
25 } 24 }
26 25
(...skipping 22 matching lines...) Expand all
49 id_, 48 id_,
50 url_, 49 url_,
51 net::URLFetcher::GET, 50 net::URLFetcher::GET,
52 this)); 51 this));
53 fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | 52 fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES |
54 net::LOAD_DO_NOT_SAVE_COOKIES); 53 net::LOAD_DO_NOT_SAVE_COOKIES);
55 fetcher_->SetRequestContext(g_browser_process->system_request_context()); 54 fetcher_->SetRequestContext(g_browser_process->system_request_context());
56 // Set retry parameter for HTTP status code 5xx. This doesn't work against 55 // Set retry parameter for HTTP status code 5xx. This doesn't work against
57 // 106 (net::ERR_INTERNET_DISCONNECTED) and so on. 56 // 106 (net::ERR_INTERNET_DISCONNECTED) and so on.
58 // TranslateLanguageList handles network status, and implements retry. 57 // TranslateLanguageList handles network status, and implements retry.
59 fetcher_->SetMaxRetriesOn5xx(kMaxRetryOn5xx); 58 fetcher_->SetMaxRetriesOn5xx(max_retry_on_5xx_);
59 if (!extra_request_header_.empty())
60 fetcher_->SetExtraRequestHeaders(extra_request_header_);
61
60 fetcher_->Start(); 62 fetcher_->Start();
61 63
62 return true; 64 return true;
63 } 65 }
64 66
65 void TranslateURLFetcher::OnURLFetchComplete(const net::URLFetcher* source) { 67 void TranslateURLFetcher::OnURLFetchComplete(const net::URLFetcher* source) {
66 DCHECK(fetcher_.get() == source); 68 DCHECK(fetcher_.get() == source);
67 69
68 std::string data; 70 std::string data;
69 if (source->GetStatus().status() == net::URLRequestStatus::SUCCESS && 71 if (source->GetStatus().status() == net::URLRequestStatus::SUCCESS &&
70 source->GetResponseCode() == net::HTTP_OK) { 72 source->GetResponseCode() == net::HTTP_OK) {
71 state_ = COMPLETED; 73 state_ = COMPLETED;
72 source->GetResponseAsString(&data); 74 source->GetResponseAsString(&data);
73 } else { 75 } else {
74 state_ = FAILED; 76 state_ = FAILED;
75 } 77 }
76 78
77 // Transfer URLFetcher's ownership before invoking a callback. 79 // Transfer URLFetcher's ownership before invoking a callback.
78 scoped_ptr<const net::URLFetcher> delete_ptr(fetcher_.release()); 80 scoped_ptr<const net::URLFetcher> delete_ptr(fetcher_.release());
79 callback_.Run(id_, state_ == COMPLETED, data); 81 callback_.Run(id_, state_ == COMPLETED, data);
80 } 82 }
OLDNEW
« no previous file with comments | « chrome/browser/translate/translate_url_fetcher.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698