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

Side by Side Diff: components/translate/core/browser/translate_script.cc

Issue 2251273002: pass script fetch start / end time to Transalte Element to implement real time latency monitoring (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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
OLDNEW
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/location.h" 9 #include "base/location.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 54
55 TranslateScript::TranslateScript() 55 TranslateScript::TranslateScript()
56 : expiration_delay_(base::TimeDelta::FromDays(kExpirationDelayDays)), 56 : expiration_delay_(base::TimeDelta::FromDays(kExpirationDelayDays)),
57 weak_method_factory_(this) { 57 weak_method_factory_(this) {
58 } 58 }
59 59
60 TranslateScript::~TranslateScript() { 60 TranslateScript::~TranslateScript() {
61 } 61 }
62 62
63 void TranslateScript::Request(const RequestCallback& callback) { 63 void TranslateScript::Request(const RequestCallback& callback) {
64 script_fetch_start_time_ = base::Time::Now().ToJsTime();
65
64 DCHECK(data_.empty()) << "Do not fetch the script if it is already fetched"; 66 DCHECK(data_.empty()) << "Do not fetch the script if it is already fetched";
65 callback_list_.push_back(callback); 67 callback_list_.push_back(callback);
66 68
67 if (fetcher_.get() != NULL) { 69 if (fetcher_.get() != NULL) {
68 // If there is already a request in progress, do nothing. |callback| will be 70 // If there is already a request in progress, do nothing. |callback| will be
69 // run on completion. 71 // run on completion.
70 return; 72 return;
71 } 73 }
72 74
73 GURL translate_script_url; 75 GURL translate_script_url;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 data_ = base::StringPrintf("var translateApiKey = '%s';\n", 137 data_ = base::StringPrintf("var translateApiKey = '%s';\n",
136 google_apis::GetAPIKey().c_str()); 138 google_apis::GetAPIKey().c_str());
137 139
138 // Insert server params to pass experimental params to google translate 140 // Insert server params to pass experimental params to google translate
139 // server. 141 // server.
140 std::string server_params; 142 std::string server_params;
141 std::map<std::string, std::string> params; 143 std::map<std::string, std::string> params;
142 if (variations::GetVariationParams(kTranslateServerStudy, &params)) { 144 if (variations::GetVariationParams(kTranslateServerStudy, &params)) {
143 server_params = params[kServerParams]; 145 server_params = params[kServerParams];
144 } 146 }
147 base::StringAppendF(
148 &data_, "var gtTimeInfo = {'fetchStart': %f, 'fetchEnd': %f};\n",
groby-ooo-7-16 2016/08/18 22:35:04 Question - wouldn't it make more sense to report j
ftang 2016/08/18 23:01:39 I need time (at least one of them) so my js in the
149 script_fetch_start_time_, base::Time::Now().ToJsTime());
145 base::StringAppendF(&data_, "var serverParams = '%s';\n", 150 base::StringAppendF(&data_, "var serverParams = '%s';\n",
146 server_params.c_str()); 151 server_params.c_str());
147 152
148 GURL security_origin = translate::GetTranslateSecurityOrigin(); 153 GURL security_origin = translate::GetTranslateSecurityOrigin();
149 base::StringAppendF( 154 base::StringAppendF(
150 &data_, "var securityOrigin = '%s';", security_origin.spec().c_str()); 155 &data_, "var securityOrigin = '%s';", security_origin.spec().c_str());
151 156
152 // Append embedded translate.js and a remote element library. 157 // Append embedded translate.js and a remote element library.
153 base::StringPiece str = ResourceBundle::GetSharedInstance(). 158 base::StringPiece str = ResourceBundle::GetSharedInstance().
154 GetRawDataResource(IDR_TRANSLATE_JS); 159 GetRawDataResource(IDR_TRANSLATE_JS);
(...skipping 11 matching lines...) Expand all
166 171
167 for (RequestCallbackList::iterator it = callback_list_.begin(); 172 for (RequestCallbackList::iterator it = callback_list_.begin();
168 it != callback_list_.end(); 173 it != callback_list_.end();
169 ++it) { 174 ++it) {
170 it->Run(success, data); 175 it->Run(success, data);
171 } 176 }
172 callback_list_.clear(); 177 callback_list_.clear();
173 } 178 }
174 179
175 } // namespace translate 180 } // namespace translate
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698