| 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 "base/values.h" | 7 #include "base/values.h" |
| 8 #include "chrome/browser/automation/automation_provider.h" | 8 #include "chrome/browser/automation/automation_provider.h" |
| 9 #include "chrome/browser/chromeos/cros/cros_library.h" | 9 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 10 #include "chrome/browser/chromeos/login/authentication_notification_details.h" | 10 #include "chrome/browser/chromeos/login/authentication_notification_details.h" |
| 11 #include "chrome/browser/chromeos/login/enterprise_enrollment_screen_actor.h" | 11 #include "chrome/browser/chromeos/login/enterprise_enrollment_screen_actor.h" |
| 12 #include "chrome/browser/chromeos/login/existing_user_controller.h" | 12 #include "chrome/browser/chromeos/login/existing_user_controller.h" |
| 13 #include "chrome/browser/chromeos/login/screen_locker.h" | 13 #include "chrome/browser/chromeos/login/screen_locker.h" |
| 14 #include "chrome/browser/chromeos/login/user_manager.h" |
| 14 #include "chrome/browser/chromeos/login/wizard_controller.h" | 15 #include "chrome/browser/chromeos/login/wizard_controller.h" |
| 15 #include "chrome/common/chrome_notification_types.h" | 16 #include "chrome/common/chrome_notification_types.h" |
| 16 #include "content/common/notification_service.h" | 17 #include "content/common/notification_service.h" |
| 17 | 18 |
| 18 using chromeos::CrosLibrary; | 19 using chromeos::CrosLibrary; |
| 19 using chromeos::NetworkLibrary; | 20 using chromeos::NetworkLibrary; |
| 20 | 21 |
| 21 NetworkManagerInitObserver::NetworkManagerInitObserver( | 22 NetworkManagerInitObserver::NetworkManagerInitObserver( |
| 22 AutomationProvider* automation) | 23 AutomationProvider* automation) |
| 23 : automation_(automation->AsWeakPtr()) {} | 24 : automation_(automation->AsWeakPtr()) {} |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 const chromeos::WifiNetworkVector& wifi_networks = | 372 const chromeos::WifiNetworkVector& wifi_networks = |
| 372 network_library->wifi_networks(); | 373 network_library->wifi_networks(); |
| 373 for (chromeos::WifiNetworkVector::const_iterator iter = wifi_networks.begin(); | 374 for (chromeos::WifiNetworkVector::const_iterator iter = wifi_networks.begin(); |
| 374 iter != wifi_networks.end(); ++iter) { | 375 iter != wifi_networks.end(); ++iter) { |
| 375 const chromeos::WifiNetwork* wifi = *iter; | 376 const chromeos::WifiNetwork* wifi = *iter; |
| 376 if (wifi->name() == ssid_) | 377 if (wifi->name() == ssid_) |
| 377 return wifi; | 378 return wifi; |
| 378 } | 379 } |
| 379 return NULL; | 380 return NULL; |
| 380 } | 381 } |
| 382 |
| 383 PhotoCaptureObserver::PhotoCaptureObserver( |
| 384 AutomationProvider* automation, |
| 385 IPC::Message* reply_message) |
| 386 : automation_(automation->AsWeakPtr()), |
| 387 reply_message_(reply_message) { |
| 388 } |
| 389 |
| 390 PhotoCaptureObserver::~PhotoCaptureObserver() { |
| 391 // TODO(frankf): Currently, we do not destroy TakePhotoDialog |
| 392 // or any of its children. |
| 393 } |
| 394 |
| 395 void PhotoCaptureObserver::OnCaptureSuccess( |
| 396 chromeos::TakePhotoDialog* take_photo_dialog, |
| 397 chromeos::TakePhotoView* take_photo_view) { |
| 398 take_photo_view->FlipCapturingState(); |
| 399 } |
| 400 |
| 401 void PhotoCaptureObserver::OnCaptureFailure( |
| 402 chromeos::TakePhotoDialog* take_photo_dialog, |
| 403 chromeos::TakePhotoView* take_photo_view) { |
| 404 AutomationJSONReply(automation_, |
| 405 reply_message_.release()).SendError("Capture failure"); |
| 406 delete this; |
| 407 } |
| 408 |
| 409 void PhotoCaptureObserver::OnCapturingStopped( |
| 410 chromeos::TakePhotoDialog* take_photo_dialog, |
| 411 chromeos::TakePhotoView* take_photo_view) { |
| 412 take_photo_dialog->Accept(); |
| 413 const SkBitmap& photo = take_photo_view->GetImage(); |
| 414 chromeos::UserManager* user_manager = chromeos::UserManager::Get(); |
| 415 if(!user_manager) { |
| 416 AutomationJSONReply(automation_, |
| 417 reply_message_.release()).SendError( |
| 418 "No user manager"); |
| 419 delete this; |
| 420 return; |
| 421 } |
| 422 |
| 423 const chromeos::UserManager::User& user = user_manager->logged_in_user(); |
| 424 if(user.email().empty()) { |
| 425 AutomationJSONReply(automation_, |
| 426 reply_message_.release()).SendError( |
| 427 "User email is not set"); |
| 428 delete this; |
| 429 return; |
| 430 } |
| 431 |
| 432 // Set up an observer for UserManager (it will delete itself). |
| 433 user_manager->AddObserver(this); |
| 434 user_manager->SetLoggedInUserImage(photo); |
| 435 user_manager->SaveUserImage(user.email(), photo); |
| 436 } |
| 437 |
| 438 void PhotoCaptureObserver::LocalStateChanged( |
| 439 chromeos::UserManager* user_manager) { |
| 440 user_manager->RemoveObserver(this); |
| 441 AutomationJSONReply(automation_, reply_message_.release()).SendSuccess(NULL); |
| 442 delete this; |
| 443 } |
| OLD | NEW |