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

Side by Side Diff: components/dom_distiller/core/url_utils.cc

Issue 2060583002: Record start up latency of DOM distiller viewer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2743
Patch Set: Created 4 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
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/dom_distiller/core/url_utils.h" 5 #include "components/dom_distiller/core/url_utils.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/guid.h" 9 #include "base/guid.h"
10 #include "base/strings/string_number_conversions.h"
10 #include "components/dom_distiller/core/url_constants.h" 11 #include "components/dom_distiller/core/url_constants.h"
11 #include "grit/components_resources.h" 12 #include "grit/components_resources.h"
12 #include "net/base/url_util.h" 13 #include "net/base/url_util.h"
13 #include "ui/base/resource/resource_bundle.h" 14 #include "ui/base/resource/resource_bundle.h"
14 #include "url/gurl.h" 15 #include "url/gurl.h"
15 16
16 namespace dom_distiller { 17 namespace dom_distiller {
17 18
18 namespace url_utils { 19 namespace url_utils {
19 20
20 namespace { 21 namespace {
21 22
22 const char kDummyInternalUrlPrefix[] = "chrome-distiller-internal://dummy/"; 23 const char kDummyInternalUrlPrefix[] = "chrome-distiller-internal://dummy/";
23 24
24 } // namespace 25 } // namespace
25 26
26 const GURL GetDistillerViewUrlFromEntryId(const std::string& scheme, 27 const GURL GetDistillerViewUrlFromEntryId(const std::string& scheme,
27 const std::string& entry_id) { 28 const std::string& entry_id) {
28 GURL url(scheme + "://" + base::GenerateGUID()); 29 GURL url(scheme + "://" + base::GenerateGUID());
29 return net::AppendOrReplaceQueryParameter(url, kEntryIdKey, entry_id); 30 return net::AppendOrReplaceQueryParameter(url, kEntryIdKey, entry_id);
30 } 31 }
31 32
32 const GURL GetDistillerViewUrlFromUrl(const std::string& scheme, 33 const GURL GetDistillerViewUrlFromUrl(const std::string& scheme,
33 const GURL& view_url) { 34 const GURL& view_url,
35 int64_t start_time_ms) {
34 GURL url(scheme + "://" + base::GenerateGUID()); 36 GURL url(scheme + "://" + base::GenerateGUID());
37 if (start_time_ms > 0) {
38 url = net::AppendOrReplaceQueryParameter(url, kTimeKey,
39 base::IntToString(start_time_ms));
40 }
35 return net::AppendOrReplaceQueryParameter(url, kUrlKey, view_url.spec()); 41 return net::AppendOrReplaceQueryParameter(url, kUrlKey, view_url.spec());
36 } 42 }
37 43
38 const GURL GetOriginalUrlFromDistillerUrl(const GURL& url) { 44 const GURL GetOriginalUrlFromDistillerUrl(const GURL& url) {
39 if (!dom_distiller::url_utils::IsDistilledPage(url)) 45 if (!dom_distiller::url_utils::IsDistilledPage(url))
40 return url; 46 return url;
41 47
42 std::string original_url_str; 48 std::string original_url_str;
43 net::GetValueForKeyInQuery(url, kUrlKey, &original_url_str); 49 net::GetValueForKeyInQuery(url, kUrlKey, &original_url_str);
44 50
45 return GURL(original_url_str); 51 return GURL(original_url_str);
46 } 52 }
47 53
54 int64_t GetTimeFromDistillerUrl(const GURL& url) {
55 if (!dom_distiller::url_utils::IsDistilledPage(url))
56 return 0;
57
58 std::string time_str;
59 if (!net::GetValueForKeyInQuery(url, kTimeKey, &time_str))
60 return 0;
61
62 int64_t time_int = 0;
63 if (!base::StringToInt64(time_str, &time_int))
64 return 0;
65
66 return time_int;
67 }
68
48 std::string GetValueForKeyInUrl(const GURL& url, const std::string& key) { 69 std::string GetValueForKeyInUrl(const GURL& url, const std::string& key) {
49 if (!url.is_valid()) 70 if (!url.is_valid())
50 return ""; 71 return "";
51 std::string value; 72 std::string value;
52 if (net::GetValueForKeyInQuery(url, key, &value)) { 73 if (net::GetValueForKeyInQuery(url, key, &value)) {
53 return value; 74 return value;
54 } 75 }
55 return ""; 76 return "";
56 } 77 }
57 78
(...skipping 14 matching lines...) Expand all
72 } 93 }
73 94
74 std::string GetIsDistillableJs() { 95 std::string GetIsDistillableJs() {
75 return ResourceBundle::GetSharedInstance() 96 return ResourceBundle::GetSharedInstance()
76 .GetRawDataResource(IDR_IS_DISTILLABLE_JS).as_string(); 97 .GetRawDataResource(IDR_IS_DISTILLABLE_JS).as_string();
77 } 98 }
78 99
79 } // namespace url_utils 100 } // namespace url_utils
80 101
81 } // namespace dom_distiller 102 } // namespace dom_distiller
OLDNEW
« no previous file with comments | « components/dom_distiller/core/url_utils.h ('k') | components/dom_distiller/core/url_utils_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698