OLD | NEW |
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 Loading... |
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 |
31 InitialLoadObserver::InitialLoadObserver(size_t tab_count, | 51 InitialLoadObserver::InitialLoadObserver(size_t tab_count, |
32 AutomationProvider* automation) | 52 AutomationProvider* automation) |
33 : automation_(automation), | 53 : automation_(automation), |
34 outstanding_tab_count_(tab_count) { | 54 outstanding_tab_count_(tab_count), |
| 55 init_time_(base::TimeTicks::Now()) { |
35 if (outstanding_tab_count_ > 0) { | 56 if (outstanding_tab_count_ > 0) { |
36 registrar_.Add(this, NotificationType::LOAD_START, | 57 registrar_.Add(this, NotificationType::LOAD_START, |
37 NotificationService::AllSources()); | 58 NotificationService::AllSources()); |
38 registrar_.Add(this, NotificationType::LOAD_STOP, | 59 registrar_.Add(this, NotificationType::LOAD_STOP, |
39 NotificationService::AllSources()); | 60 NotificationService::AllSources()); |
40 } | 61 } |
41 } | 62 } |
42 | 63 |
43 InitialLoadObserver::~InitialLoadObserver() { | 64 InitialLoadObserver::~InitialLoadObserver() { |
44 } | 65 } |
45 | 66 |
46 void InitialLoadObserver::Observe(NotificationType type, | 67 void InitialLoadObserver::Observe(NotificationType type, |
47 const NotificationSource& source, | 68 const NotificationSource& source, |
48 const NotificationDetails& details) { | 69 const NotificationDetails& details) { |
49 if (type == NotificationType::LOAD_START) { | 70 if (type == NotificationType::LOAD_START) { |
50 if (outstanding_tab_count_ > loading_tabs_.size()) | 71 if (outstanding_tab_count_ > loading_tabs_.size()) |
51 loading_tabs_.insert(source.map_key()); | 72 loading_tabs_.insert(TabTimeMap::value_type( |
| 73 source.map_key(), |
| 74 TabTime(base::TimeTicks::Now()))); |
52 } else if (type == NotificationType::LOAD_STOP) { | 75 } else if (type == NotificationType::LOAD_STOP) { |
53 if (outstanding_tab_count_ > finished_tabs_.size()) { | 76 if (outstanding_tab_count_ > finished_tabs_.size()) { |
54 if (loading_tabs_.find(source.map_key()) != loading_tabs_.end()) | 77 TabTimeMap::iterator iter = loading_tabs_.find(source.map_key()); |
| 78 if (iter != loading_tabs_.end()) { |
55 finished_tabs_.insert(source.map_key()); | 79 finished_tabs_.insert(source.map_key()); |
| 80 iter->second.set_stop_time(base::TimeTicks::Now()); |
| 81 } |
56 if (outstanding_tab_count_ == finished_tabs_.size()) | 82 if (outstanding_tab_count_ == finished_tabs_.size()) |
57 ConditionMet(); | 83 ConditionMet(); |
58 } | 84 } |
59 } else { | 85 } else { |
60 NOTREACHED(); | 86 NOTREACHED(); |
61 } | 87 } |
62 } | 88 } |
63 | 89 |
| 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 |
64 void InitialLoadObserver::ConditionMet() { | 112 void InitialLoadObserver::ConditionMet() { |
65 registrar_.RemoveAll(); | 113 registrar_.RemoveAll(); |
66 automation_->Send(new AutomationMsg_InitialLoadsComplete(0)); | 114 automation_->Send(new AutomationMsg_InitialLoadsComplete(0)); |
67 } | 115 } |
68 | 116 |
69 NewTabUILoadObserver::NewTabUILoadObserver(AutomationProvider* automation) | 117 NewTabUILoadObserver::NewTabUILoadObserver(AutomationProvider* automation) |
70 : automation_(automation) { | 118 : automation_(automation) { |
71 registrar_.Add(this, NotificationType::INITIAL_NEW_TAB_UI_LOAD, | 119 registrar_.Add(this, NotificationType::INITIAL_NEW_TAB_UI_LOAD, |
72 NotificationService::AllSources()); | 120 NotificationService::AllSources()); |
73 } | 121 } |
(...skipping 913 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
987 type == NotificationType::AUTH_NEEDED) { | 1035 type == NotificationType::AUTH_NEEDED) { |
988 AutomationMsg_SendJSONRequest::WriteReplyParams( | 1036 AutomationMsg_SendJSONRequest::WriteReplyParams( |
989 reply_message_, std::string("{}"), false); | 1037 reply_message_, std::string("{}"), false); |
990 automation_->Send(reply_message_); | 1038 automation_->Send(reply_message_); |
991 delete this; | 1039 delete this; |
992 } else { | 1040 } else { |
993 NOTREACHED(); | 1041 NOTREACHED(); |
994 } | 1042 } |
995 } | 1043 } |
996 | 1044 |
OLD | NEW |