OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "build/build_config.h" | 5 #include "build/build_config.h" |
6 | 6 |
7 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" | 7 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 #include "chrome/browser/ui/webui/theme_source.h" | 39 #include "chrome/browser/ui/webui/theme_source.h" |
40 #include "chrome/common/chrome_notification_types.h" | 40 #include "chrome/common/chrome_notification_types.h" |
41 #include "chrome/common/chrome_switches.h" | 41 #include "chrome/common/chrome_switches.h" |
42 #include "chrome/common/extensions/extension.h" | 42 #include "chrome/common/extensions/extension.h" |
43 #include "chrome/common/pref_names.h" | 43 #include "chrome/common/pref_names.h" |
44 #include "chrome/common/url_constants.h" | 44 #include "chrome/common/url_constants.h" |
45 #include "content/browser/browser_thread.h" | 45 #include "content/browser/browser_thread.h" |
46 #include "content/browser/renderer_host/render_view_host.h" | 46 #include "content/browser/renderer_host/render_view_host.h" |
47 #include "content/browser/tab_contents/tab_contents.h" | 47 #include "content/browser/tab_contents/tab_contents.h" |
48 #include "content/browser/user_metrics.h" | 48 #include "content/browser/user_metrics.h" |
49 #include "content/common/notification_service.h" | 49 #include "content/public/browser/notification_service.h" |
50 #include "grit/generated_resources.h" | 50 #include "grit/generated_resources.h" |
51 #include "grit/theme_resources.h" | 51 #include "grit/theme_resources.h" |
52 #include "ui/base/l10n/l10n_util.h" | 52 #include "ui/base/l10n/l10n_util.h" |
53 | 53 |
54 namespace { | 54 namespace { |
55 | 55 |
56 // The amount of time there must be no painting for us to consider painting | 56 // The amount of time there must be no painting for us to consider painting |
57 // finished. Observed times are in the ~1200ms range on Windows. | 57 // finished. Observed times are in the ~1200ms range on Windows. |
58 const int kTimeoutMs = 2000; | 58 const int kTimeoutMs = 2000; |
59 | 59 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 // The timer callback. If enough time has elapsed since the last paint | 131 // The timer callback. If enough time has elapsed since the last paint |
132 // message, we say we're done painting; otherwise, we keep waiting. | 132 // message, we say we're done painting; otherwise, we keep waiting. |
133 void NewTabUI::PaintTimeout() { | 133 void NewTabUI::PaintTimeout() { |
134 // The amount of time there must be no painting for us to consider painting | 134 // The amount of time there must be no painting for us to consider painting |
135 // finished. Observed times are in the ~1200ms range on Windows. | 135 // finished. Observed times are in the ~1200ms range on Windows. |
136 base::TimeTicks now = base::TimeTicks::Now(); | 136 base::TimeTicks now = base::TimeTicks::Now(); |
137 if ((now - last_paint_) >= base::TimeDelta::FromMilliseconds(kTimeoutMs)) { | 137 if ((now - last_paint_) >= base::TimeDelta::FromMilliseconds(kTimeoutMs)) { |
138 // Painting has quieted down. Log this as the full time to run. | 138 // Painting has quieted down. Log this as the full time to run. |
139 base::TimeDelta load_time = last_paint_ - start_; | 139 base::TimeDelta load_time = last_paint_ - start_; |
140 int load_time_ms = static_cast<int>(load_time.InMilliseconds()); | 140 int load_time_ms = static_cast<int>(load_time.InMilliseconds()); |
141 NotificationService::current()->Notify( | 141 content::NotificationService::current()->Notify( |
142 chrome::NOTIFICATION_INITIAL_NEW_TAB_UI_LOAD, | 142 chrome::NOTIFICATION_INITIAL_NEW_TAB_UI_LOAD, |
143 content::Source<Profile>(GetProfile()), | 143 content::Source<Profile>(GetProfile()), |
144 content::Details<int>(&load_time_ms)); | 144 content::Details<int>(&load_time_ms)); |
145 UMA_HISTOGRAM_TIMES("NewTabUI load", load_time); | 145 UMA_HISTOGRAM_TIMES("NewTabUI load", load_time); |
146 } else { | 146 } else { |
147 // Not enough quiet time has elapsed. | 147 // Not enough quiet time has elapsed. |
148 // Some more paints must've occurred since we set the timeout. | 148 // Some more paints must've occurred since we set the timeout. |
149 // Wait some more. | 149 // Wait some more. |
150 timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(kTimeoutMs), this, | 150 timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(kTimeoutMs), this, |
151 &NewTabUI::PaintTimeout); | 151 &NewTabUI::PaintTimeout); |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 SendResponse(request_id, html_bytes); | 338 SendResponse(request_id, html_bytes); |
339 } | 339 } |
340 | 340 |
341 std::string NewTabUI::NewTabHTMLSource::GetMimeType(const std::string&) const { | 341 std::string NewTabUI::NewTabHTMLSource::GetMimeType(const std::string&) const { |
342 return "text/html"; | 342 return "text/html"; |
343 } | 343 } |
344 | 344 |
345 bool NewTabUI::NewTabHTMLSource::ShouldReplaceExistingSource() const { | 345 bool NewTabUI::NewTabHTMLSource::ShouldReplaceExistingSource() const { |
346 return false; | 346 return false; |
347 } | 347 } |
OLD | NEW |