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

Side by Side Diff: chrome/browser/chromeos/login/supervised/supervised_user_creation_screen.cc

Issue 931993002: Make image_decoder a Leaky LazyInstance (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add ImageDecoder->RemoveDelegate Created 5 years, 9 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/chromeos/login/supervised/supervised_user_creation_scre en.h" 5 #include "chrome/browser/chromeos/login/supervised/supervised_user_creation_scre en.h"
6 6
7 #include "ash/desktop_background/desktop_background_controller.h" 7 #include "ash/desktop_background/desktop_background_controller.h"
8 #include "ash/shell.h" 8 #include "ash/shell.h"
9 #include "base/rand_util.h" 9 #include "base/rand_util.h"
10 #include "base/values.h" 10 #include "base/values.h"
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 98
99 SupervisedUserCreationScreen::SupervisedUserCreationScreen( 99 SupervisedUserCreationScreen::SupervisedUserCreationScreen(
100 BaseScreenDelegate* base_screen_delegate, 100 BaseScreenDelegate* base_screen_delegate,
101 SupervisedUserCreationScreenHandler* actor) 101 SupervisedUserCreationScreenHandler* actor)
102 : BaseScreen(base_screen_delegate), 102 : BaseScreen(base_screen_delegate),
103 actor_(actor), 103 actor_(actor),
104 on_error_screen_(false), 104 on_error_screen_(false),
105 manager_signin_in_progress_(false), 105 manager_signin_in_progress_(false),
106 last_page_(kNameOfIntroScreen), 106 last_page_(kNameOfIntroScreen),
107 sync_service_(NULL), 107 sync_service_(NULL),
108 image_decoder_(NULL),
109 apply_photo_after_decoding_(false), 108 apply_photo_after_decoding_(false),
110 selected_image_(0), 109 selected_image_(0),
111 histogram_helper_(new ErrorScreensHistogramHelper("Supervised")), 110 histogram_helper_(new ErrorScreensHistogramHelper("Supervised")),
112 weak_factory_(this) { 111 weak_factory_(this) {
113 DCHECK(actor_); 112 DCHECK(actor_);
114 if (actor_) 113 if (actor_)
115 actor_->SetDelegate(this); 114 actor_->SetDelegate(this);
116 } 115 }
117 116
118 SupervisedUserCreationScreen::~SupervisedUserCreationScreen() { 117 SupervisedUserCreationScreen::~SupervisedUserCreationScreen() {
119 CameraPresenceNotifier::GetInstance()->RemoveObserver(this); 118 CameraPresenceNotifier::GetInstance()->RemoveObserver(this);
120 if (sync_service_) 119 if (sync_service_)
121 sync_service_->RemoveObserver(this); 120 sync_service_->RemoveObserver(this);
122 if (actor_) 121 if (actor_)
123 actor_->SetDelegate(NULL); 122 actor_->SetDelegate(NULL);
124 if (image_decoder_.get()) 123 ImageDecoder::GetInstance()->RemoveDelegate(this);
125 image_decoder_->set_delegate(NULL);
126 NetworkPortalDetector::Get()->RemoveObserver(this); 124 NetworkPortalDetector::Get()->RemoveObserver(this);
127 } 125 }
128 126
129 void SupervisedUserCreationScreen::PrepareToShow() { 127 void SupervisedUserCreationScreen::PrepareToShow() {
130 if (actor_) 128 if (actor_)
131 actor_->PrepareToShow(); 129 actor_->PrepareToShow();
132 } 130 }
133 131
134 void SupervisedUserCreationScreen::Show() { 132 void SupervisedUserCreationScreen::Show() {
135 CameraPresenceNotifier::GetInstance()->AddObserver(this); 133 CameraPresenceNotifier::GetInstance()->AddObserver(this);
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 existing_users_->Set(it.key(), local_copy); 583 existing_users_->Set(it.key(), local_copy);
586 ui_users->Append(ui_copy); 584 ui_users->Append(ui_copy);
587 } 585 }
588 actor_->ShowExistingSupervisedUsers(ui_users.get()); 586 actor_->ShowExistingSupervisedUsers(ui_users.get());
589 } 587 }
590 588
591 void SupervisedUserCreationScreen::OnPhotoTaken( 589 void SupervisedUserCreationScreen::OnPhotoTaken(
592 const std::string& raw_data) { 590 const std::string& raw_data) {
593 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 591 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
594 user_photo_ = gfx::ImageSkia(); 592 user_photo_ = gfx::ImageSkia();
595 if (image_decoder_.get())
596 image_decoder_->set_delegate(NULL);
597 image_decoder_ = new ImageDecoder(this, raw_data,
598 ImageDecoder::DEFAULT_CODEC);
599 scoped_refptr<base::MessageLoopProxy> task_runner = 593 scoped_refptr<base::MessageLoopProxy> task_runner =
600 content::BrowserThread::GetMessageLoopProxyForThread( 594 content::BrowserThread::GetMessageLoopProxyForThread(
601 content::BrowserThread::UI); 595 content::BrowserThread::UI);
602 image_decoder_->Start(task_runner); 596 ImageDecoder::GetInstance()->RemoveDelegate(this);
597 ImageDecoder::GetInstance()->Start(
598 this, raw_data, ImageDecoder::DEFAULT_CODEC, task_runner, false);
603 } 599 }
604 600
605 void SupervisedUserCreationScreen::OnImageDecoded( 601 void SupervisedUserCreationScreen::OnImageDecoded(
606 const ImageDecoder* decoder,
607 const SkBitmap& decoded_image) { 602 const SkBitmap& decoded_image) {
608 DCHECK_EQ(image_decoder_.get(), decoder);
609 user_photo_ = gfx::ImageSkia::CreateFrom1xBitmap(decoded_image); 603 user_photo_ = gfx::ImageSkia::CreateFrom1xBitmap(decoded_image);
610 if (apply_photo_after_decoding_) 604 if (apply_photo_after_decoding_)
611 ApplyPicture(); 605 ApplyPicture();
612 } 606 }
613 607
614 void SupervisedUserCreationScreen::OnDecodeImageFailed( 608 void SupervisedUserCreationScreen::OnDecodeImageFailed() {
615 const ImageDecoder* decoder) {
616 NOTREACHED() << "Failed to decode PNG image from WebUI"; 609 NOTREACHED() << "Failed to decode PNG image from WebUI";
617 } 610 }
618 611
619 void SupervisedUserCreationScreen::OnImageSelected( 612 void SupervisedUserCreationScreen::OnImageSelected(
620 const std::string& image_type, 613 const std::string& image_type,
621 const std::string& image_url) { 614 const std::string& image_url) {
622 if (image_url.empty()) 615 if (image_url.empty())
623 return; 616 return;
624 int user_image_index = user_manager::User::USER_IMAGE_INVALID; 617 int user_image_index = user_manager::User::USER_IMAGE_INVALID;
625 if (image_type == "default" && 618 if (image_type == "default" &&
626 user_manager::IsDefaultImageUrl(image_url, &user_image_index)) { 619 user_manager::IsDefaultImageUrl(image_url, &user_image_index)) {
627 selected_image_ = user_image_index; 620 selected_image_ = user_image_index;
628 } else if (image_type == "camera") { 621 } else if (image_type == "camera") {
629 selected_image_ = user_manager::User::USER_IMAGE_EXTERNAL; 622 selected_image_ = user_manager::User::USER_IMAGE_EXTERNAL;
630 } else { 623 } else {
631 NOTREACHED() << "Unexpected image type: " << image_type; 624 NOTREACHED() << "Unexpected image type: " << image_type;
632 } 625 }
633 } 626 }
634 627
635 void SupervisedUserCreationScreen::OnImageAccepted() { 628 void SupervisedUserCreationScreen::OnImageAccepted() {
636 } 629 }
637 630
638 } // namespace chromeos 631 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698