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

Side by Side Diff: chrome/browser/automation/automation_provider_observers.cc

Issue 2813010: Revert 49862 - Measure loading time of several tabs.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 10 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/automation/automation_provider_observers.h ('k') | no next file » | 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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/automation/automation_provider_observers.h" 5 #include "chrome/browser/automation/automation_provider_observers.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/json/json_writer.h" 8 #include "base/json/json_writer.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "chrome/app/chrome_dll_resource.h" 10 #include "chrome/app/chrome_dll_resource.h"
(...skipping 10 matching lines...) Expand all
21 #include "chrome/browser/tab_contents/navigation_controller.h" 21 #include "chrome/browser/tab_contents/navigation_controller.h"
22 #include "chrome/browser/tab_contents/tab_contents.h" 22 #include "chrome/browser/tab_contents/tab_contents.h"
23 #include "chrome/common/extensions/extension.h" 23 #include "chrome/common/extensions/extension.h"
24 #include "chrome/common/notification_service.h" 24 #include "chrome/common/notification_service.h"
25 #include "chrome/test/automation/automation_constants.h" 25 #include "chrome/test/automation/automation_constants.h"
26 26
27 #if defined(OS_CHROMEOS) 27 #if defined(OS_CHROMEOS)
28 #include "chrome/browser/chromeos/login/authentication_notification_details.h" 28 #include "chrome/browser/chromeos/login/authentication_notification_details.h"
29 #endif 29 #endif
30 30
31 // Holds onto start and stop timestamps for a particular tab
32 class InitialLoadObserver::TabTime {
33 public:
34 explicit TabTime(base::TimeTicks started)
35 : load_start_time_(started) {
36 }
37 void set_stop_time(base::TimeTicks stopped) {
38 load_stop_time_ = stopped;
39 }
40 base::TimeTicks stop_time() const {
41 return load_stop_time_;
42 }
43 base::TimeTicks start_time() const {
44 return load_start_time_;
45 }
46 private:
47 base::TimeTicks load_start_time_;
48 base::TimeTicks load_stop_time_;
49 };
50
51 InitialLoadObserver::InitialLoadObserver(size_t tab_count, 31 InitialLoadObserver::InitialLoadObserver(size_t tab_count,
52 AutomationProvider* automation) 32 AutomationProvider* automation)
53 : automation_(automation), 33 : automation_(automation),
54 outstanding_tab_count_(tab_count), 34 outstanding_tab_count_(tab_count) {
55 init_time_(base::TimeTicks::Now()) {
56 if (outstanding_tab_count_ > 0) { 35 if (outstanding_tab_count_ > 0) {
57 registrar_.Add(this, NotificationType::LOAD_START, 36 registrar_.Add(this, NotificationType::LOAD_START,
58 NotificationService::AllSources()); 37 NotificationService::AllSources());
59 registrar_.Add(this, NotificationType::LOAD_STOP, 38 registrar_.Add(this, NotificationType::LOAD_STOP,
60 NotificationService::AllSources()); 39 NotificationService::AllSources());
61 } 40 }
62 } 41 }
63 42
64 InitialLoadObserver::~InitialLoadObserver() { 43 InitialLoadObserver::~InitialLoadObserver() {
65 } 44 }
66 45
67 void InitialLoadObserver::Observe(NotificationType type, 46 void InitialLoadObserver::Observe(NotificationType type,
68 const NotificationSource& source, 47 const NotificationSource& source,
69 const NotificationDetails& details) { 48 const NotificationDetails& details) {
70 if (type == NotificationType::LOAD_START) { 49 if (type == NotificationType::LOAD_START) {
71 if (outstanding_tab_count_ > loading_tabs_.size()) 50 if (outstanding_tab_count_ > loading_tabs_.size())
72 loading_tabs_.insert(TabTimeMap::value_type( 51 loading_tabs_.insert(source.map_key());
73 source.map_key(),
74 TabTime(base::TimeTicks::Now())));
75 } else if (type == NotificationType::LOAD_STOP) { 52 } else if (type == NotificationType::LOAD_STOP) {
76 if (outstanding_tab_count_ > finished_tabs_.size()) { 53 if (outstanding_tab_count_ > finished_tabs_.size()) {
77 TabTimeMap::iterator iter = loading_tabs_.find(source.map_key()); 54 if (loading_tabs_.find(source.map_key()) != loading_tabs_.end())
78 if (iter != loading_tabs_.end()) {
79 finished_tabs_.insert(source.map_key()); 55 finished_tabs_.insert(source.map_key());
80 iter->second.set_stop_time(base::TimeTicks::Now());
81 }
82 if (outstanding_tab_count_ == finished_tabs_.size()) 56 if (outstanding_tab_count_ == finished_tabs_.size())
83 ConditionMet(); 57 ConditionMet();
84 } 58 }
85 } else { 59 } else {
86 NOTREACHED(); 60 NOTREACHED();
87 } 61 }
88 } 62 }
89 63
90 DictionaryValue* InitialLoadObserver::GetTimingInformation() const {
91 ListValue* items = new ListValue;
92 for (TabTimeMap::const_iterator it = loading_tabs_.begin();
93 it != loading_tabs_.end();
94 ++it) {
95 DictionaryValue* item = new DictionaryValue;
96 base::TimeDelta delta_start = it->second.start_time() - init_time_;
97
98 item->SetReal(L"load_start_ms", delta_start.InMillisecondsF());
99 if (it->second.stop_time().is_null()) {
100 item->Set(L"load_stop_ms", Value::CreateNullValue());
101 } else {
102 base::TimeDelta delta_stop = it->second.stop_time() - init_time_;
103 item->SetReal(L"load_stop_ms", delta_stop.InMillisecondsF());
104 }
105 items->Append(item);
106 }
107 DictionaryValue* return_value = new DictionaryValue;
108 return_value->Set(L"tabs", items);
109 return return_value;
110 }
111
112 void InitialLoadObserver::ConditionMet() { 64 void InitialLoadObserver::ConditionMet() {
113 registrar_.RemoveAll(); 65 registrar_.RemoveAll();
114 automation_->Send(new AutomationMsg_InitialLoadsComplete(0)); 66 automation_->Send(new AutomationMsg_InitialLoadsComplete(0));
115 } 67 }
116 68
117 NewTabUILoadObserver::NewTabUILoadObserver(AutomationProvider* automation) 69 NewTabUILoadObserver::NewTabUILoadObserver(AutomationProvider* automation)
118 : automation_(automation) { 70 : automation_(automation) {
119 registrar_.Add(this, NotificationType::INITIAL_NEW_TAB_UI_LOAD, 71 registrar_.Add(this, NotificationType::INITIAL_NEW_TAB_UI_LOAD,
120 NotificationService::AllSources()); 72 NotificationService::AllSources());
121 } 73 }
(...skipping 913 matching lines...) Expand 10 before | Expand all | Expand 10 after
1035 type == NotificationType::AUTH_NEEDED) { 987 type == NotificationType::AUTH_NEEDED) {
1036 AutomationMsg_SendJSONRequest::WriteReplyParams( 988 AutomationMsg_SendJSONRequest::WriteReplyParams(
1037 reply_message_, std::string("{}"), false); 989 reply_message_, std::string("{}"), false);
1038 automation_->Send(reply_message_); 990 automation_->Send(reply_message_);
1039 delete this; 991 delete this;
1040 } else { 992 } else {
1041 NOTREACHED(); 993 NOTREACHED();
1042 } 994 }
1043 } 995 }
1044 996
OLDNEW
« no previous file with comments | « chrome/browser/automation/automation_provider_observers.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698