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 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_SIGNED_SETTINGS_HELPER_H_ 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_SIGNED_SETTINGS_HELPER_H_ 7 #pragma once 8 9 #include <string> 10 11 #include "chrome/browser/chromeos/login/signed_settings.h" 12 13 namespace enterprise_management { 14 class PolicyFetchResponse; 15 } // namespace enterprise_management 16 namespace em = enterprise_management; 17 namespace chromeos { 18 19 class SignedSettings; 20 21 // Helper to serialize signed settings ops, provide unified callback interface, 22 // and handle callbacks destruction before ops completion. 23 class SignedSettingsHelper { 24 public: 25 class Callback { 26 public: 27 // Callback of CheckWhitelistOp. |success| indicates whether the op succeeds 28 // or not. |email| is the email that is checked against. OnCheckWhitelistCompleted(SignedSettings::ReturnCode code,const std::string & email)29 virtual void OnCheckWhitelistCompleted( 30 SignedSettings::ReturnCode code, 31 const std::string& email) {} 32 33 // Callback of WhitelistOp that adds |email| to the whitelist. OnWhitelistCompleted(SignedSettings::ReturnCode code,const std::string & email)34 virtual void OnWhitelistCompleted( 35 SignedSettings::ReturnCode code, const std::string& email) {} 36 37 // Callback of WhitelistOp that removes |email| to the whitelist. OnUnwhitelistCompleted(SignedSettings::ReturnCode code,const std::string & email)38 virtual void OnUnwhitelistCompleted( 39 SignedSettings::ReturnCode code, const std::string& email) {} 40 41 // Callback of StorePropertyOp. OnStorePropertyCompleted(SignedSettings::ReturnCode code,const std::string & name,const std::string & value)42 virtual void OnStorePropertyCompleted( 43 SignedSettings::ReturnCode code, 44 const std::string& name, 45 const std::string& value) {} 46 47 // Callback of RetrievePropertyOp. OnRetrievePropertyCompleted(SignedSettings::ReturnCode code,const std::string & name,const std::string & value)48 virtual void OnRetrievePropertyCompleted( 49 SignedSettings::ReturnCode code, 50 const std::string& name, 51 const std::string& value) {} 52 53 // Callback of StorePolicyOp. OnStorePolicyCompleted(SignedSettings::ReturnCode code)54 virtual void OnStorePolicyCompleted( 55 SignedSettings::ReturnCode code) {} 56 57 // Callback of RetrievePolicyOp. OnRetrievePolicyCompleted(SignedSettings::ReturnCode code,const em::PolicyFetchResponse & policy)58 virtual void OnRetrievePolicyCompleted( 59 SignedSettings::ReturnCode code, 60 const em::PolicyFetchResponse& policy) {} 61 }; 62 63 // Class factory 64 static SignedSettingsHelper* Get(); 65 66 // Functions to start signed settings ops. 67 virtual void StartCheckWhitelistOp(const std::string& email, 68 Callback* callback) = 0; 69 virtual void StartWhitelistOp(const std::string& email, 70 bool add_to_whitelist, 71 Callback* callback) = 0; 72 virtual void StartStorePropertyOp(const std::string& name, 73 const std::string& value, 74 Callback* callback) = 0; 75 virtual void StartRetrieveProperty(const std::string& name, 76 Callback* callback) = 0; 77 virtual void StartStorePolicyOp(const em::PolicyFetchResponse& policy, 78 Callback* callback) = 0; 79 virtual void StartRetrievePolicyOp(Callback* callback) = 0; 80 81 // Cancels all pending calls of given callback. 82 virtual void CancelCallback(Callback* callback) = 0; 83 84 class TestDelegate { 85 public: 86 virtual void OnOpCreated(SignedSettings* op) = 0; 87 virtual void OnOpStarted(SignedSettings* op) = 0; 88 virtual void OnOpCompleted(SignedSettings* op) = 0; 89 }; 90 91 #if defined(UNIT_TEST) set_test_delegate(TestDelegate * test_delegate)92 void set_test_delegate(TestDelegate* test_delegate) { 93 test_delegate_ = test_delegate; 94 } 95 #endif // defined(UNIT_TEST) 96 97 protected: SignedSettingsHelper()98 SignedSettingsHelper() : test_delegate_(NULL) { 99 } 100 101 TestDelegate* test_delegate_; 102 }; 103 104 } // namespace chromeos 105 106 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_SIGNED_SETTINGS_HELPER_H_ 107