ownership_service.h revision bda42a81ee5f9b20d2bebedcf0bbef1e30e5b293
1// Copyright (c) 2010 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#ifndef CHROME_BROWSER_CHROMEOS_LOGIN_OWNERSHIP_SERVICE_H_ 6#define CHROME_BROWSER_CHROMEOS_LOGIN_OWNERSHIP_SERVICE_H_ 7#pragma once 8 9#include <string> 10#include <vector> 11 12#include "base/ref_counted.h" 13#include "base/singleton.h" 14#include "chrome/browser/chromeos/login/owner_key_utils.h" 15#include "chrome/browser/chromeos/login/owner_manager.h" 16#include "chrome/browser/chromeos/login/signed_settings.h" 17#include "chrome/common/notification_observer.h" 18#include "chrome/common/notification_registrar.h" 19 20namespace chromeos { 21 22class OwnershipService : public SignedSettings::Delegate<bool>, 23 public NotificationObserver { 24 public: 25 // Returns the singleton instance of the OwnershipService. 26 static OwnershipService* GetSharedInstance(); 27 virtual ~OwnershipService(); 28 29 virtual bool IsAlreadyOwned(); 30 31 // If the device has been owned already, posts a task to the FILE thread to 32 // fetch the public key off disk. 33 // Returns true if the attempt was initiated, false otherwise. 34 // 35 // Sends out a OWNER_KEY_FETCH_ATTEMPT_SUCCESS notification on success, 36 // OWNER_KEY_FETCH_ATTEMPT_FAILED on failure. 37 virtual bool StartLoadOwnerKeyAttempt(); 38 39 // If the device has not yet been owned, posts a task to the FILE 40 // thread to generate the owner's keys and put them in the right 41 // places. Keeps them in memory as well, for later use. 42 // Returns true if the attempt was initiated, false otherwise. 43 // 44 // Upon failure, sends out OWNER_KEY_FETCH_ATTEMPT_FAILED. 45 // Upon success, sends out OWNER_KEY_FETCH_ATTEMPT_SUCCESS and kicks off an 46 // asynchronous call to whitelist the owner. 47 // If no attempt is started (if the device is already owned), no 48 // notification is sent. 49 virtual bool StartTakeOwnershipAttempt(const std::string& owner); 50 51 // Initiate an attempt to sign |data| with |private_key_|. Will call 52 // d->OnKeyOpComplete() when done. Upon success, the signature will be passed 53 // as the |payload| argument to d->OnKeyOpComplete(). 54 // Returns true if the attempt was initiated, false otherwise. 55 // 56 // If you call this on a well-known thread, you'll be called back on that 57 // thread. Otherwise, you'll get called back on the UI thread. 58 virtual void StartSigningAttempt(const std::string& data, 59 OwnerManager::Delegate* d); 60 61 // Initiate an attempt to verify that |signature| is valid over |data| with 62 // |public_key_|. When the attempt is completed, an appropriate KeyOpCode 63 // will be passed to d->OnKeyOpComplete(). 64 // Returns true if the attempt was initiated, false otherwise. 65 // 66 // If you call this on a well-known thread, you'll be called back on that 67 // thread. Otherwise, you'll get called back on the UI thread. 68 virtual void StartVerifyAttempt(const std::string& data, 69 const std::vector<uint8>& signature, 70 OwnerManager::Delegate* d); 71 72 virtual bool CurrentUserIsOwner(); 73 74 // SignedSettings::Delegate<bool> implementation. 75 // These methods will be called on the UI thread. 76 virtual void OnSettingsOpSucceeded(bool value); 77 virtual void OnSettingsOpFailed(); 78 79 // NotificationObserver implementation. 80 virtual void Observe(NotificationType type, 81 const NotificationSource& source, 82 const NotificationDetails& details); 83 84 protected: 85 OwnershipService(); 86 87 private: 88 friend struct DefaultSingletonTraits<OwnershipService>; 89 friend class OwnershipServiceTest; 90 91 scoped_refptr<OwnerManager> manager_; 92 scoped_refptr<OwnerKeyUtils> utils_; 93 scoped_refptr<SignedSettings> whitelister_; 94 95 NotificationRegistrar registrar_; 96}; 97 98} // namespace chromeos 99 100#endif // CHROME_BROWSER_CHROMEOS_LOGIN_OWNERSHIP_SERVICE_H_ 101