forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added user image screen for new user login (or old user logging in th…
…rough new user screen). If user takes snapshot and hits OK on image screen, the snapshot becomes user image. If user presses Cancel, his image is downloaded via Contacts API. BUG=cros:3175 TEST=Login via new user login window. Verify that both use cases work if you logout after the browser is shown. Review URL: http://codereview.chromium.org/2578001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@48828 0039d316-1c4b-4281-b951-d872f2087c98
- Loading branch information
avayvod@chromium.org
committed
Jun 3, 2010
1 parent
f4badfb
commit 64ec034
Showing
18 changed files
with
1,152 additions
and
28 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
// Copyright (c) 2010 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef CHROME_BROWSER_CHROMEOS_LOGIN_CAMERA_H_ | ||
#define CHROME_BROWSER_CHROMEOS_LOGIN_CAMERA_H_ | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
#include "base/timer.h" | ||
|
||
class SkBitmap; | ||
|
||
namespace base { | ||
class TimeDelta; | ||
} // namespace base | ||
|
||
namespace chromeos { | ||
|
||
// Class that wraps interaction with video capturing device. Returns | ||
// frames captured with specified intervals of time via delegate interface. | ||
class Camera { | ||
public: | ||
class Delegate { | ||
public: | ||
virtual ~Delegate() {} | ||
|
||
// Called with specified intervals with decoded frame as a parameter. | ||
virtual void OnVideoFrameCaptured(const SkBitmap& frame) = 0; | ||
}; | ||
|
||
explicit Camera(Delegate* delegate); | ||
~Camera(); | ||
|
||
// Initializes camera device. Returns true if succeeded, false otherwise. | ||
// Does nothing on subsequent calls until Uninitialize is called. | ||
// Sets the desired width and height of the frame to receive from camera. | ||
bool Initialize(int desired_width, int desired_height); | ||
|
||
// Uninitializes the camera. Can be called anytime, any number of times. | ||
void Uninitialize(); | ||
|
||
// Starts capturing video frames with specified interval. | ||
// Does nothing on subsequent calls until StopCapturing is called. | ||
// Returns true if succeeded, false otherwise. | ||
bool StartCapturing(const base::TimeDelta& interval); | ||
|
||
// Stops capturing video frames. Can be called anytime, any number of | ||
// times. | ||
void StopCapturing(); | ||
|
||
private: | ||
// Tries to open the device with specified name. Returns opened device | ||
// descriptor if succeeds, -1 otherwise. | ||
int OpenDevice(const char* device_name) const; | ||
|
||
// Initializes reading mode for the device. Returns true on success, false | ||
// otherwise. | ||
bool InitializeReadingMode(int fd); | ||
|
||
// Unmaps video buffers stored in |buffers_|. | ||
void UnmapVideoBuffers(); | ||
|
||
// Called by |timer_| to get the frame from video device and send it to | ||
// |delegate_| via its method. | ||
void OnCapture(); | ||
|
||
// Reads a frame from the video device. If retry is needed, returns false. | ||
// Otherwise, returns true despite of success status. | ||
bool ReadFrame(); | ||
|
||
// Transforms raw data received from camera into SkBitmap with desired | ||
// size and notifies the delegate that the image is ready. | ||
void ProcessImage(void* data); | ||
|
||
// Defines a buffer in memory where one frame from the camera is stored. | ||
struct VideoBuffer { | ||
void* start; | ||
size_t length; | ||
}; | ||
|
||
// Delegate that receives the frames from the camera. | ||
Delegate* delegate_; | ||
|
||
// Name of the device file, i.e. "/dev/video0". | ||
std::string device_name_; | ||
|
||
// File descriptor of the opened device. | ||
int device_descriptor_; | ||
|
||
// Vector of buffers where to store video frames from camera. | ||
std::vector<VideoBuffer> buffers_; | ||
|
||
// Timer for getting frames. | ||
base::RepeatingTimer<Camera> timer_; | ||
|
||
// Desired size of the frame to get from camera. If it doesn't match | ||
// camera's supported resolution, higher resolution is selected (if | ||
// available) and frame is cropped. If higher resolution is not available, | ||
// the highest is selected and resized. | ||
int desired_width_; | ||
int desired_height_; | ||
|
||
// Size of the frame that camera will give to us. It may not match the | ||
// desired size. | ||
int frame_width_; | ||
int frame_height_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(Camera); | ||
}; | ||
|
||
} // namespace chromeos | ||
|
||
#endif // CHROME_BROWSER_CHROMEOS_LOGIN_CAMERA_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// Copyright (c) 2010 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "chrome/browser/chromeos/login/user_image_screen.h" | ||
|
||
#include "base/compiler_specific.h" | ||
#include "base/time.h" | ||
#include "chrome/browser/chromeos/login/login_utils.h" | ||
#include "chrome/browser/chromeos/login/screen_observer.h" | ||
#include "chrome/browser/chromeos/login/user_image_downloader.h" | ||
#include "chrome/browser/chromeos/login/user_image_view.h" | ||
#include "chrome/browser/chromeos/login/user_manager.h" | ||
|
||
namespace chromeos { | ||
|
||
namespace { | ||
|
||
// The resolution of the picture we want to get from the camera. | ||
const int kFrameWidth = 480; | ||
const int kFrameHeight = 480; | ||
|
||
// Frame rate in milliseconds for video capturing. | ||
// We want 25 FPS. | ||
const int kFrameRate = 40; | ||
|
||
} // namespace | ||
|
||
UserImageScreen::UserImageScreen(WizardScreenDelegate* delegate) | ||
: ViewScreen<UserImageView>(delegate), | ||
ALLOW_THIS_IN_INITIALIZER_LIST(camera_(new Camera(this))) { | ||
if (!camera_->Initialize(kFrameWidth, kFrameHeight)) | ||
camera_.reset(); | ||
} | ||
|
||
UserImageScreen::~UserImageScreen() { | ||
} | ||
|
||
void UserImageScreen::Refresh() { | ||
if (camera_.get()) | ||
camera_->StartCapturing(base::TimeDelta::FromMilliseconds(kFrameRate)); | ||
} | ||
|
||
void UserImageScreen::Hide() { | ||
if (camera_.get()) | ||
camera_->StopCapturing(); | ||
ViewScreen<UserImageView>::Hide(); | ||
} | ||
|
||
UserImageView* UserImageScreen::AllocateView() { | ||
return new UserImageView(this); | ||
} | ||
|
||
void UserImageScreen::OnVideoFrameCaptured(const SkBitmap& frame) { | ||
if (view()) | ||
view()->UpdateVideoFrame(frame); | ||
} | ||
|
||
void UserImageScreen::OnOK(const SkBitmap& image) { | ||
UserManager* user_manager = UserManager::Get(); | ||
if (user_manager) { | ||
// TODO(avayvod): Check that there's logged in user actually. | ||
const UserManager::User& user = user_manager->logged_in_user(); | ||
user_manager->SaveUserImage(user.email(), image); | ||
} | ||
if (delegate()) | ||
delegate()->GetObserver(this)->OnExit(ScreenObserver::USER_IMAGE_SELECTED); | ||
} | ||
|
||
void UserImageScreen::OnCancel() { | ||
// Download user image from his Google account. | ||
UserManager* user_manager = UserManager::Get(); | ||
if (user_manager) { | ||
// TODO(avayvod): Check that there's logged in user actually. | ||
const UserManager::User& user = user_manager->logged_in_user(); | ||
new UserImageDownloader(user.email(), | ||
LoginUtils::Get()->GetAuthToken()); | ||
} | ||
if (delegate()) | ||
delegate()->GetObserver(this)->OnExit(ScreenObserver::USER_IMAGE_SKIPPED); | ||
} | ||
|
||
} // namespace chromeos | ||
|
Oops, something went wrong.