OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/translate/core/browser/translate_script.h" | 5 #include "components/translate/core/browser/translate_script.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/logging.h" | 9 #include "base/logging.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "base/profiler/scoped_profile.h" |
11 #include "base/strings/string_piece.h" | 12 #include "base/strings/string_piece.h" |
12 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
13 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
14 #include "components/translate/core/browser/translate_url_fetcher.h" | 15 #include "components/translate/core/browser/translate_url_fetcher.h" |
15 #include "components/translate/core/browser/translate_url_util.h" | 16 #include "components/translate/core/browser/translate_url_util.h" |
16 #include "components/translate/core/common/translate_switches.h" | 17 #include "components/translate/core/common/translate_switches.h" |
17 #include "components/translate/core/common/translate_util.h" | 18 #include "components/translate/core/common/translate_util.h" |
18 #include "google_apis/google_api_keys.h" | 19 #include "google_apis/google_api_keys.h" |
19 #include "grit/components_resources.h" | 20 #include "grit/components_resources.h" |
20 #include "net/base/escape.h" | 21 #include "net/base/escape.h" |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 fetcher_->set_extra_request_header(kRequestHeader); | 111 fetcher_->set_extra_request_header(kRequestHeader); |
111 fetcher_->Request( | 112 fetcher_->Request( |
112 translate_script_url, | 113 translate_script_url, |
113 base::Bind(&TranslateScript::OnScriptFetchComplete, | 114 base::Bind(&TranslateScript::OnScriptFetchComplete, |
114 base::Unretained(this))); | 115 base::Unretained(this))); |
115 } | 116 } |
116 | 117 |
117 | 118 |
118 void TranslateScript::OnScriptFetchComplete( | 119 void TranslateScript::OnScriptFetchComplete( |
119 int id, bool success, const std::string& data) { | 120 int id, bool success, const std::string& data) { |
| 121 // TODO(vadimt): Remove ScopedProfile below once crbug.com/422577 is fixed. |
| 122 tracked_objects::ScopedProfile tracking_profile( |
| 123 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 124 "422577 TranslateScript::OnScriptFetchComplete")); |
| 125 |
120 DCHECK_EQ(kFetcherId, id); | 126 DCHECK_EQ(kFetcherId, id); |
121 | 127 |
122 scoped_ptr<const TranslateURLFetcher> delete_ptr(fetcher_.release()); | 128 scoped_ptr<const TranslateURLFetcher> delete_ptr(fetcher_.release()); |
123 | 129 |
124 if (success) { | 130 if (success) { |
125 DCHECK(data_.empty()); | 131 DCHECK(data_.empty()); |
126 // Insert variable definitions on API Key and security origin. | 132 // Insert variable definitions on API Key and security origin. |
127 data_ = base::StringPrintf("var translateApiKey = '%s';\n", | 133 data_ = base::StringPrintf("var translateApiKey = '%s';\n", |
128 google_apis::GetAPIKey().c_str()); | 134 google_apis::GetAPIKey().c_str()); |
129 | 135 |
(...skipping 19 matching lines...) Expand all Loading... |
149 | 155 |
150 for (RequestCallbackList::iterator it = callback_list_.begin(); | 156 for (RequestCallbackList::iterator it = callback_list_.begin(); |
151 it != callback_list_.end(); | 157 it != callback_list_.end(); |
152 ++it) { | 158 ++it) { |
153 it->Run(success, data); | 159 it->Run(success, data); |
154 } | 160 } |
155 callback_list_.clear(); | 161 callback_list_.clear(); |
156 } | 162 } |
157 | 163 |
158 } // namespace translate | 164 } // namespace translate |
OLD | NEW |