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

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

Issue 13488014: Translate: Adding a flag to enable "alpha language" translation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: about:flags Created 7 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/about_flags.cc ('k') | chrome/common/chrome_switches.h » ('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 (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/translate/translate_manager.h" 5 #include "chrome/browser/translate/translate_manager.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/json/json_reader.h" 10 #include "base/json/json_reader.h"
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 134
135 const char* const kTranslateScriptURL = 135 const char* const kTranslateScriptURL =
136 "https://translate.google.com/translate_a/element.js"; 136 "https://translate.google.com/translate_a/element.js";
137 const char* const kTranslateScriptQuery = 137 const char* const kTranslateScriptQuery =
138 "?cb=cr.googleTranslate.onTranslateElementLoad&hl=%s"; 138 "?cb=cr.googleTranslate.onTranslateElementLoad&hl=%s";
139 const char* const kTranslateScriptHeader = 139 const char* const kTranslateScriptHeader =
140 "Google-Translate-Element-Mode: library"; 140 "Google-Translate-Element-Mode: library";
141 const char* const kReportLanguageDetectionErrorURL = 141 const char* const kReportLanguageDetectionErrorURL =
142 "https://translate.google.com/translate_error"; 142 "https://translate.google.com/translate_error";
143 const char* const kLanguageListFetchURL = 143 const char* const kLanguageListFetchURL =
144 "https://translate.googleapis.com/translate_a/l?client=chrome&cb=sl&hl=%s"; 144 "https://translate.googleapis.com/translate_a/l"
145 "?client=chrome&cb=sl&hl=%s%s";
MAD 2013/04/05 14:18:34 At this point, I think we should start using Appe
Takashi Toyoshima 2013/04/08 03:39:05 Agreed. I'll apply AppendQueryParameter on modify
146 const char* const kAlphaLanguageQuery = "&alpha=1";
145 const int kMaxRetryLanguageListFetch = 5; 147 const int kMaxRetryLanguageListFetch = 5;
146 const int kTranslateScriptExpirationDelayDays = 1; 148 const int kTranslateScriptExpirationDelayDays = 1;
147 149
148 void AddApiKeyToUrl(GURL* url) { 150 void AddApiKeyToUrl(GURL* url) {
149 std::string api_key = google_apis::GetAPIKey(); 151 std::string api_key = google_apis::GetAPIKey();
150 std::string query(url->query()); 152 std::string query(url->query());
151 if (!query.empty()) 153 if (!query.empty())
152 query += "&"; 154 query += "&";
153 query += "key=" + net::EscapeQueryParamValue(api_key, true); 155 query += "key=" + net::EscapeQueryParamValue(api_key, true);
154 GURL::Replacements replacements; 156 GURL::Replacements replacements;
(...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after
769 return; 771 return;
770 772
771 // We don't want to do this when translate is disabled. 773 // We don't want to do this when translate is disabled.
772 DCHECK(prefs != NULL); 774 DCHECK(prefs != NULL);
773 if (CommandLine::ForCurrentProcess()->HasSwitch( 775 if (CommandLine::ForCurrentProcess()->HasSwitch(
774 switches::kDisableTranslate) || 776 switches::kDisableTranslate) ||
775 (prefs != NULL && !prefs->GetBoolean(prefs::kEnableTranslate))) { 777 (prefs != NULL && !prefs->GetBoolean(prefs::kEnableTranslate))) {
776 return; 778 return;
777 } 779 }
778 780
781 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
779 GURL language_list_fetch_url = GURL( 782 GURL language_list_fetch_url = GURL(
780 base::StringPrintf( 783 base::StringPrintf(
781 kLanguageListFetchURL, 784 kLanguageListFetchURL,
782 GetLanguageCode(g_browser_process->GetApplicationLocale()).c_str())); 785 GetLanguageCode(g_browser_process->GetApplicationLocale()).c_str(),
786 command_line.HasSwitch(switches::kEnableTranslateAlphaLanguages) ?
787 kAlphaLanguageQuery : ""));
783 AddApiKeyToUrl(&language_list_fetch_url); 788 AddApiKeyToUrl(&language_list_fetch_url);
789 VLOG(9) << "Fetch supporting language list from: "
790 << language_list_fetch_url.spec().c_str();
791
784 language_list_request_pending_.reset(net::URLFetcher::Create( 792 language_list_request_pending_.reset(net::URLFetcher::Create(
785 1, language_list_fetch_url, net::URLFetcher::GET, this)); 793 1, language_list_fetch_url, net::URLFetcher::GET, this));
786 language_list_request_pending_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | 794 language_list_request_pending_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES |
787 net::LOAD_DO_NOT_SAVE_COOKIES); 795 net::LOAD_DO_NOT_SAVE_COOKIES);
788 language_list_request_pending_->SetRequestContext( 796 language_list_request_pending_->SetRequestContext(
789 g_browser_process->system_request_context()); 797 g_browser_process->system_request_context());
790 language_list_request_pending_->SetMaxRetriesOn5xx( 798 language_list_request_pending_->SetMaxRetriesOn5xx(
791 kMaxRetryLanguageListFetch); 799 kMaxRetryLanguageListFetch);
792 language_list_request_pending_->Start(); 800 language_list_request_pending_->Start();
793 } 801 }
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
854 // list or not at all if no such candidate exists 862 // list or not at all if no such candidate exists
855 std::vector<std::string>::iterator iter; 863 std::vector<std::string>::iterator iter;
856 for (iter = accept_langs_list.begin(); 864 for (iter = accept_langs_list.begin();
857 iter != accept_langs_list.end(); ++iter) { 865 iter != accept_langs_list.end(); ++iter) {
858 std::string lang_code = GetLanguageCode(*iter); 866 std::string lang_code = GetLanguageCode(*iter);
859 if (IsSupportedLanguage(lang_code)) 867 if (IsSupportedLanguage(lang_code))
860 return lang_code; 868 return lang_code;
861 } 869 }
862 return std::string(); 870 return std::string();
863 } 871 }
OLDNEW
« no previous file with comments | « chrome/browser/about_flags.cc ('k') | chrome/common/chrome_switches.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698