| 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 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/file_util.h" | 13 #include "base/file_util.h" |
| 14 #include "base/json/json_writer.h" | 14 #include "base/json/json_writer.h" |
| 15 #include "base/scoped_ptr.h" | 15 #include "base/scoped_ptr.h" |
| 16 #include "base/string_util.h" | 16 #include "base/string_util.h" |
| 17 #include "base/stringprintf.h" | 17 #include "base/stringprintf.h" |
| 18 #include "base/threading/thread_restrictions.h" | 18 #include "base/threading/thread_restrictions.h" |
| 19 #include "base/utf_string_conversions.h" | 19 #include "base/utf_string_conversions.h" |
| 20 #include "base/values.h" | 20 #include "base/values.h" |
| 21 #include "chrome/app/chrome_command_ids.h" | 21 #include "chrome/app/chrome_command_ids.h" |
| 22 #include "chrome/browser/automation/automation_provider.h" | 22 #include "chrome/browser/automation/automation_provider.h" |
| 23 #include "chrome/browser/automation/automation_provider_json.h" | 23 #include "chrome/browser/automation/automation_provider_json.h" |
| 24 #include "chrome/browser/bookmarks/bookmark_model.h" | 24 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 25 #include "chrome/browser/browser_list.h" | 25 #include "chrome/browser/browser_list.h" |
| 26 #include "chrome/browser/browser_process.h" | 26 #include "chrome/browser/browser_process.h" |
| 27 #if defined(OS_CHROMEOS) | |
| 28 #include "chrome/browser/chromeos/cros/cros_library.h" | |
| 29 #include "chrome/browser/chromeos/login/authentication_notification_details.h" | |
| 30 #endif // defined(OS_CHROMEOS) | |
| 31 #include "chrome/browser/dom_operation_notification_details.h" | 27 #include "chrome/browser/dom_operation_notification_details.h" |
| 32 #include "chrome/browser/download/download_item.h" | 28 #include "chrome/browser/download/download_item.h" |
| 33 #include "chrome/browser/download/save_package.h" | 29 #include "chrome/browser/download/save_package.h" |
| 34 #include "chrome/browser/extensions/extension_host.h" | 30 #include "chrome/browser/extensions/extension_host.h" |
| 35 #include "chrome/browser/extensions/extension_process_manager.h" | 31 #include "chrome/browser/extensions/extension_process_manager.h" |
| 36 #include "chrome/browser/extensions/extension_updater.h" | 32 #include "chrome/browser/extensions/extension_updater.h" |
| 37 #include "chrome/browser/history/top_sites.h" | 33 #include "chrome/browser/history/top_sites.h" |
| 38 #include "chrome/browser/metrics/metric_event_duration_details.h" | 34 #include "chrome/browser/metrics/metric_event_duration_details.h" |
| 39 #include "chrome/browser/notifications/balloon.h" | 35 #include "chrome/browser/notifications/balloon.h" |
| 40 #include "chrome/browser/notifications/balloon_collection.h" | 36 #include "chrome/browser/notifications/balloon_collection.h" |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 return_value->Set("tabs", items); | 142 return_value->Set("tabs", items); |
| 147 return return_value; | 143 return return_value; |
| 148 } | 144 } |
| 149 | 145 |
| 150 void InitialLoadObserver::ConditionMet() { | 146 void InitialLoadObserver::ConditionMet() { |
| 151 registrar_.RemoveAll(); | 147 registrar_.RemoveAll(); |
| 152 if (automation_) | 148 if (automation_) |
| 153 automation_->OnInitialTabLoadsComplete(); | 149 automation_->OnInitialTabLoadsComplete(); |
| 154 } | 150 } |
| 155 | 151 |
| 156 #if defined(OS_CHROMEOS) | |
| 157 NetworkManagerInitObserver::NetworkManagerInitObserver( | |
| 158 AutomationProvider* automation) | |
| 159 : automation_(automation->AsWeakPtr()) { | |
| 160 if (chromeos::CrosLibrary::Get()->EnsureLoaded()) { | |
| 161 chromeos::CrosLibrary::Get()->GetNetworkLibrary()-> | |
| 162 AddNetworkManagerObserver(this); | |
| 163 } else { | |
| 164 automation_->OnNetworkLibraryInit(); | |
| 165 delete this; | |
| 166 } | |
| 167 } | |
| 168 | |
| 169 NetworkManagerInitObserver::~NetworkManagerInitObserver() {} | |
| 170 | |
| 171 void NetworkManagerInitObserver::OnNetworkManagerChanged( | |
| 172 chromeos::NetworkLibrary* obj) { | |
| 173 if (!obj->wifi_scanning()) { | |
| 174 obj->RemoveNetworkManagerObserver(this); | |
| 175 automation_->OnNetworkLibraryInit(); | |
| 176 delete this; | |
| 177 } | |
| 178 } | |
| 179 #endif // defined(OS_CHROMEOS) | |
| 180 | |
| 181 NewTabUILoadObserver::NewTabUILoadObserver(AutomationProvider* automation) | 152 NewTabUILoadObserver::NewTabUILoadObserver(AutomationProvider* automation) |
| 182 : automation_(automation->AsWeakPtr()) { | 153 : automation_(automation->AsWeakPtr()) { |
| 183 registrar_.Add(this, NotificationType::INITIAL_NEW_TAB_UI_LOAD, | 154 registrar_.Add(this, NotificationType::INITIAL_NEW_TAB_UI_LOAD, |
| 184 NotificationService::AllSources()); | 155 NotificationService::AllSources()); |
| 185 } | 156 } |
| 186 | 157 |
| 187 NewTabUILoadObserver::~NewTabUILoadObserver() { | 158 NewTabUILoadObserver::~NewTabUILoadObserver() { |
| 188 } | 159 } |
| 189 | 160 |
| 190 void NewTabUILoadObserver::Observe(NotificationType type, | 161 void NewTabUILoadObserver::Observe(NotificationType type, |
| (...skipping 1061 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1252 return; | 1223 return; |
| 1253 | 1224 |
| 1254 if (automation_) { | 1225 if (automation_) { |
| 1255 AutomationMsg_WaitForInfoBarCount::WriteReplyParams(reply_message_.get(), | 1226 AutomationMsg_WaitForInfoBarCount::WriteReplyParams(reply_message_.get(), |
| 1256 true); | 1227 true); |
| 1257 automation_->Send(reply_message_.release()); | 1228 automation_->Send(reply_message_.release()); |
| 1258 } | 1229 } |
| 1259 delete this; | 1230 delete this; |
| 1260 } | 1231 } |
| 1261 | 1232 |
| 1262 #if defined(OS_CHROMEOS) | |
| 1263 LoginManagerObserver::LoginManagerObserver( | |
| 1264 AutomationProvider* automation, | |
| 1265 IPC::Message* reply_message) | |
| 1266 : automation_(automation->AsWeakPtr()), | |
| 1267 reply_message_(reply_message) { | |
| 1268 | |
| 1269 registrar_.Add(this, NotificationType::LOGIN_USER_CHANGED, | |
| 1270 NotificationService::AllSources()); | |
| 1271 } | |
| 1272 | |
| 1273 LoginManagerObserver::~LoginManagerObserver() {} | |
| 1274 | |
| 1275 void LoginManagerObserver::Observe(NotificationType type, | |
| 1276 const NotificationSource& source, | |
| 1277 const NotificationDetails& details) { | |
| 1278 DCHECK(type == NotificationType::LOGIN_USER_CHANGED); | |
| 1279 | |
| 1280 if (!automation_) { | |
| 1281 delete this; | |
| 1282 return; | |
| 1283 } | |
| 1284 | |
| 1285 AutomationJSONReply reply(automation_, reply_message_.release()); | |
| 1286 Details<AuthenticationNotificationDetails> auth_details(details); | |
| 1287 if (auth_details->success()) | |
| 1288 reply.SendSuccess(NULL); | |
| 1289 else | |
| 1290 reply.SendError("Login failure."); | |
| 1291 delete this; | |
| 1292 } | |
| 1293 | |
| 1294 ScreenLockUnlockObserver::ScreenLockUnlockObserver( | |
| 1295 AutomationProvider* automation, | |
| 1296 IPC::Message* reply_message, | |
| 1297 bool lock_screen) | |
| 1298 : automation_(automation), | |
| 1299 reply_message_(reply_message), | |
| 1300 lock_screen_(lock_screen) { | |
| 1301 | |
| 1302 registrar_.Add(this, NotificationType::SCREEN_LOCK_STATE_CHANGED, | |
| 1303 NotificationService::AllSources()); | |
| 1304 } | |
| 1305 | |
| 1306 ScreenLockUnlockObserver::~ScreenLockUnlockObserver() {} | |
| 1307 | |
| 1308 void ScreenLockUnlockObserver::Observe(NotificationType type, | |
| 1309 const NotificationSource& source, | |
| 1310 const NotificationDetails& details) { | |
| 1311 DCHECK(type == NotificationType::SCREEN_LOCK_STATE_CHANGED); | |
| 1312 AutomationJSONReply reply(automation_, reply_message_); | |
| 1313 bool is_screen_locked = *Details<bool>(details).ptr(); | |
| 1314 if (lock_screen_ == is_screen_locked) | |
| 1315 reply.SendSuccess(NULL); | |
| 1316 else | |
| 1317 reply.SendError("Screen lock failure."); | |
| 1318 delete this; | |
| 1319 } | |
| 1320 #endif // defined(OS_CHROMEOS) | |
| 1321 | |
| 1322 AutomationProviderBookmarkModelObserver:: | 1233 AutomationProviderBookmarkModelObserver:: |
| 1323 AutomationProviderBookmarkModelObserver( | 1234 AutomationProviderBookmarkModelObserver( |
| 1324 AutomationProvider* provider, | 1235 AutomationProvider* provider, |
| 1325 IPC::Message* reply_message, | 1236 IPC::Message* reply_message, |
| 1326 BookmarkModel* model) | 1237 BookmarkModel* model) |
| 1327 : automation_provider_(provider->AsWeakPtr()), | 1238 : automation_provider_(provider->AsWeakPtr()), |
| 1328 reply_message_(reply_message), | 1239 reply_message_(reply_message), |
| 1329 model_(model) { | 1240 model_(model) { |
| 1330 model_->AddObserver(this); | 1241 model_->AddObserver(this); |
| 1331 } | 1242 } |
| (...skipping 808 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2140 this, | 2051 this, |
| 2141 &WaitForProcessLauncherThreadToGoIdleObserver::RunOnUIThread)); | 2052 &WaitForProcessLauncherThreadToGoIdleObserver::RunOnUIThread)); |
| 2142 } | 2053 } |
| 2143 | 2054 |
| 2144 void WaitForProcessLauncherThreadToGoIdleObserver::RunOnUIThread() { | 2055 void WaitForProcessLauncherThreadToGoIdleObserver::RunOnUIThread() { |
| 2145 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2056 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 2146 if (automation_) | 2057 if (automation_) |
| 2147 automation_->Send(reply_message_.release()); | 2058 automation_->Send(reply_message_.release()); |
| 2148 Release(); | 2059 Release(); |
| 2149 } | 2060 } |
| OLD | NEW |