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.
Implemented profile-aware owner key loading.
BUG=230018 TEST=manual Review URL: https://codereview.chromium.org/270663002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@271802 0039d316-1c4b-4281-b951-d872f2087c98
- Loading branch information
ygorshenin@chromium.org
committed
May 21, 2014
1 parent
f571bc0
commit 196e53e
Showing
22 changed files
with
462 additions
and
57 deletions.
There are no files selected for viewing
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
72 changes: 72 additions & 0 deletions
72
chrome/browser/chromeos/ownership/owner_settings_service.cc
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,72 @@ | ||
// Copyright 2014 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/ownership/owner_settings_service.h" | ||
|
||
#include <string> | ||
|
||
#include "base/bind.h" | ||
#include "chrome/browser/chrome_notification_types.h" | ||
#include "chrome/browser/chromeos/login/users/user.h" | ||
#include "chrome/browser/chromeos/login/users/user_manager.h" | ||
#include "chrome/browser/chromeos/ownership/owner_settings_service_factory.h" | ||
#include "chrome/browser/chromeos/settings/device_settings_service.h" | ||
#include "chrome/browser/profiles/profile.h" | ||
#include "content/public/browser/browser_thread.h" | ||
#include "content/public/browser/notification_details.h" | ||
#include "content/public/browser/notification_source.h" | ||
#include "crypto/nss_util_internal.h" | ||
#include "crypto/scoped_nss_types.h" | ||
|
||
using content::BrowserThread; | ||
|
||
namespace chromeos { | ||
|
||
OwnerSettingsService::OwnerSettingsService(Profile* profile) | ||
: profile_(profile), weak_factory_(this) { | ||
registrar_.Add(this, | ||
chrome::NOTIFICATION_PROFILE_CREATED, | ||
content::Source<Profile>(profile_)); | ||
} | ||
|
||
OwnerSettingsService::~OwnerSettingsService() { | ||
} | ||
|
||
void OwnerSettingsService::Observe( | ||
int type, | ||
const content::NotificationSource& source, | ||
const content::NotificationDetails& details) { | ||
if (type != chrome::NOTIFICATION_PROFILE_CREATED) { | ||
NOTREACHED(); | ||
return; | ||
} | ||
|
||
Profile* profile = content::Source<Profile>(source).ptr(); | ||
if (profile != profile_) { | ||
NOTREACHED(); | ||
return; | ||
} | ||
|
||
ReloadOwnerKey(); | ||
} | ||
|
||
void OwnerSettingsService::ReloadOwnerKey() { | ||
if (!UserManager::IsInitialized()) | ||
return; | ||
const User* user = UserManager::Get()->GetUserByProfile(profile_); | ||
if (!user || !user->is_profile_created()) | ||
return; | ||
std::string user_id = user->email(); | ||
if (user_id != OwnerSettingsServiceFactory::GetInstance()->GetUsername()) | ||
return; | ||
BrowserThread::PostTaskAndReplyWithResult( | ||
BrowserThread::IO, | ||
FROM_HERE, | ||
base::Bind(&crypto::GetPublicSlotForChromeOSUser, user->username_hash()), | ||
base::Bind(&DeviceSettingsService::InitOwner, | ||
base::Unretained(DeviceSettingsService::Get()), | ||
user_id)); | ||
} | ||
|
||
} // namespace chromeos |
51 changes: 51 additions & 0 deletions
51
chrome/browser/chromeos/ownership/owner_settings_service.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright 2014 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_OWNERSHIP_OWNER_SETTINGS_SERVICE_H_ | ||
#define CHROME_BROWSER_CHROMEOS_OWNERSHIP_OWNER_SETTINGS_SERVICE_H_ | ||
|
||
#include "base/compiler_specific.h" | ||
#include "base/macros.h" | ||
#include "base/memory/weak_ptr.h" | ||
#include "components/keyed_service/core/keyed_service.h" | ||
#include "content/public/browser/notification_observer.h" | ||
#include "content/public/browser/notification_registrar.h" | ||
|
||
class Profile; | ||
|
||
namespace chromeos { | ||
|
||
// This class reloads owner key from profile NSS slots. | ||
// | ||
// TODO (ygorshenin@): move write path for device settings here | ||
// (crbug.com/230018). | ||
class OwnerSettingsService : public KeyedService, | ||
public content::NotificationObserver { | ||
public: | ||
virtual ~OwnerSettingsService(); | ||
|
||
// NotificationObserver implementation: | ||
virtual void Observe(int type, | ||
const content::NotificationSource& source, | ||
const content::NotificationDetails& details) OVERRIDE; | ||
|
||
private: | ||
friend class OwnerSettingsServiceFactory; | ||
|
||
explicit OwnerSettingsService(Profile* profile); | ||
|
||
void ReloadOwnerKey(); | ||
|
||
Profile* profile_; | ||
|
||
content::NotificationRegistrar registrar_; | ||
|
||
base::WeakPtrFactory<OwnerSettingsService> weak_factory_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(OwnerSettingsService); | ||
}; | ||
|
||
} // namespace chromeos | ||
|
||
#endif // CHROME_BROWSER_CHROMEOS_OWNERSHIP_OWNER_SETTINGS_SERVICE_H_ |
77 changes: 77 additions & 0 deletions
77
chrome/browser/chromeos/ownership/owner_settings_service_factory.cc
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,77 @@ | ||
// Copyright 2014 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/ownership/owner_settings_service_factory.h" | ||
|
||
#include "chrome/browser/chromeos/login/users/user.h" | ||
#include "chrome/browser/chromeos/login/users/user_manager.h" | ||
#include "chrome/browser/chromeos/ownership/owner_settings_service.h" | ||
#include "chrome/browser/chromeos/profiles/profile_helper.h" | ||
#include "chrome/browser/profiles/profile.h" | ||
#include "components/keyed_service/content/browser_context_dependency_manager.h" | ||
|
||
namespace chromeos { | ||
|
||
OwnerSettingsServiceFactory::OwnerSettingsServiceFactory() | ||
: BrowserContextKeyedServiceFactory( | ||
"OwnerSettingsService", | ||
BrowserContextDependencyManager::GetInstance()) { | ||
} | ||
|
||
OwnerSettingsServiceFactory::~OwnerSettingsServiceFactory() { | ||
} | ||
|
||
// static | ||
OwnerSettingsService* OwnerSettingsServiceFactory::GetForProfile( | ||
Profile* profile) { | ||
return static_cast<OwnerSettingsService*>( | ||
GetInstance()->GetServiceForBrowserContext(profile, true)); | ||
} | ||
|
||
// static | ||
OwnerSettingsServiceFactory* OwnerSettingsServiceFactory::GetInstance() { | ||
return Singleton<OwnerSettingsServiceFactory>::get(); | ||
} | ||
|
||
void OwnerSettingsServiceFactory::SetUsername(const std::string& username) { | ||
username_ = username; | ||
if (!UserManager::IsInitialized()) | ||
return; | ||
const User* user = UserManager::Get()->FindUser(username_); | ||
if (!user || !user->is_profile_created()) | ||
return; | ||
Profile* profile = UserManager::Get()->GetProfileByUser(user); | ||
if (!profile) | ||
return; | ||
OwnerSettingsService* service = GetForProfile(profile); | ||
|
||
// It's safe to call ReloadOwnerKey() here, as profile is fully created | ||
// at this time. | ||
if (service) | ||
service->ReloadOwnerKey(); | ||
} | ||
|
||
std::string OwnerSettingsServiceFactory::GetUsername() const { | ||
return username_; | ||
} | ||
|
||
// static | ||
KeyedService* OwnerSettingsServiceFactory::BuildInstanceFor( | ||
content::BrowserContext* browser_context) { | ||
Profile* profile = static_cast<Profile*>(browser_context); | ||
if (profile->IsGuestSession() || ProfileHelper::IsSigninProfile(profile)) | ||
return NULL; | ||
return new OwnerSettingsService(profile); | ||
} | ||
|
||
bool OwnerSettingsServiceFactory::ServiceIsCreatedWithBrowserContext() const { | ||
return true; | ||
} | ||
|
||
KeyedService* OwnerSettingsServiceFactory::BuildServiceInstanceFor( | ||
content::BrowserContext* context) const { | ||
return BuildInstanceFor(context); | ||
} | ||
|
||
} // namespace chromeos |
60 changes: 60 additions & 0 deletions
60
chrome/browser/chromeos/ownership/owner_settings_service_factory.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright 2014 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_OWNERSHIP_OWNER_SETTINGS_SERVICE_FACTORY_H_ | ||
#define CHROME_BROWSER_CHROMEOS_OWNERSHIP_OWNER_SETTINGS_SERVICE_FACTORY_H_ | ||
|
||
#include <string> | ||
|
||
#include "base/compiler_specific.h" | ||
#include "base/macros.h" | ||
#include "base/memory/singleton.h" | ||
#include "components/keyed_service/content/browser_context_keyed_service_factory.h" | ||
|
||
class KeyedService; | ||
class Profile; | ||
|
||
namespace chromeos { | ||
|
||
class OwnerSettingsService; | ||
|
||
class OwnerSettingsServiceFactory : public BrowserContextKeyedServiceFactory { | ||
public: | ||
static OwnerSettingsService* GetForProfile(Profile* profile); | ||
|
||
static OwnerSettingsServiceFactory* GetInstance(); | ||
|
||
// Sets name of the user supposed to be an owner. If profile | ||
// for |username| is ready, request to reload owner key will be | ||
// sent. Otherwise, owner key will be reloaded as soon as profile will | ||
// be ready. | ||
void SetUsername(const std::string& username); | ||
|
||
// Returns the name of the user supposed to be an owner. | ||
std::string GetUsername() const; | ||
|
||
private: | ||
friend struct DefaultSingletonTraits<OwnerSettingsServiceFactory>; | ||
|
||
OwnerSettingsServiceFactory(); | ||
virtual ~OwnerSettingsServiceFactory(); | ||
|
||
static KeyedService* BuildInstanceFor(content::BrowserContext* context); | ||
|
||
// BrowserContextKeyedBaseFactory overrides: | ||
virtual bool ServiceIsCreatedWithBrowserContext() const OVERRIDE; | ||
|
||
// BrowserContextKeyedServiceFactory implementation: | ||
virtual KeyedService* BuildServiceInstanceFor( | ||
content::BrowserContext* browser_context) const OVERRIDE; | ||
|
||
// Name of the user supposed to be an owner. | ||
std::string username_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(OwnerSettingsServiceFactory); | ||
}; | ||
|
||
} // namespace chromeos | ||
|
||
#endif // CHROME_BROWSER_CHROMEOS_OWNERSHIP_OWNER_SETTINGS_SERVICE_FACTORY_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
Oops, something went wrong.