Chromium Code Reviews| 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 "chrome/browser/automation/automation_provider_observers.h" | 5 #include "chrome/browser/automation/automation_provider_observers.h" |
| 6 | 6 |
| 7 #include <deque> | 7 #include <deque> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 92 return load_start_time_; | 92 return load_start_time_; |
| 93 } | 93 } |
| 94 private: | 94 private: |
| 95 base::TimeTicks load_start_time_; | 95 base::TimeTicks load_start_time_; |
| 96 base::TimeTicks load_stop_time_; | 96 base::TimeTicks load_stop_time_; |
| 97 }; | 97 }; |
| 98 | 98 |
| 99 InitialLoadObserver::InitialLoadObserver(size_t tab_count, | 99 InitialLoadObserver::InitialLoadObserver(size_t tab_count, |
| 100 AutomationProvider* automation) | 100 AutomationProvider* automation) |
| 101 : automation_(automation->AsWeakPtr()), | 101 : automation_(automation->AsWeakPtr()), |
| 102 crashed_tab_count_(0), | |
| 102 outstanding_tab_count_(tab_count), | 103 outstanding_tab_count_(tab_count), |
| 103 init_time_(base::TimeTicks::Now()) { | 104 init_time_(base::TimeTicks::Now()) { |
| 104 if (outstanding_tab_count_ > 0) { | 105 if (outstanding_tab_count_ > 0) { |
| 105 registrar_.Add(this, content::NOTIFICATION_LOAD_START, | 106 registrar_.Add(this, content::NOTIFICATION_LOAD_START, |
| 106 NotificationService::AllSources()); | 107 NotificationService::AllSources()); |
| 107 registrar_.Add(this, content::NOTIFICATION_LOAD_STOP, | 108 registrar_.Add(this, content::NOTIFICATION_LOAD_STOP, |
| 108 NotificationService::AllSources()); | 109 NotificationService::AllSources()); |
| 110 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CREATED, | |
| 111 NotificationService::AllSources()); | |
| 112 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, | |
| 113 NotificationService::AllSources()); | |
| 109 } | 114 } |
| 110 } | 115 } |
| 111 | 116 |
| 112 InitialLoadObserver::~InitialLoadObserver() { | 117 InitialLoadObserver::~InitialLoadObserver() { |
| 113 } | 118 } |
| 114 | 119 |
| 115 void InitialLoadObserver::Observe(int type, | 120 void InitialLoadObserver::Observe(int type, |
| 116 const NotificationSource& source, | 121 const NotificationSource& source, |
| 117 const NotificationDetails& details) { | 122 const NotificationDetails& details) { |
| 118 if (type == content::NOTIFICATION_LOAD_START) { | 123 if (type == content::NOTIFICATION_LOAD_START) { |
| 119 if (outstanding_tab_count_ > loading_tabs_.size()) | 124 if (outstanding_tab_count_ > loading_tabs_.size()) |
| 120 loading_tabs_.insert(TabTimeMap::value_type( | 125 loading_tabs_.insert(TabTimeMap::value_type( |
| 121 source.map_key(), | 126 source.map_key(), |
| 122 TabTime(base::TimeTicks::Now()))); | 127 TabTime(base::TimeTicks::Now()))); |
| 123 } else if (type == content::NOTIFICATION_LOAD_STOP) { | 128 } else if (type == content::NOTIFICATION_LOAD_STOP) { |
| 124 if (outstanding_tab_count_ > finished_tabs_.size()) { | 129 if (outstanding_tab_count_ > finished_tabs_.size()) { |
| 125 TabTimeMap::iterator iter = loading_tabs_.find(source.map_key()); | 130 TabTimeMap::iterator iter = loading_tabs_.find(source.map_key()); |
| 126 if (iter != loading_tabs_.end()) { | 131 if (iter != loading_tabs_.end()) { |
| 127 finished_tabs_.insert(source.map_key()); | 132 finished_tabs_.insert(source.map_key()); |
| 128 iter->second.set_stop_time(base::TimeTicks::Now()); | 133 iter->second.set_stop_time(base::TimeTicks::Now()); |
| 129 } | 134 } |
| 130 if (outstanding_tab_count_ == finished_tabs_.size()) | |
| 131 ConditionMet(); | |
| 132 } | 135 } |
| 136 } else if (type == content::NOTIFICATION_RENDERER_PROCESS_CREATED) { | |
| 137 LOG(INFO) << "Got RENDERER_PROCESS_CREATED"; | |
| 138 } else if (type == content::NOTIFICATION_RENDERER_PROCESS_CLOSED) { | |
| 139 LOG(INFO) << "Got RENDERER_PROCESS_CLOSED"; | |
| 140 | |
| 141 // Assume no render process transitions on initial loads for simplicity. | |
| 142 // Treat every closing render process as a crash. | |
|
darin (slow to review)
2011/09/15 05:43:37
It might help to explain why instead of just summa
Paweł Hajdan Jr.
2011/09/15 18:36:44
I just removed that assumption then. Probably bett
| |
| 143 crashed_tab_count_++; | |
| 133 } else { | 144 } else { |
| 134 NOTREACHED(); | 145 NOTREACHED(); |
| 135 } | 146 } |
| 147 | |
| 148 if (finished_tabs_.size() + crashed_tab_count_ >= outstanding_tab_count_) | |
| 149 ConditionMet(); | |
| 136 } | 150 } |
| 137 | 151 |
| 138 DictionaryValue* InitialLoadObserver::GetTimingInformation() const { | 152 DictionaryValue* InitialLoadObserver::GetTimingInformation() const { |
| 139 ListValue* items = new ListValue; | 153 ListValue* items = new ListValue; |
| 140 for (TabTimeMap::const_iterator it = loading_tabs_.begin(); | 154 for (TabTimeMap::const_iterator it = loading_tabs_.begin(); |
| 141 it != loading_tabs_.end(); | 155 it != loading_tabs_.end(); |
| 142 ++it) { | 156 ++it) { |
| 143 DictionaryValue* item = new DictionaryValue; | 157 DictionaryValue* item = new DictionaryValue; |
| 144 base::TimeDelta delta_start = it->second.start_time() - init_time_; | 158 base::TimeDelta delta_start = it->second.start_time() - init_time_; |
| 145 | 159 |
| (...skipping 2554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2700 void DragTargetDropAckNotificationObserver::Observe( | 2714 void DragTargetDropAckNotificationObserver::Observe( |
| 2701 int type, | 2715 int type, |
| 2702 const NotificationSource& source, | 2716 const NotificationSource& source, |
| 2703 const NotificationDetails& details) { | 2717 const NotificationDetails& details) { |
| 2704 if (automation_) { | 2718 if (automation_) { |
| 2705 AutomationJSONReply(automation_, | 2719 AutomationJSONReply(automation_, |
| 2706 reply_message_.release()).SendSuccess(NULL); | 2720 reply_message_.release()).SendSuccess(NULL); |
| 2707 } | 2721 } |
| 2708 delete this; | 2722 delete this; |
| 2709 } | 2723 } |
| OLD | NEW |